Sandbox testing
Environment: Live
The full sandbox: test numbers and magic amounts for every outcome, the fixed OTP, webhooks, the trigger and reset endpoints, bulk and invoice behaviour, and a test plan.
# Sandbox testing
The full sandbox: test numbers and magic amounts for every outcome, the fixed OTP, webhooks, the trigger and reset endpoints, bulk and invoice behaviour, and a test plan.
## What the sandbox is
The sandbox at https://sandbox.moolre.com runs the same API code as live, with a sandbox switch. The endpoints, request fields, response envelopes and codes are the same, so a working sandbox integration is a working live integration with different credentials and a different base URL.
Everything in the sandbox is simulated. No real money moves, no mobile money provider is called, and no SMS is sent to a test number. Pending transactions settle by themselves: a worker runs every minute, and reading a status endpoint also settles anything that is due.
Sandbox responses carry an extra sandbox block that names the scenario the simulator chose and what happens next. It is not part of the live API: do not depend on it in code that must also run live.
## Your first sandbox calls
Follow these in order. Each step tells you what to send and what you should get back.
1. Create a sandbox wallet with Create Account (sandbox only). It returns an account number. Keep it: it goes in accountnumber on every call. If your wallet already exists in production, it is copied into the sandbox the first time you use its account number (name only: its callback URL and secret are not copied).
2. Send your username in X-API-USER. Keys are optional in the sandbox, but if you send X-API-KEY it must be your private key: a wrong key returns AIN05. The server may also be set to require the key on every request, exactly as live does, so send it from day one. Public keys signed by the live API are not accepted by the sandbox.
3. Set a callback URL on the sandbox wallet with Update Account (callback). Sandbox events go only to this URL, never to your live callback.
4. Make a collection to a test number such as 0240000111 (see the table below). Without skipotp the first call returns TP14: for a test number no SMS is sent and the OTP is always 123456.
5. Check the result with Payment Status, or wait for the payment.succeeded webhook. A pending scenario settles on its own after the delay in the table.
6. Reset your test data whenever you want a clean slate (see Reset below).
```curl
curl https://sandbox.moolre.com/open/transact/payment \
-H "Content-Type: application/json" \
-H "X-API-USER: $MOOLRE_USER" \
-d '{
"type": 1,
"channel": "MTN",
"currency": "GHS",
"payer": "0240000111",
"amount": "10.00",
"externalref": "SBX-ORDER-1",
"accountnumber": "1000000000001"
}'
```
```json
{
"status": 1,
"code": "TP14",
"message": "Please complete the verification process sent to you via SMS and try again.",
"data": "all",
"go": null,
"sandbox": {
"otp": "123456",
"note": "Test number: no SMS was sent. Use otpcode 123456."
},
"meta": {
"requestid": "req_c68f4c66115c26725c796242",
"notices": []
}
}
```
## How an outcome is chosen
The simulator picks the outcome from the first rule that matches, strongest first:
1. The status field of the request (sandbox only): pending, success, failed, timeout, wrong_pin, insufficient_funds, declined, expired, provider_error, not_registered, limit_exceeded, pending_success, pending_failed or random. The numbers 0 (pending), 1 (success) and 2 (failed) also work. It applies to collections and payouts only.
2. The last three digits of the payer (collections) or the receiver (payouts, bulk items and name validation; for BANK the account number). Any number works, and the recommended test numbers are <prefix>0000<code>, for example 0240000111.
3. The cents of the amount, when the number is not a scenario number (see Magic amounts).
4. Otherwise the default: random, with 85 percent success, 7 percent pending and 8 percent failed (or always success when the server is configured that way).
> **Number formats:** Phones may be written 0240000111, 233240000111 or +233240000111. Network prefixes: MTN 24 25 53 54 55 59, Telecel 20 50, AT 26 27 56 57. The bank test account is 0000000111 (seven zeros and the code).
## Test numbers (last three digits)
Use these to rehearse every outcome your code must handle. A failure always returns txstatus 2 with a reason, and a pending result keeps txstatus 0 until it settles.
| Last 3 digits | Scenario | Collection | Payout or bulk item | Name validation |
| --- | --- | --- | --- | --- |
| 111 | Success | Succeeds at once | Succeeds, code OBGH01 Pay out Successful | Found, holder name SANDBOX TEST SUCCESS |
| 222 | Pending 60 s, then success | Pending, succeeds after 60 s | APY16 in progress, succeeds after 60 s | Found |
| 333 | Insufficient funds | Fails, reason LOW_BALANCE_OR_PAYEE_LIMIT_REACHED_OR_NOT_ALLOWED | Fails, OM14 insufficient balance | Found |
| 444 | Timeout, then success | Pending, succeeds after 30 s | Single payout: pending, then succeeds after 30 s. Bulk item: first send times out (BLK30), returns to queued, then succeeds | Found |
| 555 | Outcome unknown | Stays pending for ever (settle it with the trigger endpoint or reset) | Stays pending: a single payout answers APY16, a bulk item reports pending with BLK30. A batch containing it never completes by itself | Lookup times out, AVD03 |
| 666 | Provider error | Fails, reason NETWORK_UNAVAILABLE | Fails, OM16 could not be started, not charged (bulk: after 3 attempts) | Found |
| 777 | Declined | Fails, reason TRANSACTION_DECLINED | Fails, PY05 | Found |
| 888 | Not registered | Plain failure | Fails, OM06 not an MTN MoMo subscriber | Not found, AVD02 |
| 999 | Wrong PIN | Fails, reason WRONG_PIN | Plain failure, PY05 | Found |
| 998 | Payer declined | Fails, reason PAYER_DECLINED | Plain failure, PY05 | Found |
| 997 | Prompt expired | Fails, reason PROMPT_EXPIRED | Plain failure, PY05 | Found |
| 996 | Limit exceeded | Fails, reason LIMIT_EXCEEDED | Fails, PY05 | Found |
| 1NN (not 111) | Pending, success after NN seconds (01 to 99) | As stated | APY16, then success | Found |
| 2NN (not 222) | Pending, failure after NN seconds | As stated, reason TRANSACTION_DECLINED | APY16, then failure | Found |
| 404 | Name not found (validate only) | Not applicable | Not applicable | Not found, AVD02 |
| 408 | Lookup timeout (validate only) | Not applicable | Not applicable | AVD03 |
## Magic amounts
When the number is not a scenario number, the cents of the amount choose the outcome. For example 10.91 or 250.95:
| Cents | Same as | Result |
| --- | --- | --- |
| .91 | 777 | Failed (declined) |
| .92 | 333 | Insufficient funds |
| .93 | 999 | Wrong PIN (collections) |
| .94 | 998 | Declined by the payer (collections) |
| .95 | 130 | Pending, success after 30 s |
| .96 | 230 | Pending, failure after 30 s |
| .97 | 555 | Stays pending |
| .98 | 666 | Provider error |
| .99 | 888 for payouts, 777 for collections | Receiver not registered (payout) or plain failure (collection) |
## The one-time code in the sandbox
Without skipotp, the first collection call answers TP14. For a test number (<prefix>0000<code>) no SMS is sent and the OTP is always 123456; the sandbox.otp field of the TP14 reply says so. A real phone number receives a real SMS.
The OTP limits apply in the sandbox exactly as live: 3 sends per phone per 10 minutes, 10 per phone per day, 30 per IP per hour, and 5 wrong codes invalidate the code. The refusal is OTP429 (HTTP 429 in strict mode).
1. Send the collection. You get TP14.
2. Send the same request with "otpcode": "123456". You get TP17 (Phone number verification successful).
3. Send the original request once more, without otpcode. You get the payment prompt reply (TR099) and the scenario starts.
> **Skip the OTP while building:** In the sandbox you can send "skipotp": true to go straight to the payment prompt. Remove it before you go live: it is rejected by the live API.
## What happens to the sandbox wallet
- Collections: success credits the sandbox wallet (the starter balance is GHS 1,000.00). Failure and pending credit nothing; a pending one credits when it settles.
- Payouts are charge-first like live: the amount plus the sandbox fee (1 percent) is reserved when the payout is accepted. A failure never takes the money, and a pending payout that later fails is refunded. APY21 (Insufficient wallet balance) appears when the balance is too low.
- Pending transactions settle by themselves: a one-minute worker, and whenever you read Payment Status, Account Status (type 2), the account list or a bulk read.
- Status returns txstatus 0 pending, 1 successful, 2 failed, plus reason on failures and created_at (ISO 8601 UTC).
## Callbacks and webhooks in the sandbox
Callbacks go to the callback URL of the sandbox wallet and webhooks to its webhook_url, never to your live URLs, and both are signed with the sandbox wallet secret. Headers and bodies are the same as live. Verify the signature exactly as in the guides. A sandbox transaction webhook carries one hook (live can list up to 100); use bulk_payout.completed to test a list. Payouts and settlements have no callback.
Set the callback with Update Account (callback), and switch webhooks on with webhook 1 and webhook_url. A wallet copied from your live wallet starts without either. Local development needs a public HTTPS URL (a tunnel): callback URLs that point to private or loopback addresses are refused.
Failed deliveries are retried at 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 24 hours, 48 hours and 72 hours. Webhook deliveries, Resend webhook and Send test webhook work in the sandbox with the same contract as live.
| Event | Callback | Webhook |
| --- | --- | --- |
| payment.succeeded | P01 | P01 |
| payment.failed | P02, data.reason says why | P02 |
| payout.succeeded, payout.failed, payout.reversed | None | P11, P12, P13 |
| settlement.succeeded, settlement.failed, settlement.reversed | None | P21, P22, P23 (fire them with the trigger endpoint) |
| bulk_payout.completed | Batch summary, sent once | BLK40, with every payout |
| webhook.test | WHT00, when the wallet has no webhook_url | WHT00 |
## Trigger any event on demand
POST /open/sandbox/trigger (private key, sandbox only) sends any event to your sandbox wallet, as a webhook when webhooks are on and as a callback for the events that have one, so you can test every branch of your handler without waiting. With an id it acts on a real sandbox record: a pending payment settles that way and the balance, status and event all agree. Without an id it sends a sample event and does not touch the balance.
| event | With an id | Without an id |
| --- | --- | --- |
| payment.succeeded, payment.failed | externalref or transactionid of a pending payment settles it that way. A finished payment re-sends the same outcome with a new event_id (SBX05 if you ask for the opposite) | A sample event (amount optional). The balance is not touched |
| payout.succeeded, payout.failed | Same, for a payout (a failure refunds the reserved amount) | Sample |
| payout.reversed | Reverses a successful payout: the money goes back to the wallet | Sample |
| settlement.succeeded, settlement.failed, settlement.reversed | Not applicable | Sample |
| bulk_payout.completed | batchid finishes the batch: pending items settle as final "succeeded" (default) or "failed". The completion event is sent once | Sample |
| webhook.test | Not applicable | A signed test event, one attempt |
| invoice.paid (an action: nothing is sent) | invoiceid pays the invoice (amount pays part, then the invoice reads partially_paid) | Not applicable |
```curl
curl https://sandbox.moolre.com/open/sandbox/trigger \
-H "Content-Type: application/json" \
-H "X-API-USER: $MOOLRE_USER" \
-H "X-API-KEY: $MOOLRE_KEY" \
-d '{
"accountnumber": "1000000000001",
"event": "payment.succeeded",
"externalref": "SBX-ORDER-1"
}'
```
```json
{
"status": 1,
"code": "SBX01",
"message": "Event sent.",
"data": {
"event": "payment.succeeded",
"transactionid": "1001",
"event_id": "evt_0123456789abcdef01234567",
"delivered": true,
"state": "delivered",
"http": 200,
"error": null,
"webhook": null,
"callback": {
"event_id": "evt_0123456789abcdef01234567",
"delivered": true,
"state": "delivered",
"http": 200,
"error": null
}
},
"go": null,
"meta": {
"requestid": "req_c68f4c66115c26725c796242",
"notices": []
}
}
```
> **Trigger errors:** SBX02 webhooks are off, and no callback URL for an event that has one (422), SBX03 bad event or parameter (400), SBX04 batch or invoice not found (404), SBX05 contradictory request (409), SBX06 cannot be settled (409), SBX10 wallet not found (404), SBX13 a public key was used (403).
- [Trigger a sandbox event (API reference)](https://docs.moolre.com/api/sandbox/trigger)
## Reset your test data
POST /open/sandbox/reset (private key, sandbox only) clears test data for one wallet that is yours. scope is all (default), transactions (also clears OTP and idempotency rows and restores the balance), balance, webhooks, bulk or invoices. After a reset an externalref can be used again.
```curl
curl https://sandbox.moolre.com/open/sandbox/reset \
-H "Content-Type: application/json" \
-H "X-API-USER: $MOOLRE_USER" \
-H "X-API-KEY: $MOOLRE_KEY" \
-d '{
"accountnumber": "1000000000001",
"scope": "all",
"balance": "1000.00"
}'
```
```json
{
"status": 1,
"code": "SBR01",
"message": "Sandbox data reset.",
"data": {
"deleted": {
"transactions": 12,
"webhook_deliveries": 4
},
"balance": "1000.00"
},
"go": null,
"meta": {
"requestid": "req_c68f4c66115c26725c796242",
"notices": []
}
}
```
> **Reset errors:** SBR03 bad scope, SBR04 bad balance, SBR10 wallet not found, SBR13 a public key was used.
- [Reset sandbox data (API reference)](https://docs.moolre.com/api/sandbox/reset)
## The catalogue as JSON
POST /open/sandbox/scenarios is public and read-only. It returns the same catalogue as this page as JSON, so a test suite can read the scenarios instead of hard-coding them.
- [List sandbox scenarios (API reference)](https://docs.moolre.com/api/sandbox/scenarios)
## Bulk payouts in the sandbox
Bulk payouts have the same contract, codes and limits as live (BLK01 queued, BLK02 replay, BLK09 batchref conflict, BLKR01 to BLKR13 row codes, 500 items, 20 active batches, atomic). A simulated worker moves each item from queued to submitted (about 3 seconds) and then to the outcome the receiver's last three digits choose (payout column above), and, when every item is final, sends bulk_payout.completed. With webhooks on, each payout also sends payout.succeeded or payout.failed.
Reading Bulk payout status or List bulk payouts advances the batch, so polling is enough. Items that match no scenario succeed. A batch that contains a 555 receiver stays processing until you trigger bulk_payout.completed with its batchid.
## Invoices in the sandbox
Invoices have the same fields, validation and codes as live (INV01 created, INV02 replay, INV07 reference conflict, INV12 not found, INV17 cancelled, INV18 has payments). The invoice id is {wallet id}-{n}, payment_link is https://sandbox-invoice.moolre.com/{service_id}-{id} and payment_code is *203*062{n}#. The wallet is the single service, so service_id is optional and must equal the wallet id when sent.
Pay an invoice with the trigger endpoint: event invoice.paid with invoiceid, and an optional amount for a part payment. Nothing is sent. A past due date while unpaid reads overdue.
## Other sandbox behaviour
- Validate Name is simulated and never asks a provider: it uses the last column of the test number table. Unknown numbers are found with a stable fake holder name, so the same number always gets the same name.
- Channel names MTN, TELECEL, AT, BANK and GHQR work everywhere. Numeric ids still work and add a DEPRECATED_NUMERIC_CHANNEL notice.
- Idempotency-Key works on payment, transfer, bulk and invoice create: the same key and body replays the answer with meta.replayed true; another body is IDEM01.
- sendername on transfers is validated: 2 to 30 characters, letters, spaces, full stop, apostrophe and hyphen, starting with a letter, otherwise APY22 (the sandbox is a little more lenient: it also accepts digits and up to 40 characters, but write for the live rule)
- Account Status (type 2) and the account list return sandbox transactions with from, to, starting_after, limit and status, and rows carry created_at. Payment Status types 2 and 3 cover payment IDs.
- Send X-Moolre-Http-Status: strict to get real HTTP status codes (400, 401, 403, 404, 409, 422, 429, 5xx) instead of always 200.
- Wallets belong to their account: another account's wallet number is reported as not found.
## A sandbox test plan for your integration
Run each of these before you go live. They cover the outcomes that cause most production incidents.
- [ ] Collection succeeds (…111) and you fulfil the order exactly once, even if the webhook arrives twice.
- [ ] Collection fails with wrong PIN (…999) and insufficient funds (…333): you show the reason and let the customer retry with a new externalref.
- [ ] Collection pending 60 s (…222): your order stays pending, then completes from the webhook.
- [ ] Collection stays pending (…555): your reconciliation job finds it with Payment Status and does not release goods.
- [ ] Wrong OTP five times: you handle OTP429 and tell the customer to wait.
- [ ] Payout succeeds (…111), fails (…333, …666, …777, …888) and is pending (…222, …555): a pending payout is never resent.
- [ ] A timeout is simulated by dropping your own connection: the retry with the same Idempotency-Key replays the answer.
- [ ] Callback and webhook endpoints: wrong signature is rejected, an old timestamp is rejected, a repeated event_id is ignored, and Send test webhook returns delivered true.
- [ ] Bulk batch with a bad row: the rejected rows are reported and the rest complete.
- [ ] Invoice: create, pay with the trigger endpoint, see it paid with Invoice status; cancel an unpaid one.