Pay with M-PESA
send_payment()
Enter your number. Get the prompt.
- Open the M-PESA menu or app on your phone
- Select Lipa na M-PESA → Buy Goods and Services
- Enter till 9237817 → amount → confirm with your PIN
You'll get an M-PESA confirmation SMS addressed to Drinah Online Traders — that's your receipt. Done.
- 1STK pushserver → Safaricom Daraja API
- 2PIN entryprompt lands on your phone — enter M-PESA PIN
- 3CallbackSafaricom confirms → receipt issued
- 4Donereceipt shown here + WhatsApp confirmation
under the hood
What just happened, in 4 hops.
STK Push
Your number and amount hit Safaricom's Daraja API over a signed request — the phone buzzes with a payment prompt.
PIN on-device
You enter your M-PESA PIN on your own phone. It never touches this server — that's the whole security model.
Callback
Safaricom posts the result to a webhook here — idempotent, deduplicated, matched to your transaction id.
Receipt + WhatsApp
The receipt number lands on screen and a formatted WhatsApp confirmation lands on your phone via my WotSap API.
edge_cases
Every M-PESA outcome, handled.
The same result-code map I ship to clients — no mystery failures, no silent drops. If the callback stalls, the system queries Daraja directly.
| Code | What it means | What you see |
|---|---|---|
| 0 | Success | Receipt + WhatsApp confirmation |
| 1 | Insufficient funds | Clear message, retry prompt |
| 1032 | Cancelled on the phone | “Declined” state, retry allowed |
| 1037 | Phone unreachable / no response | Timeout state with guidance |
| 1019 | Prompt expired — no PIN in time | Expired state, fresh retry |
| 2001 | Wrong M-PESA PIN | PIN error, safe to retry |
| 1004 / 13 | Another push already in progress | Duplicate guard blocks spam |
| others | 40+ mapped result codes | Human-readable, logged for admin |
// want this on your own platform? see the integration service →
Payments are infrastructure.
Build them properly.
STK Push, C2B, B2C, reconciliation and every failure mode — shipped the same way you just used it.