PayCentral › Webhooks
Webhooks
JSON · POST /payment/initiate
{ "amount": 5000, "currency": "XAF", "phone": "237691234567", "callback_url": "https://monsite.cm/webhooks/paycentral" }
payment.success |
|
payment.failed |
|
payment.cancelled |
|
payment.pending |
|
payment.refunded |
JSON · POST vers votre endpoint
{ "event": "payment.success", "timestamp": "2024-01-15T10:47:23Z", "data": { "transaction_id": "01HXYZ9K2JABCDEF", "status": "success", "provider": "mtn", "amount": 10000, "currency": "XAF", "fees": 200, "net_amount": 9800, "merchant_reference": "CMD-789", "phone": "237691234567", "provider_reference": "MTN-REF-2024..." } }
PHP
function verifyWebhook(string $body, string $signature, string $secret): bool { $expected = hash_hmac('sha256', $body, $secret); return hash_equals($expected, $signature); } // Dans votre contrôleur webhook : $body = file_get_contents('php://input'); $signature = $_SERVER['HTTP_X_PAYCENTRAL_SIGNATURE'] ?? ''; $secret = getenv('PAYCENTRAL_WEBHOOK_SECRET'); if (!verifyWebhook($body, $signature, $secret)) { http_response_code(401); exit('Invalid signature'); } $event = json_decode($body, true);
PHP · Laravel
PayCentral::verifyWebhook( $request->getContent(), $request->header('X-PayCentral-Signature') ); // retourne bool
| 1 | |
| 2 | 5 min |
| 3 | 30 min |
| 4 | 2 h |
| 5 | 24 h |
PHP · Laravel
$txnId = $event['data']['transaction_id']; // Ignorer si déjà traité if (Order::where('payment_id', $txnId) ->where('paid', true)->exists()) { return response()->json(['received' => true]); } // Traiter le paiement...