# How do I use charges?
Source: https://docs.lomi.africa/build/accept/direct-charges

Server-initiated charges for an app that must lock one rail. Hosted checkout is the default.

***

title: 'How do I use charges?'
description: 'Server-initiated charges for an app that must lock one rail. Hosted checkout is the default.'
-----------------------------------------------------------------------------------------------------------

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

Direct charges are for an app that must lock one rail. Hosted checkout is the default: create a [checkout session](/build/accept/checkout), the customer picks the method, and a new rail appears without a code change. `POST /charge/*` collects payment from your server and you build the customer-facing flow yourself.

<Callout type="warn">
  Switch charges (`POST /charge/switch`) are not available. They return `503 service_unavailable`. Use [hosted checkout](/build/accept/checkout) or [lomi. Elements](/build/accept/payment-elements) for cards.
</Callout>

<Callout type="warn">
  Prefer [hosted checkout](/build/accept/checkout) or [payment links](/build/accept/payment-links) unless you need a custom mobile-money flow. Direct charges require you to handle pending states and webhooks.
</Callout>

## When to use direct charges

Use direct charges when you want to charge quickly and will not reuse the same payment method object for repeat charges, similar to a one-shot orchestrated payment.

| Rail                      | Endpoint              | Customer step                                                                            |
| ------------------------- | --------------------- | ---------------------------------------------------------------------------------------- |
| Wave                      | `POST /charge/wave`   | Open `wave_launch_url` or `checkout_url` from the response                               |
| MTN                       | `POST /charge/mtn`    | Approve on their phone; live status starts `PENDING`                                     |
| Card                      | `POST /charge/card`   | Mount [lomi. Elements](/build/accept/payment-elements) with the returned `client_secret` |
| Switch (server-side card) | `POST /charge/switch` | **Not available**: use [hosted checkout](/build/accept/checkout)                         |

## Reference implementation

The monorepo includes a runnable example:

* Path: `apps/plugins/references/direct-charge-integration-reference`
* Routes: Wave, MTN, card, and webhook verification
* cURL scripts: `curl/create-wave-charge.sh`, `curl/create-mtn-charge.sh`

```bash
cd apps/plugins/references/direct-charge-integration-reference
pnpm install && cp .env.example .env
pnpm run dev
```

## Card flow (summary)

1. `POST /charge/card` with amount, currency, and `customer_id` or (`customer_email` + `customer_name`).
2. Mount [lomi. Elements](/build/accept/payment-elements) with `lomi_pk_test_…` or `lomi_pk_live_…` and the returned `client_secret`.
3. Listen for `PAYMENT_SUCCEEDED` webhooks for fulfillment.

Card amounts start at 1 000 F CFA (0.50 EUR/USD). Card numbers never hit your server or the lomi. API.

## Mobile money flow (summary)

1. `POST /charge/wave` or `POST /charge/mtn` with amount, currency, and customer phone in E.164 format.
2. Redirect or instruct the customer per the response.
3. Before you provide value, confirm the transaction's final **status** and **amount** via webhooks or `GET /transactions/{id}`.

See [Mobile money](/build/mobile-money) for the full guide.

### Wave request fields

`POST /charge/wave`

| Field                  | Type     | Required | Description                                        |
| ---------------------- | -------- | -------- | -------------------------------------------------- |
| `amount`               | `number` | Yes      | Amount in XOF, from 100 up to 5,000,000 inclusive. |
| `currency`             | `string` | Yes      | Must be `XOF`.                                     |
| `customer`             | `object` | Yes      | Customer details.                                  |
| `customer.name`        | `string` | Yes      | Full name.                                         |
| `customer.email`       | `string` | No       | Email.                                             |
| `customer.phoneNumber` | `string` | No       | E.164 phone (for example `+2250102030405`).        |
| `description`          | `string` | No       | Charge description.                                |
| `successUrl`           | `string` | No       | Redirect after success.                            |
| `errorUrl`             | `string` | No       | Redirect after failure.                            |
| `environment`          | `string` | No       | `live` or `test` (defaults to `live`).             |

A `201` response includes `transactionId`, `checkoutUrl`, and Wave session details. `POST /charge/mtn` follows the same pattern; see [Create MTN charge](/api/charge/ChargesController_createMtnCharge).

Card endpoints (`POST /charge/card`, `GET /charge/card/{id}`, `POST /charge/card/{id}/increment`, `POST /charge/card/{id}/capture`, `POST /charge/card/{id}/cancel`) are in the REST reference. To block a deposit without taking it, set `hold` to `true` and follow [Card holds](/build/accept/card-holds). Switch (`POST /charge/switch`) still returns `503 service_unavailable`.

## Sandbox scenarios (test key only)

With a **test** API key, direct Wave and MTN charges auto-complete by default. To test async or failure paths in CI, send `X-Scenario-Key`:

| Value     | Result                                    |
| --------- | ----------------------------------------- |
| `pending` | Charge stays `PENDING` (no auto-complete) |
| `failed`  | `400` error                               |

```bash
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"}'
```

Hosted checkout and card direct charges do **not** support this header yet. See [Simulate errors](/build/reliability/simulate-errors) and [Sandbox payments](/start/sandbox-payments#testing-mobile-money).

## lomi. Network

Operators can create direct charges on behalf of connected member accounts:

```http
POST /charge/wave HTTP/1.1
X-API-KEY: lomi_sk_live_operator_...
Lomi-Account: acct_1234567890
```

See [lomi. Network](/build/platform/network).

## Troubleshooting

Use `GET /providers` to confirm which rails are connected for the organization before calling direct charge endpoints.

| Symptom                                                        | Likely cause                                                 | Fix                                                                                                                                                                                                                     |
| -------------------------------------------------------------- | ------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Card charge returns `503 service_unavailable`                  | Card direct charges are not configured on the API deployment | **Ops:** ensure platform card-payment credentials are set on the API service for the target environment. **Merchants do not configure card-processor account keys**: card direct charges run on lomi.'s infrastructure. |
| Wave charge returns `400` about missing Aggregated Merchant ID | Wave is not fully connected in the dashboard                 | Connect Wave in the dashboard and save the **Aggregated Merchant ID** for the organization.                                                                                                                             |
| Wave charge returns `400` with a Wave edge error               | Invalid payload or Wave-side rejection                       | Send `currency: "XOF"`, nested `customer.phoneNumber` in E.164, and optional `successUrl` / `errorUrl` (camelCase). See [Wave](/build/payment-methods/wave).                                                            |
| Card charge returns `400` about customer fields                | Missing reconciliation fields                                | Include `customer_id`, or both `customer_email` and `customer_name`.                                                                                                                                                    |
| Hosted checkout works but direct charge fails                  | Different prerequisites per rail                             | Hosted checkout uses lomi.'s checkout app; direct charges hit `/charge/*` and require correct payload shape plus provider connection.                                                                                   |

<Callout type="info">
  Merchants only need `lomi_sk_...` (server) and `lomi_pk_...` (Payment Elements). They never configure platform card-payment secrets themselves.
</Callout>

## Related

* [Create Wave charge](/api/charge/ChargesController_createWaveCharge)
* [Create MTN charge](/api/charge/ChargesController_createMtnCharge)
* [Create card charge](/api/charge/ChargesController_createCardCharge)
* [Handling webhooks](/build/reliability/handling-webhooks)
