Skip to content

Sandbox credentials

  1. Sign in at developer.safaricom.co.ke.
  2. Go to My Apps and create an app, selecting the products you need.
  3. 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.

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=sandbox
DARAJA_STK_SHORTCODE=174379
DARAJA_INITIATOR_NAME=testapi
DARAJA_INITIATOR_SHORTCODE=600000
Terminal window
php artisan daraja:token

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.

  • C2B simulation is sandbox-only. The package throws a DarajaException if you call simulatePayBill() or simulateBuyGoods() while mode is live.
  • 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.

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.