Webhooks
When a payment settles or fails we POST it to your server, signed. You can have several endpoints, and route each payment to the ones that should see it.
The request
POST /mypayments/webhook HTTP/1.1
Host: billing.example.co.ke
Content-Type: application/json
User-Agent: mypayments-webhook/1.0
X-MyPayments-Event: payment.settled
X-MyPayments-Signature: t=1764784760,v1=9f2c4e…e1b7
{
"event": "payment.settled",
"transaction": {
"uuid": "1d6aea1c-6911-455b-8300-2d347cc2a6e4",
"account_uuid": "5e2989df-905b-40e9-a056-8251c2e34a37",
"provider": "mpesa",
"direction": "collection",
"kind": "stk",
"amount": "100.00",
"reported_amount": "100.00",
"amount_mismatch": false,
"currency": "KES",
"phone": "254712345678",
"phone_sha256": "7132104d6aae9c3fac82095a42c2817952bca48e09d98d5bf4ac08218982fb90",
"reference": "INV-001",
"tracking_id": "order-8842",
"provider_receipt": "TL3BD2ZK1P",
"status": "settled",
"result_code": "0",
"result_desc": "The service request is processed successfully.",
"verified": true,
"settled_at": "2026-12-03T17:59:20.102059Z",
"created_at": "2026-12-03T17:59:11.806152Z",
"source": "provider"
}
}transaction is the same object the lookup returns, so one parser serves both. Fields without a value are left out.
Events
| payment.settled | Paid and confirmed with Safaricom or KopoKopo. Fulfil the order. STK and C2B. |
| payment.failed | An STK prompt ended without payment: cancelled, timed out, insufficient funds. result_code says why. |
| payment.received | A C2B payment your server forwarded to us, recorded but not yet confirmed with Safaricom. Don't fulfil yet; payment.settled follows once it is confirmed. |
| webhook.test | Sent when you press Send test event on an endpoint in the dashboard. Its transaction is a sample. |
Tell kinds apart with transaction.kind: stk or c2b.
Answering
- Verify the signature over the raw body. Reject anything that fails.
- Fulfil once per payment: key on
transaction.uuidorprovider_receipt, because a delivery can arrive twice. - Answer any 2xx within 15 seconds. Do slow work afterwards, in a queue.
Anything else (a 4xx, 5xx, timeout, or a redirect, which we don't follow) is retried with growing gaps, up to an hour apart, for about 20 hours. Every attempt is logged on the payment in the dashboard, where you can also resend it. Endpoints must be public HTTPS with a valid certificate.
Missed one?
GET /transactions/{reference} always has the verified status, so a system that was down can catch up by asking.Endpoints and routing
Add up to 10 endpoints in Dashboard → Webhooks. Each has its own signing secret (shown once, starting whsec_) and optional filters:
- Kinds: STK, C2B.
- Shortcodes: which of your accounts.
- Payer phones: matched even when Safaricom sends only the number's hash.
- Reference prefixes: matched against the STK reference or the C2B account number (
WIFI-,HS-). - Events: which notifications it wants (for example only
payment.settled).
A payment goes to every endpoint whose filters all match. An endpoint with no routing filters is a catch-all: it gets the payments no filtered endpoint took, or every payment if you tick Also receive payments that a filtered endpoint already takes. Each endpoint gets each event for a payment once.
Hotspot billing kinds: c2b prefixes: HS-, WIFI- → hotspot payments only
Shop backend kinds: stk → every STK Push
Accounting (catch-all, also receive routed) → everythingOne payment, a different URL
Pass callback_url with an STK Push and that payment's delivery to your primary endpoint goes to that URL instead, signed with the primary endpoint's secret.
Where the money is checked
We never send payment.settled on Safaricom's word alone: we confirm every payment with them server to server first, and record the amount they report next to the amount you asked for. Check amount_mismatch before fulfilling something priced.