# For payments

Take payment in the coins your customers hold, and receive native BTC at your own Bitcoin address. Or receive BTC and pay out in stablecoins. For merchants, checkout providers and payout services that want Bitcoin settlement without holding anyone's funds in between.

## What to build

1. **Sign a checkout link on your server.** Maxy hosts the buy page. Your server signs a link with your secret key: HMAC-SHA256 over the sorted query string. Set `recipient` to your own Bitcoin address, and the customer cannot change it.
2. **Send the customer to it.** The page runs at `https://buy.maxy.co`; its older address still answers. Link to it, open it in a window, or frame it. Only your publishable key's origins can frame the page, and its events reach your page by `postMessage`, sent only to those origins.
3. **Match the payment to your invoice.** Put your invoice id in `externalId`. It comes back on every [webhook](https://maxy.co/docs/webhooks) and statement. When the order ends, the customer returns to your `redirectUrl` with `orderId` and `state`.
4. **Close the books monthly.** `GET /statements?month=2026-11` gives the month's orders with totals, in JSON, CSV or PDF: [Reconcile](https://maxy.co/docs/order-states#reconcile).

```ts
import { signCheckoutUrl } from 'maxy-labs/server';

const url = await signCheckoutUrl({
  apiKey: process.env.MAXY_PUBLISHABLE_KEY!,                 // mxk_pk_test_…: the page runs it in the browser
  from: 'USDC on base',
  defaultAmount: '50',
  recipient: 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4',   // your Bitcoin address: signed, the user cannot change it
  externalId: 'invoice-1042',
  redirectUrl: 'http://localhost:3000/paid',                 // on one of the publishable key's origins
}, process.env.MAXY_API_KEY!);
console.log(url);
```

A link lasts an hour unless you say otherwise: `signCheckoutUrl(params, secretKey, { expiresInSec })` sets its life in seconds. The link carries the fields you passed plus `kid` (the prefix of the secret key that signed it), `exp` (when it stops working, in Unix seconds) and `sig` (the HMAC-SHA256 signature over the rest). The page shows nothing if one character of it changes. To check a link yourself, `GET /checkout/verify` with its query string answers what was signed. It needs no key; `BASE` is as on [Get a price](https://maxy.co/docs/buy-btc#get-a-price).

```sh
CHECKOUT_URL='https://…'
curl -s "$BASE/checkout/verify?${CHECKOUT_URL#*\?}" | jq '{valid, sandbox, frameAncestors, recipient: .params.recipient}'
```

`CHECKOUT_URL` is the link `signCheckoutUrl` made.

| Parameter | Does |
| --- | --- |
| `apiKey` | Your publishable key |
| `from`, `defaultAmount` | What the page starts at. The customer can change the amount |
| `recipient` | The Bitcoin address that receives. Leave it out and the customer types one |
| `externalId`, `externalCustomerId` | Your ids, on webhooks and statements |
| `redirectUrl` | Where the customer goes when the order ends. Must be on one of the key's origins |
| `theme`, `locale` | The page's look and language |

A changed link, a revoked key or a `redirectUrl` off the key's origins answers `checkout_signature_invalid`; an old one, `checkout_expired`. Sign a new one.

## Your own checkout

To keep the screens in your app, run the order yourself: [Flow helpers](https://maxy.co/docs/flow-helpers) in the page, with the order placed from your server. Paying with USDC on Base or Arbitrum, the customer signs and sends no transaction, so a customer who has never held ETH can pay: [Pay with USDC](https://maxy.co/docs/pay-with-usdc).

## Pay out in stablecoins

Holding BTC and paying out in dollars, sell BTC for USDC or USDT on Base, Arbitrum and BNB Chain, USDC or USDt on Avalanche, or USDG on Robinhood Chain. The solver locks the payout in the settler before any BTC moves, and a proof of your payment releases it to your EVM wallet. Pay one output of exactly `sats`, on time: [Sell BTC](https://maxy.co/docs/sell-btc).

## Keys

Sign links with your secret key, on your server only. The link carries the publishable key, which only works on the origins Maxy issued it for. Both keys must be test keys, or both live. With test keys the whole checkout runs in the [sandbox](https://maxy.co/docs/sandbox), and nothing real moves. Before going live: [Launch checklist](https://maxy.co/docs/launch-checklist).

---
Source: https://maxy.co/docs/for-payments (Maxy Docs › Maxy for your app › Use cases)
