Skip to content
Oqtekal

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

Payments

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.

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.

We reply within one business day. Your details stay private.