Webhooks: know instantly.Webhooks : soyez prévenu aussitôt.
WunaPay calls your server when a payment, payout, refund or escrow changes. Test and live events go to separate addresses, every message is signed, and retried until your server answers.WunaPay appelle votre serveur quand un paiement, un transfert, un remboursement ou un séquestre change. Les événements test et réels vont vers des adresses séparées ; chaque message est signé, et renvoyé jusqu’à ce que votre serveur réponde.
Last updated: November 2026 (0.9.13)Dernière mise à jour : novembre 2026 (0.9.13)
Test and live addresses
You have two webhook addresses, each with its own signing secret: one for test events, one for live (real money) events. A test event is never sent to the live address, and the other way round, so a test payment can never look like a real sale on your shop.
- Create an address on your server that accepts
POSTrequests, e.g.https://yourshop.cm/wunapay/webhook. It must be public HTTPS. - In your dashboard, open Developers → Webhooks. Paste it under Test webhook and save. Live webhook appears once WunaPay approved your business for real payments.
- Copy that address’s signing secret (
whsec_…) and store it on your server, like your API key. Test and live secrets are different. - Click Send a test event: your server receives a
webhook.testevent and the dashboard shows the answer code.
WunaPay only sends webhooks to public HTTPS addresses (not to local or private networks), and does not follow redirects: give the final address. With no address for a mode, its events are still kept and can be read with GET /v1/events.
Events
| Event | When |
|---|---|
payment.succeeded | A customer paid. data is the payment. Can also come after payment.failed when the operator confirms late (up to 48 hours). |
payment.failed | A payment was declined or expired (data.failure_reason). |
payout.succeeded | A payout reached the recipient. |
payout.failed | A payout failed; the amount and fee are back in your balance. |
withdrawal.succeeded | A withdrawal to your own wallet succeeded. |
withdrawal.failed | A withdrawal failed; the money is back in your balance. |
refund.succeeded | A refund reached the customer. data.payment is the refunded payment. |
refund.failed | A refund failed; the money is back in your balance. |
escrow.held | The buyer paid; WunaPay now holds the money. data is the escrow. |
escrow.delivered | You marked the order delivered; the release countdown started. |
escrow.disputed | The buyer opened a dispute; the money stays held while our team reviews it. |
escrow.released | The money was released to you (buyer confirmed, or the release date passed). |
escrow.refunded | The buyer got all the money back. |
escrow.split | After a dispute, part went to the buyer and part to you. |
webhook.test | Sent by the “Send a test event” button; livemode matches the address you tested. |
Payments that wait for a manual check (needs_review) send no event until they end as succeeded or failed.
What you receive
POST /wunapay/webhook HTTP/1.1
Content-Type: application/json
User-Agent: WunaPay-Webhooks/1.0
WunaPay-Event: payment.succeeded
WunaPay-Mode: test
WunaPay-Signature: t=1761989412,v1=5f2b8c0e1d…
{
"id": "evt_Tg7Hk2LmN0pq",
"object": "event",
"type": "payment.succeeded",
"livemode": false,
"created_at": "2026-11-01T09:30:12.000Z",
"data": {
"id": "pay_8kQ2mZx1Lp7r",
"object": "payment",
"reference": "order_1042",
"method": "mtn_momo",
"amount": 25000,
"fee": 500,
"net": 24500,
"currency": "XAF",
"status": "succeeded",
"checkout_session": null,
"livemode": false,
...
}
}
livemodeis at the top of every event (and insidedata):true= real money,false= test. TheWunaPay-Modeheader says the same (liveortest).WunaPay-Eventis the event type;id(evt_…) is unique per event.datais the same object the API returns: a payment, a payout, withdrawal or refund, or an escrow.
Verify the signature
The WunaPay-Signature header has two parts: t (when we signed, in Unix seconds) and v1 (the signature). To check it:
- Take the raw body exactly as received (do not parse and re-encode it).
- Compute
HMAC-SHA256oft + "." + bodywith thewhsec_secret of the address that received it, in hexadecimal. - Compare with
v1using a constant-time comparison, and refuse messages older than 5 minutes. - Check
livemode: on your real shop act only ontrue; on your test server only onfalse.
// Node.js (Express). Keep the body RAW: the signature is computed on the exact bytes.
const crypto = require("node:crypto");
const express = require("express");
const app = express();
const SECRET = process.env.WUNAPAY_WEBHOOK_SECRET; // the whsec_ of THIS address (test or live)
const LIVE = process.env.WUNAPAY_LIVE === "1"; // "1" on your real shop, empty on your test server
app.post("/wunapay/webhook", express.raw({ type: "application/json" }), (req, res) => {
const parts = Object.fromEntries((req.get("WunaPay-Signature") || "").split(",").map((p) => p.trim().split("=")));
const expected = crypto.createHmac("sha256", SECRET).update(`${parts.t}.${req.body}`).digest();
const given = Buffer.from(String(parts.v1 || ""), "hex");
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
if (!fresh || given.length !== expected.length || !crypto.timingSafeEqual(expected, given)) {
return res.status(400).send("bad signature");
}
const event = JSON.parse(req.body);
if (event.livemode !== LIVE) return res.sendStatus(200); // other mode: say OK, change nothing
if (event.type === "payment.succeeded") {
// check event.data.amount, then mark the order event.data.reference as paid (only once!)
}
res.sendStatus(200); // answer quickly
});<?php
// PHP
$secret = getenv('WUNAPAY_WEBHOOK_SECRET'); // the whsec_ of THIS address (test or live)
$live = getenv('WUNAPAY_LIVE') === '1'; // '1' on your real shop
$raw = file_get_contents('php://input'); // the exact body
$header = $_SERVER['HTTP_WUNAPAY_SIGNATURE'] ?? '';
parse_str(str_replace(',', '&', $header), $parts); // t=..., v1=...
$expected = hash_hmac('sha256', ($parts['t'] ?? '') . '.' . $raw, $secret);
if (abs(time() - (int)($parts['t'] ?? 0)) > 300 || !hash_equals($expected, (string)($parts['v1'] ?? ''))) {
http_response_code(400);
exit('bad signature');
}
$event = json_decode($raw, true);
if (($event['livemode'] ?? null) !== $live) { // other mode: say OK, change nothing
http_response_code(200);
exit;
}
if ($event['type'] === 'payment.succeeded') {
// check $event['data']['amount'], then mark the order $event['data']['reference'] as paid (only once!)
}
http_response_code(200);# Python (Flask)
import hmac, hashlib, time, os, json
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["WUNAPAY_WEBHOOK_SECRET"].encode() # the whsec_ of THIS address (test or live)
LIVE = os.environ.get("WUNAPAY_LIVE") == "1" # "1" on your real shop
@app.post("/wunapay/webhook")
def wunapay_webhook():
raw = request.get_data() # the exact bytes
parts = dict(p.strip().split("=", 1) for p in request.headers.get("WunaPay-Signature", "").split(",") if "=" in p)
expected = hmac.new(SECRET, parts.get("t", "").encode() + b"." + raw, hashlib.sha256).hexdigest()
if not parts.get("t", "").isdigit() or abs(time.time() - int(parts["t"])) > 300 \
or not hmac.compare_digest(expected, parts.get("v1", "")):
abort(400)
event = json.loads(raw)
if event.get("livemode") is not LIVE: # other mode: say OK, change nothing
return "", 200
if event["type"] == "payment.succeeded":
pass # check event["data"]["amount"], then mark the order event["data"]["reference"] as paid (only once!)
return "", 200
The Node.js and PHP libraries (0.3.0) do it in one line, and can refuse test events for you: WunaPay.verifyWebhook(rawBody, header, secret, { requireLive: true }) and WunaPay\Webhook::verify($raw, $header, $secret, ['requireLive' => true]).
Retries
Answer with any 2xx status within 10 seconds (the whole request). If your server is down, slow, redirects or answers an error, WunaPay tries again after 1 minute, 5 minutes, 30 minutes, 2 hours and 12 hours (6 tries in total), then stops. Events for your business are sent one at a time, oldest first, so a slow server only delays its own events. Your dashboard shows each delivery with its answer code, and you can send any event again (to the address of its own mode).
Catch up with /v1/events
Every event is kept. If your server missed some (it was down for a day, or you had no address yet), keep the id of the last event you handled and ask for the ones after it, oldest first. Repeat with the last id while has_more is true. Handle them exactly like webhooks.
# every few minutes, or when your server starts again
curl "https://app.wunapay.com/v1/events?since=evt_Tg7Hk2LmN0pq&limit=100" \
-H "Authorization: Bearer sk_test_..."
# → { "object": "list", "has_more": false, "data": [ { "id": "evt_…", "type": "…", "livemode": false, "data": {…},
# "delivery": { "delivered": false, "attempts": 6, "last_status": "timeout" } } ] }
// Node.js library 0.3.0
const missed = await wunapay.events.catchUp(lastEventId); // oldest first, all pages
Good practice
- Check
livemodebefore you ship goods: a test event must never mark a real order as paid. - Answer fast, then do slow work (emails, stock) afterwards.
- Handle duplicates: the same event can arrive twice. Use
event.idor the object id to process it once. - Handle late success: a
payment.succeededcan follow apayment.failedfor the same payment. - Double-check important events with
GET /v1/payments/{id}, and check the amount matches the order. - Keep the secrets secret: if one leaks, use Roll secret for that address in the dashboard.
Adresses test et réelle
Vous avez deux adresses de webhook, chacune avec son propre secret de signature : une pour les événements de test, une pour les événements réels (argent réel). Un événement de test n’est jamais envoyé à l’adresse réelle, et inversement : un paiement de test ne peut jamais passer pour une vraie vente dans votre boutique.
- Créez sur votre serveur une adresse qui accepte les requêtes
POST, ex.https://votreboutique.cm/wunapay/webhook. Elle doit être publique et en HTTPS. - Dans votre tableau de bord, ouvrez Développeurs → Webhooks. Collez-la sous Webhook de test et enregistrez. Le Webhook réel apparaît quand WunaPay a approuvé votre entreprise pour les paiements réels.
- Copiez le secret de signature (
whsec_…) de cette adresse et gardez-le sur votre serveur, comme votre clé API. Les secrets test et réel sont différents. - Cliquez sur Envoyer un événement test : votre serveur reçoit un événement
webhook.testet le tableau de bord affiche le code de réponse.
WunaPay n’envoie des webhooks qu’à des adresses HTTPS publiques (pas vers des réseaux locaux ou privés) et ne suit pas les redirections : donnez l’adresse finale. Sans adresse pour un mode, ses événements sont quand même conservés et lisibles avec GET /v1/events.
Événements
| Événement | Quand |
|---|---|
payment.succeeded | Un client a payé. data est le paiement. Peut aussi arriver après payment.failed quand l’opérateur confirme en retard (jusqu’à 48 heures). |
payment.failed | Un paiement a été refusé ou a expiré (data.failure_reason). |
payout.succeeded | Un transfert est arrivé chez le bénéficiaire. |
payout.failed | Un transfert a échoué ; montant et frais sont revenus sur votre solde. |
withdrawal.succeeded | Un retrait vers votre propre portefeuille a réussi. |
withdrawal.failed | Un retrait a échoué ; l’argent est revenu sur votre solde. |
refund.succeeded | Un remboursement est arrivé chez le client. data.payment est le paiement remboursé. |
refund.failed | Un remboursement a échoué ; l’argent est revenu sur votre solde. |
escrow.held | L’acheteur a payé ; WunaPay garde l’argent. data est le séquestre. |
escrow.delivered | Vous avez marqué la commande livrée ; le compte à rebours de libération commence. |
escrow.disputed | L’acheteur a ouvert un litige ; l’argent reste bloqué pendant l’examen par notre équipe. |
escrow.released | L’argent vous a été versé (acheteur d’accord, ou date de libération passée). |
escrow.refunded | L’acheteur a été entièrement remboursé. |
escrow.split | Après un litige, une part est allée à l’acheteur et une part à vous. |
webhook.test | Envoyé par le bouton « Envoyer un événement test » ; livemode correspond à l’adresse testée. |
Les paiements en attente d’une vérification manuelle (needs_review) n’envoient pas d’événement avant de se terminer en succeeded ou failed.
Ce que vous recevez
POST /wunapay/webhook HTTP/1.1
Content-Type: application/json
User-Agent: WunaPay-Webhooks/1.0
WunaPay-Event: payment.succeeded
WunaPay-Mode: test
WunaPay-Signature: t=1761989412,v1=5f2b8c0e1d…
{
"id": "evt_Tg7Hk2LmN0pq",
"object": "event",
"type": "payment.succeeded",
"livemode": false,
"created_at": "2026-11-01T09:30:12.000Z",
"data": {
"id": "pay_8kQ2mZx1Lp7r",
"object": "payment",
"reference": "order_1042",
"method": "mtn_momo",
"amount": 25000,
"fee": 500,
"net": 24500,
"currency": "XAF",
"status": "succeeded",
"checkout_session": null,
"livemode": false,
...
}
}
livemodefigure en haut de chaque événement (et dansdata) :true= argent réel,false= test. L’en-têteWunaPay-Modedit la même chose (liveoutest).WunaPay-Eventest le type d’événement ;id(evt_…) est unique par événement.dataest le même objet que celui renvoyé par l’API : un paiement, un transfert, retrait ou remboursement, ou un séquestre.
Vérifier la signature
L’en-tête WunaPay-Signature contient deux parties : t (moment de la signature, en secondes Unix) et v1 (la signature). Pour la vérifier :
- Prenez le corps brut exactement tel que reçu (sans le décoder puis le réencoder).
- Calculez le
HMAC-SHA256det + "." + corpsavec le secretwhsec_de l’adresse qui l’a reçu, en hexadécimal. - Comparez avec
v1par une comparaison à temps constant, et refusez les messages de plus de 5 minutes. - Vérifiez
livemode: sur votre vraie boutique, n’agissez que surtrue; sur votre serveur de test, que surfalse.
// Node.js (Express). Keep the body RAW: the signature is computed on the exact bytes.
const crypto = require("node:crypto");
const express = require("express");
const app = express();
const SECRET = process.env.WUNAPAY_WEBHOOK_SECRET; // the whsec_ of THIS address (test or live)
const LIVE = process.env.WUNAPAY_LIVE === "1"; // "1" on your real shop, empty on your test server
app.post("/wunapay/webhook", express.raw({ type: "application/json" }), (req, res) => {
const parts = Object.fromEntries((req.get("WunaPay-Signature") || "").split(",").map((p) => p.trim().split("=")));
const expected = crypto.createHmac("sha256", SECRET).update(`${parts.t}.${req.body}`).digest();
const given = Buffer.from(String(parts.v1 || ""), "hex");
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
if (!fresh || given.length !== expected.length || !crypto.timingSafeEqual(expected, given)) {
return res.status(400).send("bad signature");
}
const event = JSON.parse(req.body);
if (event.livemode !== LIVE) return res.sendStatus(200); // other mode: say OK, change nothing
if (event.type === "payment.succeeded") {
// check event.data.amount, then mark the order event.data.reference as paid (only once!)
}
res.sendStatus(200); // answer quickly
});<?php
// PHP
$secret = getenv('WUNAPAY_WEBHOOK_SECRET'); // the whsec_ of THIS address (test or live)
$live = getenv('WUNAPAY_LIVE') === '1'; // '1' on your real shop
$raw = file_get_contents('php://input'); // the exact body
$header = $_SERVER['HTTP_WUNAPAY_SIGNATURE'] ?? '';
parse_str(str_replace(',', '&', $header), $parts); // t=..., v1=...
$expected = hash_hmac('sha256', ($parts['t'] ?? '') . '.' . $raw, $secret);
if (abs(time() - (int)($parts['t'] ?? 0)) > 300 || !hash_equals($expected, (string)($parts['v1'] ?? ''))) {
http_response_code(400);
exit('bad signature');
}
$event = json_decode($raw, true);
if (($event['livemode'] ?? null) !== $live) { // other mode: say OK, change nothing
http_response_code(200);
exit;
}
if ($event['type'] === 'payment.succeeded') {
// check $event['data']['amount'], then mark the order $event['data']['reference'] as paid (only once!)
}
http_response_code(200);# Python (Flask)
import hmac, hashlib, time, os, json
from flask import Flask, request, abort
app = Flask(__name__)
SECRET = os.environ["WUNAPAY_WEBHOOK_SECRET"].encode() # the whsec_ of THIS address (test or live)
LIVE = os.environ.get("WUNAPAY_LIVE") == "1" # "1" on your real shop
@app.post("/wunapay/webhook")
def wunapay_webhook():
raw = request.get_data() # the exact bytes
parts = dict(p.strip().split("=", 1) for p in request.headers.get("WunaPay-Signature", "").split(",") if "=" in p)
expected = hmac.new(SECRET, parts.get("t", "").encode() + b"." + raw, hashlib.sha256).hexdigest()
if not parts.get("t", "").isdigit() or abs(time.time() - int(parts["t"])) > 300 \
or not hmac.compare_digest(expected, parts.get("v1", "")):
abort(400)
event = json.loads(raw)
if event.get("livemode") is not LIVE: # other mode: say OK, change nothing
return "", 200
if event["type"] == "payment.succeeded":
pass # check event["data"]["amount"], then mark the order event["data"]["reference"] as paid (only once!)
return "", 200
Les bibliothèques Node.js et PHP (0.3.0) le font en une ligne, et peuvent refuser les événements de test pour vous : WunaPay.verifyWebhook(rawBody, header, secret, { requireLive: true }) et WunaPay\Webhook::verify($raw, $header, $secret, ['requireLive' => true]).
Nouveaux essais
Répondez avec un statut 2xx en moins de 10 secondes (requête complète). Si votre serveur est éteint, lent, redirige ou répond une erreur, WunaPay réessaie après 1 minute, 5 minutes, 30 minutes, 2 heures et 12 heures (6 essais au total), puis s’arrête. Les événements de votre entreprise partent un par un, du plus ancien au plus récent : un serveur lent ne retarde que ses propres événements. Votre tableau de bord affiche chaque envoi avec son code de réponse, et vous pouvez renvoyer n’importe quel événement (vers l’adresse de son propre mode).
Rattraper avec /v1/events
Chaque événement est conservé. Si votre serveur en a manqué (panne d’une journée, ou pas encore d’adresse), gardez l’identifiant du dernier événement traité et demandez les suivants, du plus ancien au plus récent. Recommencez avec le dernier identifiant tant que has_more vaut true. Traitez-les exactement comme des webhooks.
# every few minutes, or when your server starts again
curl "https://app.wunapay.com/v1/events?since=evt_Tg7Hk2LmN0pq&limit=100" \
-H "Authorization: Bearer sk_test_..."
# → { "object": "list", "has_more": false, "data": [ { "id": "evt_…", "type": "…", "livemode": false, "data": {…},
# "delivery": { "delivered": false, "attempts": 6, "last_status": "timeout" } } ] }
// Node.js library 0.3.0
const missed = await wunapay.events.catchUp(lastEventId); // oldest first, all pages
Bonnes pratiques
- Vérifiez
livemodeavant de livrer : un événement de test ne doit jamais marquer une vraie commande comme payée. - Répondez vite, puis faites le travail lent (e-mails, stock) ensuite.
- Gérez les doublons : un même événement peut arriver deux fois. Utilisez
event.idou l’identifiant de l’objet pour ne le traiter qu’une fois. - Prévoyez le succès tardif : un
payment.succeededpeut suivre unpayment.failedpour le même paiement. - Revérifiez les événements importants avec
GET /v1/payments/{id}, et vérifiez que le montant correspond à la commande. - Gardez les secrets secrets : en cas de fuite, utilisez Renouveler le secret pour cette adresse dans le tableau de bord.