> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laces.run/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Laces is event registration software for every kind of event, not only races. Use the event's own wording.
> There is one environment, production: payments made through the API are real. Money is integer minor units; read the event's currency.
> Collecting payments with no Laces event uses POST /payments, then POST /orders/{orderId}/pay: start at /guides/collect-payments. Never call pay to test: there is no sandbox.
> Never put a client secret in browser code or an LLM chat. Branch on error_code, not on message.
> Overview of Laces: https://laces.run/llms.txt

# Mobile money payments on your site with Laces

> Take MTN, Airtel and other mobile money payments on your own site with the Laces API: send the prompt, wait, handle failures and retry without charging twice.

The buyer never leaves your site. You create a payment, call pay with their
number, and they approve a prompt on their phone.

> [!NOTE]
>
> **Every request on this page** goes to `https://connect.laces.run/v1`, from
> your **server**, with `Authorization: Bearer <token>`. Laces must first turn
> on payments for your organization, and your API key needs `payments:write`,
> `orders:write` and `orders:read`. Never send an
> organization id: Laces takes the organization from the token. The client
> secret stays on your server, never in a browser or an LLM chat. **There is
> no sandbox: a pay request moves real money.**

## Step 1: Pick the method before you create

`payment_method` sets the fee and cannot be changed afterwards.

| Where | `momo` | `airtel` |
| - | - | - |
| Uganda | MTN Mobile Money numbers | Airtel Money numbers |
| Kenya, Ghana, Rwanda, Zambia | Every network | The same price as `momo` |
| US, GB and EU organizations | Not available (`422 no_rate_for_method`), unless you send a `payer_country` | Not available |

In Uganda, ask which network the buyer uses, or infer it from the number,
**before** you create the payment.

## Step 2: Create

Get a token first:

```bash theme={null}
export LACES_BASE="https://connect.laces.run/v1"

TOKEN=$(curl -s -X POST "$LACES_BASE/oauth/token" \
  -u "$LACES_CLIENT_ID:$LACES_CLIENT_SECRET" \
  -d "grant_type=client_credentials" \
  | python3 -c 'import json,sys; print(json.load(sys.stdin)["access_token"])')
```

```bash theme={null}
curl -s -X POST "$LACES_BASE/payments" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 6f1c3c9e-2f4b-4c64-9a2f-0d1c5a8b7e11" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 50000,
  "currency": "UGX",
  "payment_method": "momo",
  "partner_reference": "SHOP-ORDER-8812",
  "description": "Club jersey, size L",
  "product": "jersey",
  "customer": { "name": "Amina Nakato", "email": "amina@example.com", "phone": "+256763494235" },
  "metadata": { "cart_id": "c-8812", "size": "L" },
  "source_url": "https://shop.example.com/jerseys/home",
  "on_success_url": "https://shop.example.com/thanks",
  "on_failure_url": "https://shop.example.com/cart"
}'
```

The `201` answer carries `data.order` with `id`, `total`, `currency`,
`status: "cart"` and `hold_expires_at`. Save `id` with your purchase.
**Next:** pay.

## Step 3: Pay

Send a **new** `Idempotency-Key` (not the create key) and the number:

```bash theme={null}
curl -s -X POST "$LACES_BASE/orders/Pm4xT9cL/pay" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 0b1b7d2e-8c3a-4a0e-9f55-3c1d6f2a9b40" \
  -H "Content-Type: application/json" \
  -d '{ "msisdn": "0763494235" }'
```

`0763494235` is the example number in these docs; use the payer's own. In
Uganda a local number (`07…`) is accepted. Everywhere else, send the country
code (`+254…`, `+233…`, `+250…`, `+260…`). The number must be from the
payment's country (`payer_country`, else your organization's), or the answer is
`400 invalid_msisdn`.

```json Response 200: the prompt was sent theme={null}
{
  "code": 200,
  "message": "Payment initiated successfully",
  "data": {
    "order_id": "Pm4xT9cL",
    "order_code": "LC-3N8V5K",
    "status": "prompt_sent",
    "total": 52500,
    "currency": "UGX",
    "payment_status": "prompt_sent",
    "next_action": { "kind": "await_confirmation", "message": "Approve the payment prompt on your phone" },
    "skipped_provider": false,
    "prompt_expires_at": "2026-11-25T08:18:00.000Z",
    "failure_kind": null,
    "failure_message": null,
    "failure_required_balance": null
  }
}
```

```json Response 200: nothing was sent, safe to try again theme={null}
{
  "code": 200,
  "message": "Payment initiated successfully",
  "data": {
    "order_id": "Pm4xT9cL",
    "order_code": "LC-3N8V5K",
    "status": "failed",
    "total": 52500,
    "currency": "UGX",
    "payment_status": "failed",
    "next_action": { "kind": "none" },
    "skipped_provider": false,
    "prompt_expires_at": null,
    "retry_safe": true,
    "failure_kind": "provider_not_reached",
    "failure_message": null,
    "failure_required_balance": null
  }
}
```

