Webhooks
Hear from Swichi when collections, payouts, transfers and links succeed or fail, and verify each event.
Add an endpoint on Swichi Gateway → Developers → Webhooks. Sandbox and live have their own
endpoints: the header's Test mode switch picks which you are looking at. Press Send test event
to see a signed webhook.test arrive.
Events
| Event | When |
|---|---|
collection.succeeded | Swichi confirmed the money with the network; data.receipt is the signed receipt |
collection.failed | The payer declined or had too little; data.failure says why |
collection.expired | Nobody approved it in time |
payout.succeeded | The money reached the mobile money account or bank |
payout.failed | It could not be sent; the money and fee are back in your wallet |
payout.pending_approval | It is over your approval threshold and waits for Finance |
transfer.succeeded | A transfer your key made went through |
link.paid | A checkout link of your business was paid |
balance.low | Money leaving took your balance under your alert (Developers → Settings), once a day |
The body is JSON: {"type": "...", "livemode": false, "timestamp": "...", "data": {...}}, where
data is the object as the API returns it (a collection, a payout, a transfer; for link.paid the
link with the payment's amount and receipt).
Each event is sent once per change of state, from Swichi's own records: never forwarded from a network. If your server misses one, it is retried; you can also read the object with the API at any time.
Verify the signature
Events follow the Standard Webhooks specification: webhook-id,
webhook-timestamp and webhook-signature headers, the signature being v1, +
base64(HMAC-SHA256(secret, id + "." + timestamp + "." + body)) with the part of your secret after
whsec_, base64-decoded. Refuse timestamps older than 5 minutes, and act on an event only after
checking its signature. Code for Node.js, PHP, Laravel and Next.js is below.
Verify a webhook in your code
import crypto from "node:crypto"
// secret: the endpoint's whsec_… secret; body: the raw request body as a string.
export function verify(secret, headers, body) {
const id = headers["webhook-id"], ts = headers["webhook-timestamp"]
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false
const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64")
const want = "v1," + crypto.createHmac("sha256", key).update(`${id}.${ts}.${body}`).digest("base64")
return headers["webhook-signature"].split(" ").some((sig) =>
sig.length === want.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want)))
}Retries and replay
Answer with any 2xx within 10 seconds. Otherwise Swichi retries after 5 seconds, 5 minutes,
30 minutes, 2, 5 and 10 hours, then every 12 hours for 3 days; then the endpoint is turned off and
the owner gets an e-mail. Every delivery is on the endpoint's page, with Resend. Use the
event's webhook-id to skip one you already handled.