paylod
Test in sandbox

Guides

Test in sandbox

.md

Build the whole flow against Safaricom's sandbox with test credentials — including the failure paths — before a shilling moves.

Get sandbox credentials

Create an app on the Safaricom Daraja portal and open its Sandbox credentials. You want four values:

FieldSandbox value
Consumer keyFrom the Daraja portal
Consumer secretFrom the Daraja portal
Shortcode174379 (Safaricom's shared test paybill)
PasskeyFrom "Lipa na M-Pesa Online" in the portal

Paste them into your application's Sandbox environment in paylod, then mint an mp_test_… key.

What sandbox actually does

Sandbox is Safaricom's own environment, not a paylod mock. The STK Push is real: it goes to Daraja, Daraja answers, and the callback comes back to paylod's hosted receiver exactly as it would in production. What is not real is the money — nothing settles.

That means the shape of everything you build — the 202, the paymentId, the webhook envelope, the signature, the result codes — is identical in production. There is no second integration to write.

Send a test payment

Set PAYLOD_API_KEY to the mp_test_… key. Nothing else changes.

sandbox.ts
import { Paylod } from "@paylod/node";

const paylod = new Paylod(process.env.PAYLOD_API_KEY!);   // mp_test_… key

const outcome = await paylod.collectAndWait({
  amount: 10,
  phone: "254708374149",     // Safaricom's published test MSISDN
  accountReference: "TEST-1",
});

console.log(outcome.paid ? outcome.receipt : outcome.message);

Use a real number you control and you will get a real prompt, with no real money attached.

Exercise the failure paths

Most production incidents are failure paths nobody tried. Before you go live, make sure your code does something sensible for each of these:

Result codeHow to trigger it in sandboxWhat your code should do
1032Press Cancel on the promptShow a friendly retry, do not fulfil
1037Ignore the prompt until it expiresRetry, or fall back to polling
2001Enter the wrong M-Pesa PINAsk them to try again
1Push an amount above the test balanceTell the customer the balance is low

Every code, with its cause and fix, is in the error reference.

Test your webhook locally

No tunnel needed. The CLI streams your live webhook events to localhost with the signature intact:

Terminal
npx @paylod/cli listen --forward http://localhost:3000/webhook

Your handler verifies a real signature against a real payload, on your laptop. See Handle the result.

Next

Go live — swap the credentials, swap the key, keep the code.