Sandbox credentials
Create a sandbox app
Section titled “Create a sandbox app”- Sign in at developer.safaricom.co.ke.
- Go to My Apps and create an app, selecting the products you need.
- Copy the Consumer Key and Consumer Secret into your
.env.
Products are per-app. If a call returns Invalid API call as no apiproduct match found, the product is not attached to the app you generated the token with.
Test credentials
Section titled “Test credentials”The portal’s Test Credentials page supplies the sandbox short code, initiator name, initiator password and the M-Pesa Express passkey. These are shared sandbox values, not secrets.
DARAJA_MODE=sandboxDARAJA_STK_SHORTCODE=174379DARAJA_INITIATOR_NAME=testapiDARAJA_INITIATOR_SHORTCODE=600000Verify the credentials
Section titled “Verify the credentials”php artisan daraja:tokenTest numbers
Section titled “Test numbers”Safaricom’s sandbox accepts 254708374149 for most APIs. Real numbers work for
M-Pesa Express in sandbox and will genuinely ring the handset — the payment does
not complete, but the prompt appears.
What sandbox will not do
Section titled “What sandbox will not do”- C2B simulation is sandbox-only. The package throws a
DarajaExceptionif you callsimulatePayBill()orsimulateBuyGoods()whilemodeislive. - Callbacks still need a public URL. Sandbox permits HTTP, but Safaricom must still be able to reach your host from the internet.
- Some APIs are production-only. M-Pesa Ratiba and B2B Express Checkout are commercial products requiring a signed agreement, so sandbox coverage is limited.
Testing without Safaricom
Section titled “Testing without Safaricom”Most of the time you should not be hitting sandbox at all. The package is built
on Laravel’s HTTP client, so Http::fake() intercepts everything — see
Testing.