Testing
There are three separate ways to test, and they answer different questions:
| What you want to prove | Use | Real money? |
|---|---|---|
| Your app → VectaPay → the provider → a real phone → your webhook | Smoke test (Developer → Testing) | Briefly — Safaricom credits it back a few minutes later |
| Your handler reacts correctly to every outcome, including failures | Webhook simulator (Developer → Webhooks → Send test event) | No — nothing is charged |
| Your Paystack checkout (cards, bank transfer) works | Paystack test keys in a Payment Method | No — Paystack’s test mode |
Everything below applies only to a pk_test_ key. A pk_live_ key never enters test mode — see
Authentication.
The smoke test, in one minute
The smoke test is a real end-to-end run: your backend calls collect(), VectaPay sends a real
M-Pesa prompt from our own test line, you enter your M-Pesa PIN on your own phone, Safaricom
settles it in its sandbox, and VectaPay fires a signed payment.succeeded webhook back to you.
Nothing in that path is simulated by VectaPay — the money is charged and then credited back a few
minutes later.
Step 1 — Verify the phone you’ll test with
Open Developer → Testing, enter a Safaricom number you can reach right now, and send the request. You’ll get one KES 10 M-Pesa prompt on that phone. Enter your PIN, and the completed payment marks the number as verified.
There is no SMS code and no separate “validate number” step. Completing a payment is the proof: only someone holding the handset can enter the PIN.
- KES 10 is the smallest amount M-Pesa accepts. It is charged on the sandbox test line, and Safaricom credits it back a few minutes later.
- A number stays verified until you verify a different one or choose Forget this phone. A new number is unverified until it completes its own prompt.
- Verification prompts are rate-limited to 5 per business per day and 3 per phone per day.
Exceeding either returns
429with aretryAfterSecondshint. - Only business roles with technical access (Owner, Admin, Developer) can verify a phone.
Step 2 — Send a test payment from your app
Create a pk_test_ key under Developer → API Keys, then make a normal
collect() call to the verified number:
const payment = await vectapay.payments.collect({
customer: { phone: "254712345678" }, // must be the verified number
amount: money(1000), // any amount; Safaricom credits it back
reference: "SMOKE-001",
description: "Smoke test",
});Test mode enforces three rules, each with a clear error instead of a silent surprise:
| Rule | What happens if you break it |
|---|---|
| The customer phone must be your verified test phone. | 400 — verifies the last three digits so you know which number to use. |
You cannot pass providerAccountId. | 400 — test payments always run on our test line. |
| M-Pesa is the only rail test mode can prompt. | Card/bank goes through a Paystack test account instead (below). |
Test payments are rate-limited to 5 per business per hour, 20 per business per day, and
2 per phone per hour. A blocked prompt returns 429 with retryAfterSeconds — the limits
exist so a leaked test key can’t be used to spam a handset, and test traffic never bills.
Step 3 — Watch it land
Turn on Sandbox view in Settings → Account (Developer mode required). Payments, Home, and Reports then show test activity only, with a banner on every page; production data is hidden until you switch it off. The toggle is per browser and never changes what a teammate sees.
Your webhook receives the same signed delivery as live traffic. The envelope’s top-level
environment is "test", and the payment carries providerAccountUsed.environment: "SANDBOX".
Simulating outcomes
Safaricom’s sandbox is reliable at one thing: completing a payment. It is not a good way to
produce FAILED, CANCELLED, or EXPIRED — and there is no documented set of test numbers that
trigger them.
Use Developer → Webhooks → Send test event instead. Pick any event your handler subscribes to, optionally edit the payload, and it is delivered to your configured URL exactly like a real delivery — same signature scheme, same headers — with two extra top-level fields:
{
"id": "evt_...",
"type": "payment.failed",
"environment": "test",
"test": true,
"createdAt": "2026-08-26T10:15:00Z",
"data": {
"paymentId": "test_1756203300000",
"status": "failed",
"failure": { "code": "CUSTOMER_CANCELLED", "message": "Request cancelled by user" }
}
}test: trueis only ever set on a simulated delivery. Real traffic — test mode or live — never carries it. Branch on it when a simulated event must not touch a real order.environment: "test" | "live"is present on every delivery, real or simulated, and tells you which provider environment produced it.- A simulated delivery does not create or change a payment record. It only exercises your endpoint.
- The event has to be ticked in your webhook subscriptions first. The simulator will not send one you haven’t subscribed to.
A simulated delivery is a real delivery as far as the pipeline is concerned: it is logged, it retries on the same five-attempt schedule as live traffic, and a failing endpoint counts it toward the five-failure pause. That is the point — a test that passes tells you the endpoint will accept the real event.
See Testing Your Endpoint for the full simulator workflow, the payload each event type gets, and troubleshooting.
Paystack test keys
Paystack is the one provider where you bring test credentials, because its test mode is a
separate pair of keys rather than a shared platform line. Add a Payment Method with your Paystack
test keys (sk_test_…) and VectaPay stores it as a test account — it can never take real
money.
- The wizard detects the
sk_test_prefix automatically; there is no separate “sandbox” switch. - A Paystack test account can back a payment link (a test link) and a hosted-checkout
collect()with anemailand no phone. - It is never used implicitly for M-Pesa prompts. Those go to the test line above.
- Replace the keys with your live keys when you’re ready to accept real payments — the same
account switches to live, and payments it already took keep their
SANDBOXenvironment. If the account is used by a payment link, remove it from the link first: switching the account would otherwise change what customers pay through that link.
What test mode cannot do
Test keys are deliberately limited to collecting money:
- Payouts, refunds, payment retries, and batch operations are live-only. A
pk_test_key on those routes returns401withAPI key environment mismatch. Required: LIVE, Got: TEST. - Payment links are production artefacts — they outlive your session and are handed to customers. Only live payment methods (and Paystack test-key accounts, which are explicitly labelled) can back one.
- Airtel Money has no test mode at all. Its sandbox cannot prompt a real handset, so VectaPay refuses to create a SANDBOX Airtel account. Connect real Airtel credentials when you’re ready to collect through it.
Going live
M-Pesa and Airtel have no environment switch — the accounts you connect are always production accounts, and test payments never go through them. A Paystack account is the exception: its environment follows the key pair it stores, so updating it with live keys makes it a live account.
Connect your real payment method
Payment Methods → Connect a payment method — your Paybill/Till and Daraja credentials, an Airtel merchant number, or live Paystack keys. See Connecting a Payment Method.
Create a live API key
Developer → API Keys → Create key, choose Live, and swap it into your server’s environment variable. Test responses and live responses use the same shapes; only the key changes.
Point your webhook at a public URL
localhost won’t work — use a tunnel while developing, then your real HTTPS domain. A production
webhook URL must use HTTPS.
Check the things that only bite in production
- You branch on
FailureCodevalues, not provider error strings. - You send an
idempotencyKeyon every request your own code can retry. - Your endpoint acknowledges with
200before doing slow work, and dedupes onIdempotency-Key.