# How do I simulate errors?
Source: https://docs.lomi.africa/build/reliability/simulate-errors

Test declines, authentication challenges, async mobile money, and webhook failures before go-live.

***

title: 'How do I simulate errors?'
description: 'Test declines, authentication challenges, async mobile money, and webhook failures before go-live.'
docType: how-to
---------------

import { Callout } from '@/components/docs/docs-callout';
import { DocsAgentIndex } from '@/components/docs/docs-agent-index';

<DocsAgentIndex />

Use this index to exercise failure paths in **sandbox**. This page is the **scenario matrix**. Full test card numbers and MoMo behavior live in **[Sandbox payments](/start/sandbox-payments)**. How to structure tests: **[Testing guide](/build/reliability/testing)**.

<Callout type="warn">
  Run these scenarios only with **test API keys** (`lomi_sk_test_...`). Never use test card numbers in live mode.
</Callout>

## Scenario matrix

| Scenario                                           | How to trigger                                                    | Expected outcome                             | Learn more                                                                  |
| -------------------------------------------------- | ----------------------------------------------------------------- | -------------------------------------------- | --------------------------------------------------------------------------- |
| Card approved                                      | `4242 4242 4242 4242` on hosted checkout                          | `completed`, test balance credit             | [Sandbox payments: cards](/start/sandbox-payments#testing-card-payments)    |
| Card declined                                      | Decline test PANs in sandbox table                                | `failed`                                     | Same section                                                                |
| 3D Secure / authentication                         | Auth-required test cards                                          | `requires_action` or challenge UI            | [Sandbox payments](/start/sandbox-payments)                                 |
| Wave (test)                                        | Select Wave on sandbox checkout                                   | Often immediate `completed`                  | [Wave](/build/payment-methods/wave)                                         |
| MTN (test)                                         | `POST /charge/mtn` with test MSISDN                               | Immediate `completed` on test key            | [MTN](/build/payment-methods/mtn-momo)                                      |
| Direct MoMo `pending` (test)                       | `X-Scenario-Key: pending` on `POST /charge/mtn` or `/charge/wave` | Charge stays `PENDING`; no auto-complete     | [Sandbox payments: scenarios](/start/sandbox-payments#testing-mobile-money) |
| Direct MoMo `failed` (test)                        | `X-Scenario-Key: failed` on `POST /charge/mtn` or `/charge/wave`  | `400` error response                         | Same section                                                                |
| MTN (live)                                         | Real MSISDN, live key                                             | Starts `PENDING`                             | [Verify payments](/build/reliability/verify-payments)                       |
| Pending expiration                                 | Wait beyond session/transaction TTL                               | `expired` or `failed`                        | [Payment and payout lifecycle](/build/reliability/payment-lifecycle)        |
| Webhook signature failure                          | POST without valid `X-Lomi-Signature`                             | Your endpoint returns 4xx; lomi. retries     | [Handling webhooks](/build/reliability/handling-webhooks)                   |
| Duplicate webhook                                  | Replay same event `id`                                            | Your handler dedupes; no double fulfill      | [Webhook reliability](/build/reliability/webhook-reliability)               |
| Insufficient balance payout                        | Test payout rules in sandbox                                      | `400` or `failed` payout                     | [Payouts in test mode](/start/sandbox-payments#payouts-in-test-mode)        |
| Invalid API key                                    | Omit or wrong `X-API-Key`                                         | `401`                                        | [Authentication](/api/authentication)                                       |
| Rate limit                                         | Burst requests in test                                            | `429`                                        | [Error handling](/build/reliability/error-handling)                         |
| Card 3DS via `X-Scenario-Key`                      | Not supported                                                     | Use test PANs                                | [Sandbox payments](/start/sandbox-payments#testing-card-payments)           |
| MoMo redirect vs push via header                   | Not supported                                                     | Wave is a launch URL; MTN is a push          | [Mobile money](/build/mobile-money)                                         |
| Payout `insufficient_balance` via `X-Scenario-Key` | Not supported                                                     | Follow payout test rules (Wave is live-only) | [Payouts in test mode](/start/sandbox-payments#payouts-in-test-mode)        |
| Open a dispute in sandbox                          | Not supported                                                     | Live card-network events only                | [Disputes](/build/money/disputes)                                           |

## Direct charge scenarios (test key only)

On **`POST /charge/mtn`** and **`POST /charge/wave`**, send `X-Scenario-Key` to override default test behavior. This applies to **direct charges only**-hosted checkout and card charges do not read this header yet.

| Header value | Behavior                                                     |
| ------------ | ------------------------------------------------------------ |
| *(omit)*     | Default: test charge auto-completes and credits test balance |
| `pending`    | Charge remains `PENDING`; no auto-complete (poll or webhook) |
| `failed`     | Request fails with `400`                                     |

```bash
# Keep charge pending (CI / dunning tests)
curl -sS -X POST "https://sandbox.api.lomi.africa/charge/mtn" \
  -H "X-API-KEY: $LOMI_SECRET_KEY" \
  -H "X-Scenario-Key: pending" \
  -H "Content-Type: application/json" \
  -d '{"amount":1000,"currency":"XOF","customer_phone":"+2250700000000"}'

# Simulate provider failure
curl -sS -X POST "https://sandbox.api.lomi.africa/charge/wave" \
  -H "X-API-KEY: $LOMI_SECRET_KEY" \
  -H "X-Scenario-Key: failed" \
  -H "Content-Type: application/json" \
  -d '{"amount":1000,"currency":"XOF","customer_phone":"+2250700000000"}'
```

## Automation

For CI and integration tests, see [Testing guide](/build/reliability/testing) and use sandbox `curl` recipes in [Sandbox payments](/start/sandbox-payments#api-and-hosted-checkout-recipes).

<DocsNextSteps>
  <DocsNextStep href="/start/integration-journey" hint="Sandbox to live">
    Integration journey
  </DocsNextStep>

  <DocsNextStep href="/start/go-live" hint="When failure paths work">
    Go live
  </DocsNextStep>
</DocsNextSteps>
