# Crypto checkout (beta test)

> Beta test: take a payment priced in USD, ARS or CHF in crypto through a hosted page. Redirect the buyer to it, or embed it in an iframe.

Source: https://business-api-docs.youhodler.com/beta/crypto-checkout

# Crypto checkout

Checkout takes a payment in crypto for a basket priced in US dollars,
Argentine pesos or Swiss francs. You create a checkout for any amount on your server. The buyer opens a hosted page,
enters their name, email and tax ID, picks a coin and network, and sends the quoted amount to the deposit address
shown there. The deposit settles into the receiving account like any other
crypto deposit.

There are two ways to show the page:

1. **Redirect (hosted page).** Send the buyer to the checkout `url`. After
paying, or when they cancel, the page sends them back to your site. This is
the simplest integration, and the one to start with.
2. **Embed (iframe).** Put the same `url` in an `<iframe>` on your site. The
page stays in the frame and tells your site what happens through
`postMessage`.

Either way, your server confirms the payment with
`GET /v1/checkouts/{id}` before it fulfils the order.

You can also create and follow checkouts without code. On sandbox, the
[console](https://business-api-admin-sandbox.youhodler.com) has
**Crypto → Checkout**.

## Links

| What | Sandbox |
| --- | --- |
| Console | [business-api-admin-sandbox.youhodler.com](https://business-api-admin-sandbox.youhodler.com) |
| Merchant API | `https://b2b2x-sandbox.youhodler.com/checkout-api` |
| Platform API (tokens) | `https://b2b2x-sandbox.youhodler.com/api` |
| Hosted page | `https://b2b2x-sandbox.youhodler.com/checkout/pay/{id}` |
| Sepolia explorer (USDC, ETH payments) | [sepolia.etherscan.io](https://sepolia.etherscan.io) |

## Base URL

The Merchant API runs as its own service next to the platform API:

| Environment | Base URL |
| --- | --- |
| Sandbox | `https://b2b2x-sandbox.youhodler.com/checkout-api` |

Below, `$CHECKOUT_API` is the base URL for your environment.

## Authentication

Checkout uses the B2B2X access token you already have. It needs no separate
API key. Send the token as `Authorization: Bearer <access_token>`:

- **Service account.** Use a client-credentials token (see
[Authentication](/integrations/authentication)).
- **Console user.** The console sends the user's own token.

The service checks access to `account_ref` with your token:

- To read checkouts, the token needs `deposits.read` on that account.
- To create one, it also needs `funding_endpoints.provision`, because a
checkout provisions a deposit address on the account.

The account must also be connected to Checkout once. An enterprise
administrator presses **Connect checkout** in the console (Crypto → Checkout),
or calls the API with a token that holds `service_accounts.create` and
`role_assignments.create`:

```bash
curl -X POST "$CHECKOUT_API/v1/merchant/connect" \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"account_ref": "master-accounts/<id>"}'
```

Connecting creates a `checkout_module` role (read deposits, read and
provision deposit addresses) and a managed service account with it. That
account appears in your API keys as "Checkout module (managed)"; revoking it
disconnects Checkout. `GET /v1/merchant?account_ref=…` shows the state:
`not_connected`, `connected`, `rotation_due` (reconnect within 14 days),
`expired` or `disconnected`. On sandbox, an administrator's first checkout
connects the account automatically.

## Option 1: Redirect to the hosted page

The flow has four steps:

1. Your server creates a checkout.
2. You redirect the buyer to its `url`.
3. The buyer returns to your `success_url` or `cancel_url`.
4. Your server reads the checkout and fulfils the order only if it is `paid`.

### 1. Create the checkout on your server

Create the checkout on your server, never in the browser: the access token
must not reach the buyer.

```bash
curl -X POST "$CHECKOUT_API/v1/checkouts" \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Idempotency-Key: order-1042" \
  -H "Content-Type: application/json" \
  -d '{
    "account_ref": "master-accounts/<account_id>",
    "amount": {"value": "120.00", "currency": "USD"},
    "order_id": "ORDER-1042",
    "description": "2 items from Example Shop",
    "success_url": "https://shop.example.com/orders/1042/thanks",
    "cancel_url": "https://shop.example.com/cart",
    "expires_in_minutes": 60
  }'
```

| Field | Rules |
| --- | --- |
| `account_ref` | The account that receives the payment. |
| `amount.value` | A decimal string, greater than 0, with at most 15 digits before the point and 2 after. |
| `amount.currency` | `USD`, `ARS` or `CHF`. The buyer pays the equivalent in a coin at the market price. |
| `order_id` | Optional, up to 128 characters. |
| `description` | Optional, up to 256 characters. The buyer sees it. |
| `success_url` | Optional. An `https` URL of up to 2048 characters. The buyer returns here after paying. |
| `cancel_url` | Optional. An `https` URL of up to 2048 characters. The buyer returns here if they cancel. |
| `expires_in_minutes` | Optional, from 5 to 1440. The default is 60. |

The response is `201` with a Checkout object:

```json
{
  "id": "6f1c…",
  "object": "checkout",
  "status": "open",
  "amount": {"value": "120.00", "currency": "USD"},
  "success_url": "https://shop.example.com/orders/1042/thanks",
  "cancel_url": "https://shop.example.com/cart",
  "url": "https://b2b2x-sandbox.youhodler.com/checkout/pay/6f1c…",
  "expires_at": "…",
  "payment": null,
  "payer": null
}
```

Store `id` with your order. `success_url` and `cancel_url` are `null` when you
did not set them. `payer` is `null` until the buyer gives their details on the
page, see [Buyer details](#buyer-details).

It is safe to repeat the request. If you send the same `Idempotency-Key`, or
the same `order_id`, for the same `account_ref`, you get the existing checkout
back with `200` and the header `Idempotent-Replay: true`. Keys and order IDs
are scoped per `account_ref`. In the beta the body is **not compared**: a
repeat with a different amount still returns the first checkout, with its
original amount. Use a new `order_id` for a new order.

### 2. Redirect the buyer to `url`

Answer the buyer's "Pay" click with a redirect to `url`, e.g. `303 See Other`.

### 3. The buyer returns to your site

The page adds `checkout_id` to the URL it sends the buyer to. If your URL
already has a query, it is appended with `&`.

| What happens | Where the buyer goes |
| --- | --- |
| The payment is received | The page shows "Payment received" and after 5 seconds redirects to `success_url?checkout_id=<id>`. A **Return to** button redirects at once. |
| The buyer presses **Cancel and return** before a payment is detected, or after the checkout expired | `cancel_url?checkout_id=<id>` |

Without a `success_url` the buyer stays on the paid screen. Without a
`cancel_url` the page shows no cancel link.

### 4. Verify before you fulfil

A visit to your `success_url` is **not** proof of payment: anyone can open
that URL. On the success page, read the checkout on your server and fulfil
the order only when its `status` is `paid`:

```bash
curl "$CHECKOUT_API/v1/checkouts/<checkout_id>" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Also check that the checkout belongs to the order you stored. A visit to your
`cancel_url` does not mean the checkout is dead: a deposit can still arrive,
see [Statuses](#statuses).

### Example: Node.js

A minimal server (Node.js 18+) with a pay route and a success route:

```js
const CHECKOUT_API = 'https://b2b2x-sandbox.youhodler.com/checkout-api';

async function checkoutApi(path, init = {}) {
  const response = await fetch(`${CHECKOUT_API}${path}`, {
    ...init,
    headers: {
      // A client-credentials token, see Authentication.
      Authorization: `Bearer ${await getAccessToken()}`,
      'Content-Type': 'application/json',
      ...init.headers,
    },
  });
  const body = await response.json();
  if (!response.ok) throw new Error(body.error.code);
  return body;
}

// POST /pay?order=ORDER-1042 from your checkout button.
export async function pay(order, res) {
  const checkout = await checkoutApi('/v1/checkouts', {
    method: 'POST',
    headers: {'Idempotency-Key': order.id},
    body: JSON.stringify({
      account_ref: 'master-accounts/<account_id>',
      amount: {value: order.totalUsd, currency: 'USD'},
      order_id: order.id,
      success_url: `https://shop.example.com/orders/${order.id}/thanks`,
      cancel_url: 'https://shop.example.com/cart',
    }),
  });
  await saveCheckoutId(order.id, checkout.id);
  res.writeHead(303, {Location: checkout.url}).end();
}

// GET /orders/:id/thanks?checkout_id=… — the success_url.
export async function thanks(order, res) {
  const checkout = await checkoutApi(`/v1/checkouts/${order.checkoutId}`);
  if (checkout.status === 'paid') await fulfil(order);
  // Otherwise show "payment pending" and poll; see Follow the payment.
}
```

The success route reads the checkout id it stored, not the one in the URL.

## Option 2: Embed the page in an iframe

```html
<iframe
  id="yh-checkout"
  src="https://b2b2x-sandbox.youhodler.com/checkout/pay/6f1c…"
  title="Pay with crypto"
  width="100%"
  height="640"
  style="border:0"
  allow="clipboard-write"
></iframe>
```

Inside a frame the page never navigates, so `success_url` and `cancel_url`
are not used. It posts messages to the parent window instead. They carry no
buyer data:

| `type` | Fields | When |
| --- | --- | --- |
| `ready` | `type`, `checkout_id`, `status` | The page has loaded. |
| `status` | `type`, `checkout_id`, `status` | The status changed. |
| `paid` | `type`, `checkout_id`, `status` | The payment was received. |
| `expired` | `type`, `checkout_id`, `status` | The checkout expired. |
| `cancel` | `type`, `checkout_id`, `status` | The buyer pressed cancel. Your site decides what to show next. |
| `resize` | `type`, `checkout_id`, `height` | The page height changed, in pixels. |

Set the frame height from `resize`, so the page never scrolls inside the
frame, and check the origin of every message:

```js
const frame = document.getElementById('yh-checkout');
window.addEventListener('message', event => {
  if (event.origin !== 'https://b2b2x-sandbox.youhodler.com') return;
  if (typeof event.data !== 'object' || event.data === null) return;
  const {type, height} = event.data;
  if (type === 'resize') frame.style.height = height + 'px';
  if (type === 'paid') {
    // Show a confirmation, then confirm the order on your server.
  }
  if (type === 'cancel') {
    // Close the frame and take the buyer back to the cart.
  }
});
```

Messages are UI hints only. Fulfil an order only after your server has read
the checkout with `GET /v1/checkouts/{id}`.

## Follow the payment

```bash
curl "$CHECKOUT_API/v1/checkouts/<checkout_id>" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

This endpoint refreshes the status before it answers. With a
[webhook](#webhooks) set up, read it when an event arrives. Without one, poll
it until the status is final (see [Statuses](#statuses)); every 10 to 15
seconds is enough.

To list an account's checkouts, newest first:

```bash
curl "$CHECKOUT_API/v1/checkouts?account_ref=master-accounts/<account_id>&status=paid&limit=20" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

The response is `{"data": [...], "next_cursor": "..."}`. To get the next page,
pass `cursor=<next_cursor>`. The list does not refresh statuses itself; a
background job does, so a list status can lag by a few seconds. Read the
single checkout before you act on it.

Once the buyer picks a coin, `payment` is filled with these fields:

- `asset`
- `network`
- `address`
- `memo` (`null` when the network has none)
- `amount`: what the buyer must send, e.g. `{"value": "120.000000", "currency": "USDT"}`
- `quote_expires_at`
- `deposit_id` (`null` until a deposit is matched)
- `received`: what arrived, in the same shape, or `null`
- `fee`: the fee deducted from the deposit, in the same shape, or `null` (see [Fees](#fees))
- `net`: `received` minus `fee`, what the receiving account keeps, or `null`

## Webhooks

A webhook tells your server when a checkout changes status, so you do not have
to poll. Set one endpoint per receiving account in the console under
**Crypto → Checkout → Webhook**, or through the API.

### Set up the endpoint

```bash
curl -X PUT "$CHECKOUT_API/v1/merchant/webhook" \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"account_ref": "master-accounts/<id>", "url": "https://shop.example.com/webhooks/checkout"}'
```

The URL must start with `https://` and resolve to a public address. The first
call creates the endpoint and returns its signing `secret` (`whsec_…`). Store
it: it is shown only once. A later `PUT` with a new `url` keeps the secret.

| Method | Path | What it does |
| --- | --- | --- |
| `GET` | `/v1/merchant/webhook?account_ref=…` | The endpoint, without the secret. `404 webhook_not_configured` if none. |
| `PUT` | `/v1/merchant/webhook` | Create the endpoint or change its URL. |
| `POST` | `/v1/merchant/webhook/rotate-secret` | A new secret, shown once. The old one keeps signing for 24 hours. |
| `DELETE` | `/v1/merchant/webhook?account_ref=…` | Remove the endpoint. Delivery history stays. |
| `POST` | `/v1/merchant/webhook/test` | Send a `checkout.test` event. `404 webhook_not_configured` if no endpoint is set. |
| `GET` | `/v1/merchant/webhook-deliveries?account_ref=…` | Delivery log, newest first. Filters: `checkout_id`, `status`; paging: `limit`, `cursor`. |
| `POST` | `/v1/merchant/webhook-deliveries/{id}/redeliver` | Send an event again. |

### Events

| Event | Sent when |
| --- | --- |
| `checkout.processing` | A deposit matched the checkout and is being credited. Skipped when the deposit is already credited by the time it is matched. |
| `checkout.paid` | The deposit is credited. Fulfil the order after reading the checkout. |
| `checkout.expired` | The checkout expired without a payment. |
| `checkout.failed` | The matched deposit failed. |
| `checkout.test` | You asked for a test event. |

Every event is a `POST` with a JSON body:

```json
{
  "id": "3b0f9c2e-…",
  "object": "event",
  "type": "checkout.paid",
  "created_at": "2026-11-05T10:15:02Z",
  "data": {"checkout": { "id": "6f1c…", "status": "paid", "…": "…" }}
}
```

`data.checkout` is the checkout as `GET /v1/checkouts/{id}` returned it at the
moment of the change. `checkout.test` carries `"checkout": null`.

### Verify the signature

Each request carries two headers:

- `YH-Webhook-Id`: the event `id`. The same event can arrive more than once;
use the id to process it only once.
- `YH-Webhook-Signature`: `t=<unix seconds>,v1=<hex>`. `v1` is
HMAC-SHA256 of `<t>.<raw body>` with your secret. For 24 hours after a
rotation the header has a second `v1`, signed with the old secret.

Check the signature over the raw body, before parsing it, and refuse old
timestamps:

```js

const TOLERANCE_SECONDS = 300;

export function verifyCheckoutWebhook(rawBody, header, secret) {
  const parts = header.split(',').map(p => p.split('='));
  const t = parts.find(([k]) => k === 't')?.[1];
  const signatures = parts.filter(([k]) => k === 'v1').map(([, v]) => v);
  if (!t || signatures.length === 0) return false;
  if (Math.abs(Date.now() / 1000 - Number(t)) > TOLERANCE_SECONDS) return false;
  const expected = crypto
    .createHmac('sha256', secret)
    .update(`${t}.${rawBody}`)
    .digest('hex');
  return signatures.some(
    s =>
      s.length === expected.length &&
      crypto.timingSafeEqual(Buffer.from(s), Buffer.from(expected))
  );
}
```

### Delivery and retries

Answer with any `2xx` status within 10 seconds; the body is ignored. Any other
answer, a timeout or a redirect counts as a failure. A failed event is retried
after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours, 12 hours and
24 hours, then marked `failed`. Events are not guaranteed to arrive in order:
always read the checkout before you act.

The delivery log shows each event's status (`pending`, `delivered`, `failed`),
attempts and the last response code. An event raised while no endpoint is set
is logged as `failed` with `no_endpoint`. Redeliver any event from the log or
the console.

## Buyer details

Before the hosted page shows the coins, it asks the buyer for four fields:
name, surname, email and tax ID. All four are required on the page. It asks
the same in both ways of showing the page, the redirect and the iframe. The
details never decide whether a deposit pays the checkout.

Once the buyer sends them, the checkout carries a `payer` object:

```json
"payer": {
  "first_name": "Ana",
  "last_name": "Gómez",
  "email": "ana@example.com",
  "tax_id": "20-12345678-9",
  "provided_at": "2026-11-04T12:05:00Z"
}
```

| Field | Meaning |
| --- | --- |
| `first_name` | The buyer's name, 1 to 100 characters. |
| `last_name` | The buyer's surname, 1 to 100 characters. |
| `email` | The buyer's email, up to 254 characters. |
| `tax_id` | The buyer's tax ID, 1 to 32 characters. |
| `provided_at` | When the buyer gave the details. |

`payer` is `null` while the buyer has not given them. It appears on
`GET /v1/checkouts/{id}` and on every item of `GET /v1/checkouts`, so whoever
can read the checkout sees it: the master account, and the receiving account
when that is a sub-account or a client account. The console shows it in the
checkout details.

The details are **self-declared**. YouHodler does not verify them. Treat them
as what the buyer typed, not as a checked identity.

## Fees

YouHodler takes its fee from each payment. The fee is the crypto deposit fee
in your agreement with YouHodler, and it is deducted from the deposit when it
is credited. Nothing is invoiced separately.

Each checkout shows what was deducted:

```json
"payment": {
  "…": "…",
  "received": {"value": "120.000000", "currency": "USDT"},
  "fee": {"value": "0.120000", "currency": "USDT"},
  "net": {"value": "119.880000", "currency": "USDT"}
}
```

`fee` and `net` are `null` until the deposit is credited. The console shows
them in the checkout details. Your rate is set in your agreement; ask your
YouHodler contact to change it.

The page sends the details with the coin choice. Its own endpoint,
`POST /v1/public/checkouts/{id}/select`, takes an optional `payer` with the
same four fields: `first_name`, `last_name`, `email` and `tax_id`. The page's
public view of the checkout has `payer_provided`, a boolean that says whether
the buyer has given their details; the details themselves are only on your
authenticated API. Your server does not call these endpoints.

## Statuses

| Status | Meaning | Terminal |
| --- | --- | --- |
| `open` | The buyer has not picked a coin yet. | No |
| `awaiting_payment` | A coin is picked. The page shows the address and amount. The quote is valid for 30 minutes, and picking again re-quotes. | No |
| `processing` | A matching deposit has arrived and is held or not settled yet. | No |
| `paid` | The deposit settled into the receiving account. | Yes |
| `expired` | `expires_at` passed before any deposit arrived. | Usually; see below |
| `failed` | The deposit failed or was rejected. | Yes |

An `expired` checkout can still become `paid`. This happens when the buyer had
picked a coin and a matching deposit arrives within **24 hours after
`expires_at`**. Until then, keep polling an expired checkout at a slow rate,
e.g. once a minute, and do not cancel the order on `expired` alone. A checkout
whose buyer never picked a coin, or that expired more than 24 hours ago, stays
`expired`.

A deposit matches a checkout when all of these are true:

- the asset is the same;
- it arrives at the checkout's address after the coin was picked;
- it is at least the quoted `payment.amount`;
- no other checkout has claimed it.

A live checkout wins over an expired one for the same deposit.

## Errors

Errors look like `{"error": {"code": "...", "message": "..."}}`. Act on the
`code`. The `message` is for logs; for `validation_failed` it starts with the
field it is about, e.g. `amount.value: …`.

| Status | Code | Meaning |
| --- | --- | --- |
| `400` | `validation_failed` | The request is invalid. The message names the field. |
| `400` | `invalid_webhook_url` | Webhooks only: the URL is not `https://` or is malformed. |
| `401` | `unauthorized` | The token is missing, expired or invalid. |
| `403` | `account_forbidden` | The token has no access to `account_ref`. |
| `403` | `insufficient_capability` | Create only: the token lacks `funding_endpoints.provision` on the account. |
| `403` | `checkout_disabled` | Checkout is turned off for your enterprise. Contact YouHodler. |
| `404` | `checkout_not_found` | No such checkout, or one you cannot see. It is never `403`. |
| `404` | `merchant_not_enabled` | The account is not connected to Checkout. Connect it first. |
| `404` | `webhook_not_configured` | Webhooks only: the account has no webhook endpoint. |
| `404` | `webhook_delivery_not_found` | Webhooks only: no such delivery for this account. |
| `409` | `checkout_conflict` | A concurrent change. Retry. |
| `409` | `checkout_expired` | Hosted page only: the checkout has expired. |
| `409` | `checkout_not_payable` | Hosted page only: the checkout cannot take a coin choice now. |
| `422` | `currency_not_supported` | Create only: no coin can be priced in `amount.currency` right now. |
| `422` | `unsupported_payment_option` | Hosted page only: that asset and network are not offered. |
| `500` | `internal_error` | An unexpected error. Retry later. |
| `503` | `platform_unavailable` | The platform did not answer. Retry with the same `Idempotency-Key`. |
| `503` | `merchant_misconfigured` | The account's Checkout setup on the YouHodler side is incomplete. Contact YouHodler; a retry does not help. |
| `503` | `price_unavailable` | Hosted page only: no price for the coin right now. |
| `503` | `address_not_ready` | Hosted page only: the deposit address is still being created. Retry. |
| `503` | `address_failed` | Hosted page only: the deposit address could not be created. |

The codes marked "Hosted page only" come from the page's own endpoints. The
page handles them; your server does not see them.

## Test a payment

On sandbox, pay with testnet coins:

1. Create a checkout and open its `url`.
2. Pick a coin whose network runs on a testnet on sandbox. The page lists only
the networks the environment supports.
3. From a testnet wallet, send at least the quoted amount to the address shown
on the page.
4. Watch the status go from `awaiting_payment` to `processing` to `paid`.

## Beta limits

- **USD, ARS and CHF.** A checkout is priced in one of them; you receive the coin
the buyer sends, not the fiat amount.
- **No receipts.** The page collects the buyer's details (see
[Buyer details](#buyer-details)) but does not send receipts.
