M-Pesa in production
Not a getting-started guide. This is what happens after the first payment works: the callback that never arrives, the customer charged twice, the ledger that disagrees with Safaricom on a Monday morning.
9 field notes from four platforms I built and still run, plus a searchable result-code reference and what Daraja 3.0 actually changed.
Integrate
Getting the first payment to work at all.
- M-Pesa Daraja API Integration with Next.js: A Production GuideMost Daraja tutorials stop at a successful STK Push in sandbox. This is the rest of it: token caching, callback verification, idempotent writes and the failure modes that only show up with real money.
- Running M-Pesa STK Push on Serverless Without Losing PaymentsServerless removes the long-lived process that most M-Pesa integrations quietly assume. Token caches, in-memory state, background work after the response: here is what breaks, and what to do instead.
Test
Proving it works before a real customer finds out it does not. Callbacks are the hard part: they arrive from Safaricom, so nothing on your laptop can receive one by default.
- Testing M-Pesa Callbacks Locally Without ngrokI spent an afternoon restarting a tunnel, editing a URL, sending a shilling, and waiting. Twelve times. Then I worked out that most callback development needs no tunnel at all.
- Why Your M-Pesa Callback Never ArrivesThe customer paid, Safaricom took the money, and your app never found out. A ranked list of the reasons Daraja callbacks go missing, and how to tell which one is yours.
Go live
The part that is not engineering. Budget for it separately, because none of it is under your control.
Operate
What breaks once real money is moving and nobody is watching the terminal.
- M-Pesa B2C: Paying People Out Without Losing Track of the MoneyCollecting money with STK Push is the easy half. Sending it back out has stricter credentials, a different failure surface, and no user watching the screen to tell you it went wrong.
- M-Pesa Refunds and Reversals: Undoing a Payment You Already TookSomebody paid for a listing we had to take down. Giving the money back turned out to be a harder decision than taking it, because M-Pesa offers two ways to do it and they leave completely different records.
- What M-Pesa Teaches You About Building Fintech in Emerging MarketsM-Pesa moved money on feature phones and SMS while Silicon Valley was perfecting online banking for people who already had bank accounts. What it got right is not what most people think.
Reconcile
Making your ledger and Safaricom’s agree, including on the days they do not.
Reference
Safaricom publishes no consolidated error reference, so this is the one I keep.
Not covered here
Your first STK Push, step by step. This pillar starts after that. For a beginner walkthrough, the dedicated tutorial series elsewhere is a better use of your time.