Payments · · 1 min read
How to integrate M‑Pesa STK Push without losing a single payment
Callbacks fail, phones go offline and customers tap “cancel”. Here is how we design M-Pesa integrations that never lose track of money.
Bruno Sharif
Founder & Lead Engineer
Most M-Pesa integrations work on the happy path. The problems start when the callback never arrives, the customer’s phone is switched off, or the same payment is confirmed twice. In production, those edge cases happen every day.
1. Store the request before you send it
Write every STK Push request to your database with its CheckoutRequestID before calling Safaricom. If anything fails afterwards, you still know exactly what you asked for and can recover.
2. Treat callbacks as notifications, not truth
Callbacks can be delayed, duplicated or lost. Make your callback handler idempotent, and run a scheduled job that queries the status of any request still pending after a few minutes.
3. Reconcile every day
Compare your records with the M-Pesa statement daily. Automated reconciliation turns a stressful month-end into a report you glance at.
Done well, M-Pesa becomes the most reliable part of your checkout. Done casually, it becomes the source of your most painful support tickets.
Keep reading
Product ·
Five signs your business has outgrown spreadsheets
Spreadsheets are a brilliant start. Here is how to tell when they have quietly become the most expensive system you own.
Hosting & cloud ·
What “fast” really means for a Kenyan website
Your visitors are mostly on mid-range Android phones and mobile data. Designing for them changes almost every technical decision.
Engineering ·
Why we build boring software
The most valuable systems are the ones nobody has to think about. Our engineering principles, explained.
Start a project
Want this kind of thinking on your project?
Tell us what you are trying to achieve. You will hear back from an engineer within one business day.

