Websites11 min read

M-Pesa Daraja Sandbox Testing: Validating STK Push Before Go-Live 2026

Mohamed Bah·Fondateur, Kolonell
August 14, 2026
Share:
M-Pesa Daraja Sandbox Testing: Validating STK Push Before Go-Live 2026

M-Pesa Daraja Sandbox Testing: Validating STK Push Before Go-Live 2026

Websites

The verdict in three sentences

A reliable test environment is what separates a calm go-live from a weekend spent refunding angry customers. In 2026, set up a webhook tunnel (ngrok or equivalent), simulate the STK push callbacks, and replay every event until success, timeout and cancellation are all handled. The rule: never ship a payment flow that has not passed a checklist of at least 12 test cases.

Building the sandbox step by step

M-Pesa Daraja uses an STK push (a prompt on the customer's phone), while other operators like Orange Money use a web redirect with a notification URL. The testing principle is the same: an isolated environment, test credentials, and a callback endpoint reachable from the internet.

Test element2026 value / toolRole
Local tunnelngrok, cloudflaredExpose localhost to the callback
Callback URLhttps://xxxx.ngrok.io/webhookReceive payment status
Test accountProvided by operatorPay with no real money
STK timeout60 secondsSimulate expiration
Daraja test shortcode174379Safaricom sandbox
Event replayLog + manual POSTTest idempotency
Webhook signatureHeader to verifyReject fake calls

The classic trap: coding only the happy path (the customer pays, everything works). In reality 20 to 30 % of attempts end in timeout, cancellation or insufficient balance. Each of these cases needs a defined and tested behavior.

The 12-case checklist and their actions

Here are the statuses to cover and the expected action from your back end. Do not sign off the test phase until all 12 are green.

#Test caseStatus receivedExpected action
1Successful paymentsuccessFulfill, mark paid
2Insufficient balancefailedFulfill nothing, clear message
3Customer cancelscancelledRelease the cart
4STK timeout 60 stimeoutMark pending, retry
5Double callbacksuccess x2Idempotency, one fulfillment
6Wrong amountmismatchReject, alert
7Invalid signatureIgnore, log
8Unknown reference404Log, no fulfillment
9Late callbacksuccessFulfill if not already done
10Customer network droppendingServer verify on return
11RefundrefundedCancel the order
12Manual replaysuccessNo double effect

Cases 5 and 9 are the most often forgotten and the most costly: they test idempotency, the ability to receive the same event twice without fulfilling twice.

Mini case study

Grace, who runs an online-ordering eatery in Nairobi, launched without serious testing. The first Friday night, a traffic spike on mobile data generated dozens of timeouts. Her system, handling only the happy path, left orders stuck without ever confirming or cancelling. The result: 23 phantom orders, a paralyzed kitchen, and 34,000 KES of tickets impossible to reconcile that evening. After building a sandbox and validating the 12 cases (especially timeout and replay), the stuck-order rate fell below 1 %. The test phase cost 2 days of work; the ruined weekend had cost far more.

Need a professional website?

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

FAQ

How long does an M-Pesa STK push stay active in the 2026 sandbox?

About 60 seconds. Without a PIN entry in that window, the request expires and you get a failure or timeout status. Test this case explicitly, it is one of the most common in production.

Do I need a tunnel like ngrok to test webhooks?

Yes, in local development. The operator must reach your callback from the internet, and localhost is not accessible. A tunnel exposes your local URL during testing.

Which shortcode do I use for the Daraja sandbox?

The test shortcode 174379 in the Safaricom sandbox environment. It lets you simulate an STK push with no real money movement.

How many cases should I test before production?

At least 12: success, failure, cancellation, timeout, double callback, refund and manual replay. The idempotency cases (double callback, late callback) are non-negotiable.

Can I replay a webhook event to test?

Yes, and it is essential. Keep the payload in your logs and re-POST it manually: your system must produce exactly the same result as the first time, with no double effect.

Let's talk about your project. We build your mobile money sandbox and validate every webhook before go-live. WhatsApp +221 77 596 93 33.

Tags:#orange money#m-pesa#daraja#sandbox#webhooks#recette#kenya#test
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.