PHP code example of nexera / pay
1. Go to this page and download the library: Download nexera/pay 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/ */
nexera / pay example snippets
era = new \Nexera\Pay\NexeraPay(
getenv('NEXERA_PAY_API_KEY'),
getenv('NEXERA_PAY_SECRET'),
);
// Créer un paiement Mobile Money (STK)
$payment = $nexera->payments->create([
'amount' => 10000, // 100.00 USD en cents
'currency' => 'USD',
'method' => 'mobile_money',
'operator' => 'mpesa',
'phone' => '243812345001',
'reference' => 'INV-2026-0001',
'description' => 'Facture #INV-2026-0001',
]);
echo $payment['id'] . ' — ' . $payment['status']; // pay_xxx — processing
$payment = $nexera->payments->create([
'amount' => 50000,
'currency' => 'USD',
'method' => 'card',
'reference' => 'INV-002',
'customer_email' => '[email protected] ',
'customer_name' => 'Jean Kabala',
'return_url' => 'https://monsite.cd/facture/002',
]);
// Rediriger vers le checkout hosted MokoAfrika
header('Location: ' . $payment['checkout_url']);
use Nexera\Pay\Webhooks;
Route::post('/webhooks/nexera', function (Request $request) {
$sig = $request->header('X-Nexera-Signature', '');
$body = $request->getContent();
if (!Webhooks::verifySignature(env('NEXERA_WEBHOOK_SECRET'), $sig, $body)) {
return response('invalid signature', 401);
}
$event = json_decode($body, true);
if ($event['type'] === 'payment.succeeded') {
$tx = $event['data']['object'];
// Marquer la facture tx['reference'] comme payée dans ta DB
}
return response('ok', 200);
});
$payout = $nexera->payouts->create([
'amount' => 100,
'currency' => 'CDF',
'operator' => 'mpesa',
'phone' => '243828584688',
'reference' => 'REMB-001',
'description' => 'Remboursement client',
]);
// Refund total
$nexera->refunds->create('pay_xxx');
// Refund partiel
$nexera->refunds->create('pay_xxx', ['amount' => 5000, 'reason' => 'Article manquant']);
$bal = $nexera->balance->get();
echo $bal['available']['USD']; // en cents
use Nexera\Pay\NexeraPay;
use Nexera\Pay\Errors\{ValidationError, RateLimitError, SignatureError};
try {
$p = $nexera->payments->create([...]);
} catch (RateLimitError $e) {
echo "Rate limited, retry dans {$e->retryAfter}s";
} catch (ValidationError $e) {
echo "Validation failed: {$e->detail}";
} catch (SignatureError $e) {
// Clé/secret incorrect ou horloge système décalée
}