E-commerce11 min read

Integrating the M-Pesa Daraja API at checkout in Nairobi 2026

Mohamed Bah·Fondateur, Kolonell
August 27, 2026
Share:
Integrating the M-Pesa Daraja API at checkout in Nairobi 2026

Integrating the M-Pesa Daraja API at checkout in Nairobi 2026

E-commerce

The verdict in three sentences

Integrating M-Pesa Daraja in Nairobi requires a till number/shortcode, a consumer key/secret and a public callback URL to receive STK Push results. Buy Goods merchant fees run 0 to 0.55 %, average latency is 2 to 6 seconds, and the failure rate sits between 6 and 11 %. A 60-second timeout and a single retry turn most of those transient failures into completed sales.

The M-Pesa Daraja STK Push flow step by step

StepTechnical action2026 detail
1Get consumer key + secretVia the Safaricom Daraja portal
2Generate an OAuth tokenLifetime ~3600 s
3Call STK PushAmount, KES, unique AccountReference
4Customer enters PINPrompt pushed to their phone
5Receive callback POSTSafaricom hits your callback URL
6Read ResultCode 0/otherConfirm the order server-side

Key point: use an idempotent AccountReference per order to avoid double charges on retry. Never confirm an order on the front-end response alone — wait for the ResultCode 0 callback confirmed server-side.

M-Pesa Daraja (Nairobi) vs MTN MoMo (Abidjan)

CriterionM-Pesa Daraja (KE)MTN MoMo (CI)
Merchant fee0 to 0.55 % (Buy Goods)~1.5 %
MechanismSTK Push + callbackrequesttopay + polling
Merchant IDtill number / shortcodeapiuser/apikey
ConfirmationCallback URL POSTPolling GET status
Average latency2-6 s3-8 s
Failure rate6-11 %4-9 %
Recommended timeout60 s90 s

Structural difference: M-Pesa calls you back via a callback URL, while MTN makes you poll the status. The callback model saves requests but demands an always-available public endpoint — plan a queue and rely on Safaricom's own retries.

Mini case study

Wanjiru runs an accessories shop in Nairobi: 300 M-Pesa payments/month, average basket KES 1,500. At 0.55 % her monthly fees are just KES 2,475. But with a 9 % STK Push failure rate she loses 27 sales — about KES 40,500 in revenue. Adding a single retry after a 60 s timeout recovers roughly 60 % of those transient failures, i.e. 16 sales and KES 24,000/month saved. Reliability engineering beats fee optimization here.

FAQ

Need a professional website?

Kolonell builds websites that attract clients, optimized for the Sénégalese market. Free quote in 2 minutes.

Do I need the Daraja sandbox before production?

Yes, absolutely. The sandbox simulates STK Push, PIN entry and failure result codes. Test ResultCode 0, cancellation, timeout and insufficient-funds cases before switching to production keys.

How do I avoid double charges?

Use an idempotent AccountReference per order and check status before any new call. On retry, reuse the same reference so Safaricom recognises the transaction and does not charge twice.

What timeout should I set?

60 seconds for M-Pesa, since the customer must approve the STK prompt and enter their PIN. Below 30 s you cut off in-progress payments and inflate your failure rate.

What if my callback URL is unreachable?

Safaricom retries the callback, but you should still query the transaction status as a fallback. Always expose a health-checked, always-on endpoint behind a queue.

Is MTN MoMo relevant from Nairobi?

Not for selling in Kenya, but essential if you target West Africa. MTN uses requesttopay + polling, a different model you integrate separately.

Let's talk about your project. We integrate M-Pesa Daraja and MTN MoMo with sandbox testing, idempotency and smart retries so you stop losing sales. WhatsApp +221 77 596 93 33.

Tags:#m-pesa#daraja api#mtn momo#payment integration#nairobi#abidjan#checkout#api
Share:

Mohamed Bah

Fondateur, Kolonell

Passionate about digital and entrepreneurship in Africa, Mohamed has been helping Sénégalese businesses with their digital transformation since 2020. Founder of Kolonell, he believes every SME deserves a professional and accessible online présence.