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

# Card payments and return URLs with Laces

> Take card payments with the Laces API: send the buyer to the Laces card page and bring them back with on_success_url, on_failure_url and status placeholders.

Card details never touch your site. You create a payment, the pay call returns
a Laces page, the buyer pays there and comes back to you.

> [!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: Check card is available

Get a token, then quote:

```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/quote" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 50000, "currency": "UGX" }'
```

```json Response 200 theme={null}
{
  "code": 200,
  "message": "Payment quoted successfully",
  "data": {
    "currency": "UGX",
    "price_minor": 50000,
    "laces_fee_minor": 2500,
    "total_minor": 52500,
    "card": { "laces_fee_minor": 4400, "total_minor": 54400 },
    "airtel": { "laces_fee_minor": 3100, "total_minor": 53100 },
    "payment_methods": ["momo", "card", "airtel"]
  }
}
```

Offer card only when `payment_methods` lists `card`. Show
`data.card.total_minor`. Card follows the country: today Uganda, Kenya, Ghana,
Rwanda and US, GB and EU organizations, not Zambia. Trust the quote, not this
list. Otherwise create answers `400 rail_unavailable`.

## Step 2: Create with `payment_method: "card"`

```bash theme={null}
curl -s -X POST "$LACES_BASE/payments" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 9a7e4c21-5d3b-4f10-8c6e-2b9f1a0d7e55" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 50000,
  "currency": "UGX",
  "payment_method": "card",
  "partner_reference": "SHOP-ORDER-8813",
  "description": "Club jersey, size M",
  "product": "jersey",
  "customer": { "name": "Amina Nakato", "email": "amina@example.com", "phone": "+256763494235" },
  "metadata": { "cart_id": "c-8813", "size": "M" },
  "source_url": "https://shop.example.com/jerseys/home",
  "on_success_url": "https://shop.example.com/thanks",
  "on_failure_url": "https://shop.example.com/cart"
}'
```

```json Response 201 theme={null}
{
  "code": 201,
  "message": "Payment created successfully",
  "data": {
    "order": {
      "id": "Qd7rW2yB",
      "order_code": "LC-6H2J9P",
      "order_type": "partner_payment",
      "status": "cart",
      "currency": "UGX",
      "subtotal": 50000,
      "discount_total": 0,
      "donation_total": 0,
      "laces_fee": 4400,
      "total": 54400,
      "failure_kind": null,
      "partner_reference": "SHOP-ORDER-8813",
      "description": "Club jersey, size M",
      "product": "jersey",
      "metadata": { "cart_id": "c-8813", "size": "M" },
      "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-8813"
      },
      "hold_expires_at": "2026-11-25T08:29:03.000Z",
      "prompt_expires_at": null,
      "created_at": "2026-11-25T08:14:03.000Z"
    },
    "checkout_lines": [
      { "label": "Subtotal", "amount": 50000 },
      { "label": "Laces Service Fee", "amount": 4400 },
      { "label": "Total", "amount": 54400 }
    ],
    "is_free": false,
    "is_test_mode": false,
    "fee_rate": { "flat_fee": 1500, "percent_fee": 5.8, "currency": "UGX", "payment_method": "card" }
  }
}
```

## Step 3: Pay, with no number

```bash theme={null}
curl -s -X POST "$LACES_BASE/orders/Qd7rW2yB/pay" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: 4c2d8e1f-7a6b-4b39-a0d5-6e8f2c1b9a33" \
  -H "Content-Type: application/json" \
  -d '{}'
```

```json Response 200 theme={null}
{
  "code": 200,
  "message": "Continue on the hosted payment page",
  "data": {
    "order_id": "Qd7rW2yB",
    "order_code": "LC-6H2J9P",
    "status": "cart",
    "total": 54400,
    "currency": "UGX",
    "next_action": { "kind": "redirect", "redirect_url": "https://laces.run/pay?order=Qd7rW2yB" },
    "skipped_provider": false,
    "prompt_expires_at": null
  }
}
```

Nothing is charged here. The `Idempotency-Key` is required but not used up, so
calling again is safe. Note that the answer has no `payment_status` and no
`failure_kind`.

## Step 4: Redirect the buyer

Send their browser to `next_action.redirect_url` (`303` redirect or a link).
Use the URL as given; don't build it. The page shows your organization's name,
the description, the amount, the fee and the total. Where the card network
can't take your currency (UGX, for example), it shows the amount in USD before
they pay. Your order stays in its own currency. The page can carry your color
and logo: set them on the key ([Branding](https://docs.laces.run/guides/branding.md)).

## Step 5: The buyer comes back

| Field | When it is used |
| - | - |
| `on_success_url` | The payment is paid |
| `on_failure_url` | The buyer chooses to leave an unpaid, failed or ended payment, or it failed and can't be tried again on the page. After a decline the page lets them try again first. It does not send them back while the latest attempt is open. |

* A payment's own URL wins. Without one, the key's saved
  `default_success_url` or `default_failure_url` is used. With neither, the
  buyer sees a short Laces result page and stays there.
* `https` only (a registered `http://localhost:<port>` also works for URLs you
  send in a request, not for saved defaults). The origin must be in the key's
  **Return URL domains**. At most 2048 characters **with the order id and
  status added**. Otherwise `400 invalid_return_url`.
* They are checked again when used. If you remove a domain from the key, or
  revoke the key, the buyer is not sent there.
* `laces_status` can be `paid`, `cart` (they left without paying), `failed`,
  `expired` or `cancelled`. **None of them is final**: `failed` and `expired`
  can still become `paid`. Trust the webhook or an order read.

**Laces adds two values to the URL:**

| Value | Placeholder | Otherwise added as |
| - | - | - |
| The order id | `{LACES_ORDER_ID}` | `laces_order_id=` in the query |
| The order's status at that moment | `{LACES_STATUS}` | `laces_status=` in the query |

| You send | The buyer arrives at |
| - | - |
| `https://shop.example.com/thanks` | `https://shop.example.com/thanks?laces_order_id=Qd7rW2yB&laces_status=paid` |
| `https://shop.example.com/thanks?ref=a%20b` | `https://shop.example.com/thanks?ref=a+b&laces_order_id=Qd7rW2yB&laces_status=paid` |
| `https://shop.example.com/pay/{LACES_ORDER_ID}/{LACES_STATUS}` | `https://shop.example.com/pay/Qd7rW2yB/paid` |
| `https://shop.example.com/#/thanks?order={LACES_ORDER_ID}&state={LACES_STATUS}` | `https://shop.example.com/#/thanks?order=Qd7rW2yB&state=paid` |
| `https://shop.example.com/#/thanks` | `https://shop.example.com/?laces_order_id=Qd7rW2yB&laces_status=paid#/thanks` |

* **Using a `#` fragment (single-page apps)? Use `{LACES_STATUS}` and
  `{LACES_ORDER_ID}` inside it.** Otherwise the values go in the query, before
  the `#`. A fragment that already gives `laces_status` or `laces_order_id` a
  different value is dropped whole.
* **The query string is re-written** when values are added: `%20` can become
  `+`, and any `laces_order_id` or `laces_status` you put there is replaced.
  Read parameters by name; don't sign or compare the raw query string.
* Your own `order_id` or `status` parameters are left alone.

> [!WARNING]
>
> **A return URL is never proof of payment.** Anyone can type it. On your
> server, read the order or wait for the `order.paid` webhook, then fulfil.
> Show "We're confirming your payment" until then.

```js thanks.js theme={null}
import { app, fulfilIfPaid } from "./webhook.js"; // on the Webhooks page
import { db } from "./db.js"; // your own store

// GET /thanks?laces_order_id=...&laces_status=...
app.get("/thanks", async (req, res) => {
  const id = String(req.query.laces_order_id ?? "");
  const purchase = await db.findByLacesOrderId(id);
  if (!purchase) return res.status(404).send("Not found");
  try {
    await fulfilIfPaid(purchase, id); // safe if the webhook ran first
  } catch (err) {
    console.error(err); // can't read it now: the webhook or your job will
  }
  const { fulfilled, released } = await db.stateOf(purchase.id);
  res.render(fulfilled ? "thanks" : released ? "ended" : "confirming", { purchase });
});
```

"ended" says the reservation ended, and that you will contact the buyer if a
payment arrived: a late one is in review. A purchase undone after it was
fulfilled keeps `fulfilled` and still shows "thanks"; a second order for it shows
"thanks" too, and your handler has sent the duplicate to review.

## If the buyer does not come back

They may have closed the tab. A paid payment still sends `order.paid`. An
abandoned one sends **nothing**: an untouched `cart` becomes `expired` 15 to 20
minutes after creation.

## If the buyer wants to try again

| Order | Do this |
| - | - |
| `cart` or `failed`, created less than 15 minutes ago | Call pay again and send them to the same page |
| `payment_initiated`, `prompt_sent` | Wait: the card may be going through |
| Older, or `expired` | Create a new payment. Pay still answers with the page (a card pay call never says `hold_expired`), but the page may refuse it. |
| `paid` | Stop. Pay still answers with the page's URL for a paid order, so read the order first. |

Wants mobile money instead? `retryPayment` with the new method
([guide](https://docs.laces.run/guides/collect-payments.md#the-whole-thing-in-node)) creates a new payment. **No route cancels a card
order**, and a card page left open can still be paid, so replace one only when
the buyer has come back to you, keep the old order id, and [ask for one to be
refunded](https://docs.laces.run/concepts/fees.md#refunds) if both are paid.

## If the total changes

On the Laces page a buyer may be able to change how they pay, which changes
the fee and `total`. Compare `requested_amount` and `requested_currency` with
your price, never `total`.

A changed method can also start a **mobile money prompt** for this order, so a
"card" order can be `prompt_sent`. Treat it like any live payment: wait.

Codes: [Errors](https://docs.laces.run/payments/errors.md).


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