PHP code example of mecxer713 / gopay-php
1. Go to this page and download the library: Download mecxer713/gopay-php library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mecxer713 / gopay-php example snippets
use Mecxer713\GoPay\GoPayService;
$gopay = new GoPayService(
baseUrl: 'https://gopay.gooomart.com',
paymentApiKey: 'votre_api_key',
paymentSecretKey: 'votre_secret_key',
payoutApiKey: 'votre_payout_api_key',
);
// Initier un paiement
$response = $gopay->initPayment(4000, 'CDF', '+24399000000', 'REF-001');
if ($response->isSuccessful()) {
echo $response->transId; // TRANS-001.94786.53389
echo $response->transactionStatus; // "success"
echo $response->amount; // "4000"
echo $response->currency; // "CDF"
}
use Mecxer713\GoPay\Facades\GoPay;
// Initier un paiement
$response = GoPay::initPayment(4000, 'CDF', '+24399000000', 'REF-001');
if ($response->isSuccessful()) {
$transId = $response->transId;
}
// Vérifier le statut d'un paiement
$check = GoPay::checkPayment('REF-001');
echo $check->transactionStatus; // "success", "pending", ...
use Mecxer713\GoPay\GoPayServiceInterface;
class PaymentController extends Controller
{
public function __construct(private GoPayServiceInterface $gopay) {}
public function pay(): JsonResponse
{
$response = $this->gopay->initPayment(4000, 'CDF', '+24399000000', 'REF-001');
return response()->json([
'success' => $response->isSuccessful(),
'trans_id' => $response->transId,
]);
}
}
return [
// ...
Mecxer713\GoPay\Symfony\GoPayBundle::class => ['all' => true],
];
use Mecxer713\GoPay\GoPayServiceInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PaymentController extends AbstractController
{
public function __construct(private GoPayServiceInterface $gopay) {}
public function pay(): Response
{
$balance = $this->gopay->getPayoutBalance();
return $this->json(['balance' => $balance->balance]);
}
}
use Mecxer713\GoPay\GoPayService;
$gopay = new GoPayService(
baseUrl: 'https://gopay.gooomart.com',
paymentApiKey: 'votre_api_key',
paymentSecretKey: 'votre_secret_key',
payoutApiKey: 'votre_payout_api_key',
);
$balance = $gopay->getPayoutBalance();
echo $balance->balance; // 5000.0
$response = $gopay->initPayment(
amount: 4000,
devise: 'CDF',
telephone: '+24399000000',
myref: 'REF-001',
usersId: null // optionnel
);
$response = $gopay->checkPayment(ref: 'REF-001');
$response = $gopay->getPayoutBalance();
echo $response->balance; // 5000.0
echo $response->currency; // "USD"
$response = $gopay->sendPayoutTransfer(
montant: 500,
devise: 'CDF',
telephones: ['0991234567', '0811234567'],
myrefs: ['ref-001', 'ref-002'],
dateDenvoi: null // optionnel : "2024/12/25 14:00"
);
$response = $gopay->getPayoutTransferStatus(transIdOrMyref: 'TRANS-001.94786.53389');
echo $response->transactionStatus; // "EN ATTENTE" | "TRAITÉE" | "REJETÉE"
$transfers = $gopay->getPayoutTransfers(); // array brut
$response = $gopay->deletePayoutTransfer(transId: 'TRANS-001.94786.53389');
use Mecxer713\GoPay\Exception\GoPayException;
use Mecxer713\GoPay\Enums\GoPayErrorCode;
try {
$response = GoPay::initPayment(4000, 'CDF', '+24399000000', 'REF-001');
if ($response->isSuccessful()) {
// Traitement du succès
$transId = $response->transId;
} else {
// Erreur retournée par l'API GoPAY
echo $response->message; // "Aucune transaction..."
echo $response->errorCode; // "ERR_NO_PAYMENT_FOUND"
// Comparaison typée via l'enum
if ($response->errorCode === GoPayErrorCode::TIMESTAMP_EXPIRED->value) {
// Le timestamp est trop ancien, relancer la requête
}
// Accès aux données brutes de la réponse, ex: transaction: {status: 'failed'}
$raw = $response->raw;
}
} catch (GoPayException $e) {
// Erreur réseau, timeout, ou JSON invalide
echo $e->getMessage();
}
bash
composer bash
php artisan vendor:publish --provider="Mecxer713\GoPay\GoPayServiceProvider" --tag="gopay-config"