Testing in the sandbox
Build your integration against Safaricom's Daraja sandbox with test money, then switch the same account to production.
A sandbox account
- Create an app on developer.safaricom.co.ke and copy its consumer key and secret.
- In Dashboard → Accounts, add an M-PESA account with environment sandbox, the test shortcode and passkey Daraja shows under its simulator (STK: shortcode
174379), and your app's keys. - Use its account id in the API exactly as you will in production. Responses are the same shape;
environmentsayssandbox.
STK Push
Send to a Safaricom number you hold, or the test number Daraja lists. The sandbox does not always send a real prompt or a callback; when the callback never comes, we still ask Daraja for the result after a couple of minutes, so the payment settles or fails either way.
C2B
Register the C2B URLs on the sandbox shortcode Daraja gives you for C2B (a 600xxx number), then use Simulate C2B on the account page to have Daraja send a test payment with the account number you choose. It arrives as a normal C2B webhook.
Webhooks
Send test event on an endpoint delivers a signed webhook.test. Each payment's page in the dashboard lists every delivery attempt and its HTTP answer, and can resend.
Going live
On the account page, Move to production walks you through your production shortcode, passkey and keys from Safaricom's Go Live. Then press Register C2B URLs again for the production shortcode. The account id stays the same, so your code does not change.
Real money