> ## 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

# Payment errors: every error_code and what to do

> Every error_code from the Laces payments routes, for creating, quoting, paying and reading: the HTTP status, what it means and what your code should do.

Branch on `error_code`. `error` is for people and may be reworded; `message`
is kept for older clients. Log the `X-Request-Id` response header with every
error and quote it to [support@laces.run](mailto:support@laces.run).

> [!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.**

```json 403 theme={null}
{
  "code": 403,
  "message": "shop_payments_not_enabled",
  "error": "Payments are not enabled for this organization",
  "error_code": "shop_payments_not_enabled"
}
```

```json 429 (pay), with the header Retry-After: 1800 theme={null}
{
  "code": 429,
  "message": "payer_prompt_limit",
  "error": "Too many payment requests have been sent to this number. Please wait before trying again, or use a different number.",
  "details": { "retry_after_seconds": 1800 },
  "error_code": "payer_prompt_limit"
}
```

## Create (`POST /payments`) and quote (`POST /payments/quote`)

Quote checks only `amount`, `currency` and `payer_country`, so it gives only
the codes marked **Q**. Neither answer depends on a buyer's number.

| HTTP | `error_code` | Meaning | Do this |
| - | - | - | - |
| 400 | `idempotency_key_required` | No `Idempotency-Key` header | Send one |
| 400 | `invalid_request` **Q** | A field is missing, too long, the wrong type, not one line, or has hidden characters; the email or phone is not valid; or `description`, `product` or `customer.name` contains a web address (`://` or `www.`). `error` names the field. | Fix it. Put the link in `source_url`. |
| 400 | `invalid_amount` **Q** | Not a whole number above 0, or too large or too small to charge | Send minor units as an integer |
| 400 | `amount_too_large` **Q** | Over the most Laces allows your organization to ask for | Lower it, or ask Laces |
| 400 | `currency_mismatch` **Q** | `currency` isn't your organization's | Leave it out, or fix it |
| 400 | `unsupported_country` **Q** | `payer_country` isn't accepted. `error` lists the accepted codes. | Leave it out, or fix it |
| 400 | `invalid_payment_method` | Not a method Laces knows | Use one from the quote |
| 400 | `rail_unavailable` | Card isn't offered for that country, or you sent `bank_transfer`, which no country has yet | Use one from the quote |
| 400 | `invalid_metadata` | Not a flat map of strings, over 20 keys, a bad key, a value over 500 characters, or over 4096 bytes | Fix it |
| 400 | `invalid_source_url` | `source_url` isn't `https`, its origin isn't in the key's Return URL domains, it is over 2048 characters, or it is a link shortener, a shared host (such as `sites.google.com`, `linktr.ee`, `facebook.com`, `github.com`) or a Laces address | Use a page on your own site |
| 400 | `invalid_return_url` | `on_success_url` or `on_failure_url` isn't `https` on a Return URL domain, or is over 2048 characters with the order id and status added | Fix it, or add the domain |
| 400 | `invalid_json` **Q** | The body isn't valid JSON | Fix it |
| 401 | `unauthorized`, `invalid_token` **Q** | No token, or it is wrong, expired or revoked | Get a new token once, then retry |
| 403 | `insufficient_scope` **Q** | The token lacks `payments:write` | Turn it on, then get a **new** token |
| 403 | `credential_not_permitted` **Q** | You sent a publishable key | Use a bearer token, from your server |
| 403 | `shop_payments_not_enabled` **Q** | Laces has not turned payments on for your organization, or has turned them off. Only these two routes: payments already created can still be paid, read and refunded. | Ask [support@laces.run](mailto:support@laces.run) |
| 413 | `payload_too_large` **Q** | The body is over 1 MB | Send less |
| 403 | `shop_payments_blocked` **Q** | Laces has stopped payments for your organization | Hide your pay button and contact Laces |
| 403 | `payments_disabled` **Q** | Your organization isn't cleared to take payments | Contact Laces |
| 404 | `org_not_found` **Q** | The organization no longer exists | Contact Laces |
| 409 | `idempotency_in_progress` | The same key is still being processed | Retry shortly with the **same** key |
| 409 | `sale_closed`, `shop_event_conflict` | Payments are unavailable for your organization | Contact Laces |
| 422 | `idempotency_key_reuse` | The key was used with a different body | Use a new key |
| 422 | `no_rate_for_method` | That method has no price there (mobile money for a US, GB or EU organization) | Use one from the quote |
| 429 | `rate_limited` **Q** | Over about 60 creates (shared with other writes), or 60 quotes, a minute | Wait `Retry-After` |
| 503 | `fx_unavailable` **Q** | No exchange rate right now | Retry shortly, same key |
| 500 | `server_error` **Q** | Unexpected | Retry with backoff, **same** key |

`partner_reference` here is `invalid_request` when missing or over 128
characters (on `POST /orders` it is `invalid_partner_reference`).

## Pay (`POST /orders/{orderId}/pay`)

Needs `orders:write` **as well as** `payments:write` on the key.

| HTTP | `error_code` | Meaning | Do this |
| - | - | - | - |
| 400 | `idempotency_key_required` | No `Idempotency-Key` header | Send one |
| 400 | `msisdn_required` | Mobile money needs the payer's number | Send `msisdn` |
| 400 | `invalid_msisdn` | Not a valid number for the payment's country, or the country code is missing outside Uganda | Ask again |
| 400 | `validation_failed`, `invalid_json` | The body is wrong | Fix it |
| 400 | `rail_unavailable` | That network isn't available here. Nothing was charged. | Another number or method |
| 401 | `unauthorized`, `invalid_token` | No token, or it is wrong, expired or revoked | New token once, then retry |
| 403 | `insufficient_scope` | The token lacks `orders:write` | Turn it on, get a new token |
| 403 | `credential_not_permitted` | You sent a publishable key | Bearer token, from your server |
| 403 | `shop_payments_blocked` | Laces has stopped new payments for your organization. Nothing was charged. | Stop, contact Laces |
| 404 | `not_found` | No such order in your organization | Check the id |
| 409 | `prompt_in_progress` | A prompt is already on the payer's phone | Wait for the result. Not a failure. |
| 409 | `charge_pending_same_number` | That number already has a live prompt for this order | Wait for the result. Don't try another number while it is live. |
| 409 | `order_not_payable` | Already paid, in progress, or closed | Read the order |
| 409 | `order_total_invalid` | The order has nothing to charge | Create a new payment |
| 409 | `hold_expired` | The payment window is over | **New payment, new key** |
| 409 | `rate_lock_expired` | The exchange rate ran out. Nothing was charged. | **New payment, new key** |
| 409 | `reprice_required` | That number is priced differently. Nothing was sent. | **New payment, new key** ([how](https://docs.laces.run/payments/mobile-money.md#try-again)) |
| 409 | `idempotency_in_progress` | The same key is still being processed | Read the order |
| 413 | `payload_too_large` | The body is over 1 MB | Send less |
| 422 | `payer_not_registered` | The number has no mobile money account. Nothing was charged. | Another number |
| 422 | `idempotency_key_reuse` | The key was used with another order or number | New key |
| 429 | `payer_prompt_limit` | 3 prompts in an hour or 10 in 24 hours on this number, across all Laces orders. Nothing was sent. | If no prompt is live: wait `Retry-After` (also `details.retry_after_seconds`), or another number |
| 429 | `rate_limited` | Too many requests | Wait `Retry-After` |
| 503 | `service_unavailable` | Temporarily unavailable. Nothing was sent. | Let the buyer try again shortly |
| 500 | `server_error` | Unexpected; a charge may exist | [Read the order first](#a-500-or-no-answer-from-pay) |

A **failed** payment is not an HTTP error: the pay call answers `200` with
`payment_status: "failed"`, or a webhook arrives later. See
[Mobile money](https://docs.laces.run/payments/mobile-money.md#step-5-when-it-fails).

## Read and list

| HTTP | `error_code` | Meaning |
| - | - | - |
| 400 | `validation_failed` | A bad `limit`, `status` or `order_type` (`partner_payment`, `ticket`, or `partner_package`, which is always empty) |
| 400 | `invalid_cursor` | The cursor isn't valid |
| 403 | `insufficient_scope` | The token lacks `orders:read` |
| 404 | `not_found` | No such order or event in your organization |

## A `500`, or no answer, from pay

A charge may exist. The call can still be running, and until it commits the
order reads as it did before: `cart`, **or an earlier `failed` or `expired`**.
Wait **3 minutes**, then **read the order**:

| Order | Do this |
| - | - |
| `payment_initiated`, `prompt_sent` | Wait for the result |
| `paid` | Act on it |
| `cart`, `failed`, `expired` | Nothing was sent, or it has ended. The buyer may try again, with a new key. |

## Which `Idempotency-Key`?

Keys don't expire. A key that finished always gives its first answer back, a
**snapshot**: a replayed create says `cart` and a replayed pay says
`prompt_sent` even after the order is paid.

| Last answer | Next request |
| - | - |
| Create: no answer, `5xx`, `409 idempotency_in_progress` | **Same** key |
| Pay: no answer or `5xx` | Read the order first (above) |
| `429 rate_limited` | **Same** key: it was refused before any work |
| Create refused for any other reason | **Same** key if the body is unchanged, **new** key if it changed |
| Pay: `prompt_in_progress`, `charge_pending_same_number`, `payer_prompt_limit`, `rail_unavailable`, `payer_not_registered`, `shop_payments_blocked`, `service_unavailable` | The key is free again. **It sends a new prompt** when it succeeds, so only when the buyer asks; new key for another number |
| Pay: `invalid_msisdn`, `order_not_payable`, `order_total_invalid`, `hold_expired`, `reprice_required`, `rate_lock_expired` | **New** key. (The old one answers `idempotency_in_progress` for up to 2 minutes.) |
| A failed payment the buyer retries, or a replacement payment | **New** keys |


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