A `200` does **not** mean paid. It means the request was handled: look at
`payment_status`.

## Step 4: Wait

Tell the buyer "Check your phone and enter your PIN", and count down to
`prompt_expires_at`. When it passes the payment has **not** failed: keep
waiting. Learn the result from the [`order.paid` or `order.failed`
webhook](https://docs.laces.run/payments/webhooks). To poll as well (scope `orders:read`):

```js laces.js theme={null}
// Node 18+. Server only: it uses the client secret.
const BASE = process.env.LACES_BASE ?? "https://connect.laces.run/v1";
const TIMEOUT_MS = 60_000; // a pay call can take a while

let cached = { token: null, exp: 0 };
async function getToken(signal) {
  if (cached.token && Date.now() < cached.exp - 60_000) return cached.token;
  const basic = Buffer.from(
    `${process.env.LACES_CLIENT_ID}:${process.env.LACES_CLIENT_SECRET}`,
  ).toString("base64");
  const res = await fetch(`${BASE}/oauth/token`, {
    method: "POST",
    headers: {
      Authorization: `Basic ${basic}`,
      "Content-Type": "application/x-www-form-urlencoded",
    },
    body: "grant_type=client_credentials",
    signal,
  });
  const body = await res.json();
  if (!res.ok) throw new Error(`token: ${body.error}`);
  cached = { token: body.access_token, exp: Date.now() + body.expires_in * 1000 };
  return cached.token;
}

export async function laces(method, path, { body, idempotencyKey, timeoutMs = TIMEOUT_MS } = {}) {
  const signal = AbortSignal.timeout(timeoutMs); // the whole call, token included
  for (let refreshed = false; ; refreshed = true) {
    const res = await fetch(`${BASE}${path}`, {
      method,
      headers: {
        Authorization: `Bearer ${await getToken(signal)}`,
        ...(body && { "Content-Type": "application/json" }),
        ...(idempotencyKey && { "Idempotency-Key": idempotencyKey }),
      },
      ...(body && { body: JSON.stringify(body) }),
      signal,
    });
    const json = await res.json().catch(() => ({}));
    if (res.ok) return json.data;
    if (json.error_code === "invalid_token" && !refreshed) {
      cached = { token: null, exp: 0 }; // once: the token was refused before any work
      continue;
    }
    const err = new Error(json.error_code ?? `http_${res.status}`);
    err.status = res.status;
    err.code = json.error_code ?? null; // stable: branch on this
    err.details = json.details ?? null;
    err.retryAfter = Number(res.headers.get("Retry-After")) || null;
    err.requestId = res.headers.get("X-Request-Id"); // quote this to support
    throw err;
  }
}
```

```js wait.js theme={null}
import { laces } from "./laces.js";

// Poll about every 4 seconds, for about 4 minutes.
export async function waitForPayment(orderId, timeoutMs = 240_000) {
  const until = Date.now() + timeoutMs;
  while (Date.now() < until) {
    const order = await laces("GET", `/orders/${orderId}`);
    if (!["cart", "payment_initiated", "prompt_sent"].includes(order.status)) return order;
    await new Promise((r) => setTimeout(r, 4000));
  }
  return null; // still not known: keep waiting for the webhook
}
```

```json GET /orders/Pm4xT9cL while the prompt is out theme={null}
{
  "code": 200,
  "message": "Order retrieved successfully",
  "data": {
    "id": "Pm4xT9cL",
    "order_code": "LC-3N8V5K",
    "order_type": "partner_payment",
    "status": "prompt_sent",
    "currency": "UGX",
    "subtotal": 50000,
    "discount_total": 0,
    "donation_total": 0,
    "laces_fee": 2500,
    "total": 52500,
    "failure_kind": null,
    "partner_reference": "SHOP-ORDER-8812",
    "description": "Club jersey, size L",
    "product": "jersey",
    "metadata": { "cart_id": "c-8812", "size": "L" },
    "source_url": "https://shop.example.com/jerseys/home",
    "source_site": "shop.example.com",
    "requested_amount": 50000,
    "requested_currency": "UGX",
    "buyer": { "name": "Amina Nakato", "email": "amina@example.com", "phone": "+256763494235" },
    "attribution": {
      "channel": "partner_api",
      "api_client_id": "LCSCLI-EXAMPLECLNT2345EXAMP",
      "checkout_session_id": null,
      "partner_reference": "SHOP-ORDER-8812"
    },
    "hold_expires_at": "2026-11-25T08:29:03.000Z",
    "prompt_expires_at": "2026-11-25T08:18:00.000Z",
    "created_at": "2026-11-25T08:14:03.000Z"
  }
}
```

## Step 5: When it fails

```json GET /orders/Pm4xT9cL after a failure theme={null}
{
  "code": 200,
  "message": "Order retrieved successfully",
  "data": {
    "id": "Pm4xT9cL",
    "order_code": "LC-3N8V5K",
    "order_type": "partner_payment",
    "status": "failed",
    "currency": "UGX",
    "subtotal": 50000,
    "discount_total": 0,
    "donation_total": 0,
    "laces_fee": 2500,
    "total": 52500,
    "failure_kind": "timed_out",
    "partner_reference": "SHOP-ORDER-8812",
    "description": "Club jersey, size L",
    "product": "jersey",
    "metadata": { "cart_id": "c-8812", "size": "L" },
    "source_url": "https://shop.example.com/jerseys/home",
    "source_site": "shop.example.com",
    "requested_amount": 50000,
    "requested_currency": "UGX",
    "buyer": { "name": "Amina Nakato", "email": "amina@example.com", "phone": "+256763494235" },
    "attribution": {
      "channel": "partner_api",
      "api_client_id": "LCSCLI-EXAMPLECLNT2345EXAMP",
      "checkout_session_id": null,
      "partner_reference": "SHOP-ORDER-8812"
    },
    "hold_expires_at": null,
    "prompt_expires_at": null,
    "created_at": "2026-11-25T08:14:03.000Z"
  }
}
```

| `failure_kind` | Tell the buyer |
| - | - |
| `provider_not_reached` | "You have not been charged. Please try again." |
| `timed_out` | "The payment wasn't approved in time. Please try again." |
| `declined` | "The payment was declined. Check your balance or try another number." |
| `other`, or a value you don't know | "The payment didn't go through. Please try again." |

### One rule while a payment is live

**While the order is `payment_initiated` or `prompt_sent`, don't call pay**, not
even with another number, and don't create another payment. It ends as `paid`,
`failed` or `expired`, usually in minutes and within about 2 hours.

Laces blocks only part of this: any new prompt on the order for 2 minutes
(`409 prompt_in_progress`), and the **same number** on it for 10 minutes
(`409 charge_pending_same_number`). After that, or on another order, a second
prompt can go out while the first can still be approved. If a buyer is debited
twice on **one** order you get no second webhook: send
[support@laces.run](mailto:support@laces.run) the order id.

### Try again

**Lock per purchase** while you read, pay or create, so a double click or two
servers can't start two payments. Only when the buyer asks. **Never in the background**, whatever the answer was:
once the wait is over, the same request, even with the same key, sends a new
prompt. Read **every order of the purchase** first; any other status
means stop and let a person look:

| Order | Do this |
| - | - |
| `paid` | Stop |
| `payment_initiated`, `prompt_sent` | Wait |
| `cart` or `failed`, created less than 15 minutes ago | Pay again on the **same order**, new pay key |
| Older, or `expired`, or another method | **New payment**: new create key, new pay key, same `partner_reference`. Show the new total. |

Inside 15 minutes, these answers also mean a new payment. The call charged
nothing:

| Answer | Why |
| - | - |
| `409 hold_expired` | The payment window is over |
| `409 reprice_required` | Uganda: the number is on the other network (create with the other method), or this retry would go through a route with a different price (create again with the same method) |
| `409 rate_lock_expired` | Cross-border: the exchange rate ran out |

There is no route that changes or cancels a payment. **Keep the old order id**:
a late approval can still pay it, and two paid orders for one
`partner_reference` means one refund. Code: `retryPayment` in the
[guide](https://docs.laces.run/guides/collect-payments.md#the-whole-thing-in-node).

`429 payer_prompt_limit`: the number has had **3 prompts in an hour, or 10 in 24
hours**, across all Laces orders. Nothing was sent. If no prompt is live, the
buyer can use another number, or wait `Retry-After` seconds.

`retry_safe` is only on the pay answer, not on reads or webhooks: `false` means
read the order before you offer a retry. The read is what decides.

**No answer from pay?** The call may still be running, and the order can still
read `cart`, or the `failed` or `expired` of an earlier try. Wait **3 minutes**
before you believe it; until then only the **same** key is safe (it answers
`idempotency_in_progress` or the first result).

## Idempotency, in one line

No answer (timeout, network error, `5xx`): [read the order
first](https://docs.laces.run/payments/errors.md#a-500-or-no-answer-from-pay). Anything that changed: **new**
key. The pay key is tied to the order and the number.

Full list of codes: [Errors](https://docs.laces.run/payments/errors.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.