PayCentral ›



Content-Type
X-PayCentral-Signature
X-PayCentral-Event
User-Agent
JSON · corps du webhook
{
  "event": "payment.success",
  "timestamp": "2026-10-31T10:44:02.000000Z",
  "data": {
    "id": "01a1918d-9bc8-7383-b422-79d779e1c1ea",
    "provider": "airtel",
    "amount": "5000.00",
    "currency": "XAF",
    "fees": "75.00",
    "net_amount": "4925.00",
    "status": "success",
    "merchant_reference": "CMD-123",
    "provider_reference": "01a1918d-9bc9-70c1-8519-840f9eb9728d",
    "paid_at": "2026-10-31T10:44:02.000000Z",
    "environment": "sandbox",
    "failure_reason": null,
    "expires_at": "2026-10-31T11:42:19.000000Z",
    "late_confirmed": false,
    "late_confirmed_at": null,
    "possible_duplicate": false,
    "refunded_amount": "0.00",
    "dispute_status": null,
    "disputed_at": null,
    "created_at": "2026-10-31T10:42:19.000000Z",
    "metadata": null
  }
}

payment.success
payment.failed
payment.cancelled
refund.completed / refund.pending / refund.rejected
payout.success / payout.failed
dispute.opened / dispute.won / dispute.lost
payment.updated


JavaScript · server.js
// server.js : npm install express
import express from 'express'
import crypto from 'node:crypto'

const app = express()
const SECRET = process.env.PAYCENTRAL_WEBHOOK_SECRET   // « whsec_… » copié depuis le tableau de bord

// express.raw() sur CETTE route uniquement, et AUCUN app.use(express.json()) avant elle
app.post('/paycentral/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  const expected = 'sha256=' + crypto.createHmac('sha256', SECRET).update(req.body).digest('hex')
  const received = req.get('X-PayCentral-Signature') ?? ''

  const ok = received.length === expected.length &&
    crypto.timingSafeEqual(Buffer.from(received), Buffer.from(expected))
  if (!ok) return res.sendStatus(401)

  const event = JSON.parse(req.body.toString('utf8'))
  if (event.event === 'payment.success') {
    // 1. retrouver la commande avec event.data.merchant_reference
    // 2. vérifier le montant : Number(event.data.amount)
    // 3. marquer la commande payée UNE SEULE FOIS (ignorer si déjà payée)
  }
  res.sendStatus(200)   // toute réponse 2xx confirme la réception
})

app.listen(3000, () => console.log('En écoute sur http://localhost:3000'))

PHP · webhook-paycentral.php
<?php
// webhook-paycentral.php : à déployer sur une URL HTTPS publique
$secret   = getenv('PAYCENTRAL_WEBHOOK_SECRET');      // « whsec_… » copié depuis le tableau de bord
$body     = file_get_contents('php://input');         // corps BRUT, exactement comme reçu
$received = $_SERVER['HTTP_X_PAYCENTRAL_SIGNATURE'] ?? '';
$expected = 'sha256=' . hash_hmac('sha256', $body, $secret);

if (!hash_equals($expected, $received)) {
    http_response_code(401);
    exit('Signature invalide');
}

$event = json_decode($body, true);
$data  = $event['data'];

if ($event['event'] === 'payment.success') {
    // 1. retrouver la commande avec $data['merchant_reference']
    // 2. vérifier le montant : (float) $data['amount'] doit égaler celui de la commande
    // 3. marquer la commande payée UNE SEULE FOIS (ignorer si déjà payée)
}

http_response_code(200);   // toute réponse 2xx confirme la réception
echo 'OK';

PHP · filet de sécurité (cron)
<?php
// À lancer toutes les 5 minutes (cron) : filet de sécurité si un webhook s'est perdu
foreach (commandes_en_attente_depuis_plus_de(10) as $commande) {
    $r = $pc->status($commande->transaction_id);
    $statut = $r['body']['transaction']['status'] ?? null;

    if ($statut === 'success')                           { marquer_payee($commande); }
    elseif (in_array($statut, ['failed', 'cancelled']))  { marquer_echouee($commande); }
    // "processing" : on réessaiera au prochain passage
}

Bash · requête signée de test
SECRET="whsec_VOTRE_SECRET"
BODY='{"event":"payment.success","timestamp":"2026-10-31T10:44:02.000000Z","data":{"id":"01a1918d-9bc8-7383-b422-79d779e1c1ea","provider":"airtel","amount":"5000.00","currency":"XAF","fees":"75.00","net_amount":"4925.00","status":"success","merchant_reference":"CMD-123","provider_reference":"x","paid_at":"2026-10-31T10:44:02.000000Z","metadata":null}}'
SIG="sha256=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.* //')"

curl -i -X POST http://localhost:3000/paycentral/webhook \
  -H "Content-Type: application/json" \
  -H "X-PayCentral-Event: payment.success" \
  -H "X-PayCentral-Signature: $SIG" \
  -d "$BODY"