Sandbox Only • No Real Money

Daraja Sandbox

Ansai Technologies - M-Pesa integration test harness (sandbox)

Test endpoint only. This is a test endpoint for the Safaricom sandbox only, using test shortcode 174379. No real money moves. Use it to trigger and verify sandbox STK push flows while you build your M-Pesa integration.

Endpoints

GET or POST /api/push?phone=254798435456&amount=1

Sends a sandbox STK push prompt to the phone. Open as a link or call it from your test app: /api/push?phone=254798435456&amount=1

GET /api/status?checkoutId=...

Queries the result of a push (ResultCode 0 means success). Pass the CheckoutRequestID returned by the push as checkoutId.

POST /api/callback

The callback URL Safaricom calls with the outcome. Configure this URL in your Daraja app or STK push request to receive sandbox results.

Setup

  1. Create an app in the Daraja developer portal (sandbox) and enable M-PESA Express.
  2. In this Vercel project's Settings - Environment Variables, set DARAJA_CONSUMER_KEY, DARAJA_CONSUMER_SECRET and DARAJA_PASSKEY from that app.
  3. Redeploy, then open /api/push to receive a test prompt on the phone.
Note that until step 2 is done the endpoints answer with a 'not configured' JSON message. Add the three variables above and redeploy to activate live sandbox calls.