# Payments

Taking money for a customer: every method and direction with its status, then checkout sessions, payment links, payments, saved methods, subscriptions, refunds, disputes, and paying a checkout session by stablecoin or bank transfer.

Status: card, wallet and bank-debit acceptance and payment instructions at checkout are test mode only. Delegated payment tokens and paying by the call are preview, off by default. The code is `lib/checkout.ts`, `lib/payments-sync.ts`, `lib/deposits.ts`, `lib/ops/` and `lib/providers/cards.ts`; the matrix is `lib/pure/payment-matrix.ts`.

The customer is the merchant: each customer holds its own account at the card processor, created on demand and onboarded on a hosted page, and Skerry acts on it as the platform. Payers pay on hosted pages, so card details never reach Skerry or the partner. Amounts are integer minor units beside a lowercase `currency`.

## Before a customer can take a card payment

A customer takes card payments once its own account at the card processor reports that charges are enabled. `GET /customers/{id}` says so in `can.accept_cards` and in `card_acceptance`. Until then a checkout session or a payment is refused with 409 `onboarding_incomplete`, and `detail.steps` names `card_acceptance`.

`card_acceptance.currencies` lists the currencies a card payment can be presented in, from the processor's rules for the account's country, and `card_acceptance.settlement_currency` the one its settlements arrive in. A checkout session, payment link or subscription in any other currency is refused with 400 `currency_not_supported` before the processor is asked, and `detail.accepted` lists the ones that work. A session that can also be paid by instruction is still made, without the card. Both fields are empty until the account has been read from the processor once.

A person does this step, once for each customer. `POST /customers/{id}/onboarding-link` with `steps: ["card_acceptance"]` returns a link. Whoever opens it is sent to the card processor's hosted page, confirms the details of the business there and accepts the processor's agreement. Business verification is a separate step, and a card payment does not wait for it.

Sandbox is the same. The account is the business's own account at the card processor, and the processor takes its agreement only from a person on its own page, so no call completes this step, in test mode either. In sandbox the page accepts the processor's test values and no real business is checked. Do it once for each sandbox customer that takes payments. `POST /customers/{id}/verification` is not this step: it carries business verification only, and only for a customer whose owner has already opened the hosted onboarding.

### Before the banking partner knows a customer

A customer made from a name, an email and a country is not known to the banking partner until its owner has been through hosted onboarding (`POST /customers/{id}/onboarding-link`). Until then:

- A list of what the banking partner holds for the customer (accounts, payees, wallets, standing orders, memos, people, and `GET /payouts?customer_id=`) answers with an empty `data`.
- One thing of the customer's by its id (a payee, an account, a wallet, a standing order's conversions, a person) answers 404: none of them exists yet.
- An operation that makes or changes something at the banking partner, or reads its settings (fees, rewards), answers 409 `onboarding_incomplete` with `detail.next_step` naming the onboarding link.
- The customer itself, its verification and its card acceptance answer as for any customer.

## Every method and direction

`GET /capabilities` returns this matrix as `payment_methods`; `GET /customers/{id}/payment-methods` returns it for one customer with each cell marked `enabled`. A cell has one status, a `reason_code`, and the provider by role. `test/payment-matrix.test.mjs` fails when a cell claims to work and no route serves it.

| Status | Meaning |
|---|---|
| `available` | Works for every verified customer. |
| `per_customer` | Works for a customer the provider has enabled for it. |
| `preview` | Built against a provider preview; off unless the deployment switches it on and the customer's merchant account reports the feature. |
| `off` | Intended, not usable yet. |
| `not_offered` | Not served, or the direction does not apply to the method. |

`Settles` says whether the outcome is known as the payer finishes (`immediate`) or arrives later as an event (`delayed`): a delayed method moves a payment through `processing` to `succeeded` or `failed`.

| Method | Provider | Settles | pay_in | pay_out | hold_and_capture | recurring | refund | dispute |
|---|---|---|---|---|---|---|---|---|
| Cards | card_processor | immediate | per_customer | not_offered | per_customer | per_customer | per_customer | per_customer |
| Wallets (saved cards and device wallets) | card_processor | immediate | per_customer | not_offered | per_customer | per_customer | per_customer | per_customer |
| Klarna | card_processor | immediate | per_customer | not_offered | per_customer | not_offered | per_customer | per_customer |
| Affirm | card_processor | immediate | per_customer | not_offered | per_customer | not_offered | per_customer | per_customer |
| Afterpay and Clearpay | card_processor | immediate | per_customer | not_offered | per_customer | not_offered | per_customer | per_customer |
| iDEAL | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| Bancontact | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| EPS | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| Przelewy24 | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| BLIK | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| TWINT | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| Swish | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| MobilePay | card_processor | immediate | per_customer | not_offered | per_customer | not_offered | per_customer | per_customer |
| Pix | card_processor | immediate | per_customer | not_offered | not_offered | not_offered | per_customer | per_customer |
| Cash App Pay | card_processor | immediate | per_customer | not_offered | per_customer | per_customer | per_customer | per_customer |
| Amazon Pay | card_processor | immediate | per_customer | not_offered | per_customer | per_customer | per_customer | per_customer |
| Revolut Pay | card_processor | immediate | per_customer | not_offered | per_customer | per_customer | per_customer | per_customer |
| Multibanco | card_processor | delayed | per_customer | not_offered | not_offered | not_offered | per_customer | not_offered |
| Konbini | card_processor | delayed | per_customer | not_offered | not_offered | not_offered | per_customer | not_offered |
| Boleto | card_processor | delayed | per_customer | not_offered | not_offered | not_offered | not_offered | not_offered |
| OXXO | card_processor | delayed | per_customer | not_offered | not_offered | not_offered | not_offered | not_offered |
| ACH debit | card_processor | delayed | per_customer | not_offered | not_offered | per_customer | per_customer | per_customer |
| SEPA debit | card_processor | delayed | per_customer | not_offered | not_offered | per_customer | per_customer | per_customer |
| Bacs debit | card_processor | delayed | per_customer | not_offered | not_offered | per_customer | per_customer | per_customer |
| Stablecoin on the hosted page | card_processor | delayed | per_customer | not_offered | not_offered | not_offered | per_customer | not_offered |
| ACH credit into a virtual account | banking_partner | delayed | available | not_offered | not_offered | not_offered | available | not_offered |
| Wire into a virtual account | banking_partner | delayed | available | not_offered | not_offered | not_offered | available | not_offered |
| SEPA credit into a virtual account | banking_partner | delayed | available | not_offered | not_offered | not_offered | available | not_offered |
| Faster Payments into a virtual account | banking_partner | delayed | off | not_offered | not_offered | not_offered | off | not_offered |
| ACH payout | banking_partner | delayed | not_offered | available | not_offered | not_offered | not_offered | not_offered |
| Same-day ACH payout | banking_partner | delayed | not_offered | available | not_offered | not_offered | not_offered | not_offered |
| Wire payout | banking_partner | delayed | not_offered | available | not_offered | not_offered | not_offered | not_offered |
| FedNow payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| RTP payout | banking_partner | delayed | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| SEPA payout | banking_partner | delayed | not_offered | available | not_offered | not_offered | not_offered | not_offered |
| Faster Payments payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| SPEI payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| Pix payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| Bre-B payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| Colombian bank transfer payout | banking_partner | delayed | not_offered | per_customer | not_offered | not_offered | not_offered | not_offered |
| USDC on base, ethereum, polygon, solana, arbitrum, optimism, tron, stellar, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| USDT on base, ethereum, polygon, solana, arbitrum, optimism, tron, stellar, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| EURC on base, ethereum, polygon, solana, arbitrum, optimism, tron, stellar, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| PYUSD on base, ethereum, polygon, solana, arbitrum, optimism, tron, stellar, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| USDB on base, ethereum, polygon, solana, arbitrum, optimism, tron, stellar, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| OUSD on base, ethereum, solana, tempo | banking_partner | delayed | per_customer | per_customer | not_offered | not_offered | per_customer | not_offered |
| Conversion between a customer's own balances | banking_partner | delayed | not_offered | available | not_offered | not_offered | not_offered | not_offered |
| Pulling money from a bank account into a wallet on demand | banking_partner |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| Cards issued against a balance | banking_partner |  | not_offered | off | not_offered | not_offered | not_offered | off |
| Paying by the call in stablecoin (x402 and the Machine Payments Protocol) | card_processor | delayed | preview | not_offered | not_offered | preview | preview | not_offered |
| Paying by the call with a delegated card token (the Machine Payments Protocol) | card_processor | immediate | preview | not_offered | not_offered | preview | preview | preview |
| A delegated payment token presented by an agent at checkout (seller side) | card_processor | immediate | preview | not_offered | not_offered | not_offered | preview | preview |
| An agent paying other merchants (buyer side) | none |  | not_offered | preview | not_offered | not_offered | not_offered | not_offered |
| Push to a debit card | none |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| Cash | none |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| Cheque | none |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| Mobile money | none |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |
| Crypto assets other than stablecoins | none |  | not_offered | not_offered | not_offered | not_offered | not_offered | not_offered |

A method the card processor reports active on a merchant account that this table does not know is still shown for that customer, with refund and dispute marked as the processor reports them.

| Reason code | Meaning |
|---|---|
| `ok` | Works as documented. |
| `enabled_at_onboarding` | Switched on for a customer when the card processor has enabled it on the customer's merchant account. |
| `enabled_at_verification` | Switched on for a customer during verification by the banking partner. |
| `chain_coin_pair_varies` | Offered where the banking partner supports this coin on this chain for the customer. |
| `payee_bank_dependent` | Used only when the payee's bank reports that it can receive it. |
| `not_applicable` | This direction does not apply to this method. |
| `not_built` | The provider offers it; this platform does not serve it yet. |
| `no_holds_on_method` | The method collects at once; there is nothing to hold and capture later. |
| `no_recurring_on_method` | The method cannot be charged again without the payer present. |
| `method_has_no_refunds` | The method cannot be refunded through the processor; return the money another way. |
| `method_has_no_disputes` | The payer authorises each payment, so the method has no dispute process. |
| `refund_is_a_payout` | A refund is a payout back to where the money came from, or to a destination given with the refund. |
| `as_reported_by_processor` | Depends on the method as the card processor reports it for the payment. |
| `preview_off_by_default` | Built against a provider preview. Off unless the deployment switches it on and the customer's merchant account reports the feature. |
| `card_issuing_not_switched_on` | Card issuing is switched off for this platform. |
| `account_currency_not_switched_on` | Accounts in this currency are switched off for this platform. |
| `inbound_only` | Reported on money arriving; not offered for sending. |
| `provider_has_no_pull_api` | The banking partner documents no call that pulls money from a bank account on demand. Money comes in by the payer sending it to a virtual account. |
| `agent_paying_preview` | Built from the wallet provider's and the payment protocols' documentation, and not yet run against them. Off unless the deployment switches it on and connects the wallet provider. |
| `not_served` | The platform does not serve this method. |
| `not_served_non_stablecoin` | Only stablecoins are held and moved. Other crypto assets are not served. |

## The operations

| Operation | Scope | Idempotency-Key | Moves money | What it does |
|---|---|---|---|---|
| `POST /checkout-sessions` | `payments:write` | optional | yes | Start a checkout for a payer. |
| `GET /checkout-sessions` | `payments:read` | none | no | Checkout sessions, newest first. |
| `GET /checkout-sessions/{id}` | `payments:read` | none | no | One session. |
| `POST /checkout-sessions/{id}/expire` | `payments:write` | optional | no | Close an open session so it can no longer be paid. |
| `POST /payment-links` | `payments:write` | optional | yes | A reusable or single-use link to a hosted checkout for a fixed amount. |
| `GET /payment-links` | `payments:read` | none | no | Payment links, newest first. |
| `GET /payment-links/{id}` | `payments:read` | none | no | One payment link, with how many times it has been used. |
| `PATCH /payment-links/{id}` | `payments:write` | none | no | Pause, resume or disable a link. |
| `GET /payments` | `payments:read` | none | no | Payments, newest first. |
| `GET /payments/{id}` | `payments:read` | none | no | One payment: status, fee, amounts received and refunded, and `risk` (level, score and how the payer's authentication ended) where the processor reports them. |
| `POST /payments` | `payments:write` | required | yes | Charge a saved method with the payer absent, under the mandate they gave; or, with `payment_token`, charge a delegated payment token an agent holds for its buyer (a preview: 409 `capability_off` until it is switched on for the customer). |
| `POST /payments/{id}/capture` | `payments:write` | optional | yes | Collect funds that were held. |
| `POST /payments/{id}/cancel` | `payments:write` | optional | no | Release a hold, or abandon a payment that has not succeeded. |
| `POST /payments/{id}/refunds` | `refunds:write` | required | yes | Refund all or part of a payment. |
| `GET /payments/{id}/refunds` | `payments:read` | none | no | Refunds made against a payment. |
| `GET /disputes` | `payments:read` | none | no | Disputes against payments, newest first. |
| `GET /disputes/{id}` | `payments:read` | none | no | One dispute, with the date evidence is due. |
| `POST /disputes/{id}/evidence` | `payments:write` | optional | no | Send evidence, and submit it when complete: text fields, file fields (the id of an uploaded file) and `enhanced_evidence`. |
| `POST /disputes/{id}/files` | `payments:write` | optional | no | Upload a file to use as evidence: PDF, JPEG or PNG, up to 5 MB, base64-encoded. |
| `GET /disputes/{id}/files` | `payments:read` | none | no | Files uploaded for a dispute, newest first. |
| `GET /disputes/{id}/suggested-evidence` | `payments:read` | none | no | A draft of the text evidence from what is on record: the session, what was bought, the delegated token and its limits, how the calling agent identified itself, and the times. |
| `GET /customers/{id}/unmatched-deposits` | `payments:read` | none | no | Deposits that could not be credited to a checkout session (wrong coin or chain, no reference, an unknown reference, or late), waiting for a person. |
| `POST /customers/{id}/unmatched-deposits/{deposit_id}/assign` | `payments:write` | optional | no | Credit a deposit that was set aside to the checkout session it was meant for. |
| `POST /customers/{id}/unmatched-deposits/{deposit_id}/refund` | `refunds:write` | required | yes | Send a deposit that was set aside back, whole: to where it came from when that is on record, otherwise to `destination`. |
| `GET /settlements` | `settlements:read` | none | no | Card proceeds on their way to the business's bank, newest first. |
| `GET /settlements/{id}` | `settlements:read` | none | no | One settlement. |
| `POST /settlements` | `settlements:write` | required | yes | Send proceeds to the business's bank now. |
| `GET /customers/{id}/balances` | `customers:read` | none | no | What the customer holds per currency: card proceeds (available, pending) and stablecoin. |
| `POST /payers` | `payments:write` | optional | no | Record someone who pays a customer. |
| `GET /payers` | `payments:read` | none | no | Payers, newest first. |
| `GET /payers/{id}` | `payments:read` | none | no | One payer. |
| `GET /payers/{id}/payment-methods` | `payments:read` | none | no | Methods the payer saved: brand, last four, expiry, and the mandate. |
| `DELETE /payers/{id}/payment-methods/{method_id}` | `payments:write` | none | no | Forget a saved method and revoke its mandate. |
| `POST /customers/{id}/payment-method-setups` | `payments:write` | optional | no | A hosted page where a payer saves a method for later, without paying now. |
| `POST /subscriptions` | `payments:write` | required | yes | Charge a payer on a schedule from a saved method. |
| `GET /subscriptions` | `payments:read` | none | no | Subscriptions, newest first. |
| `GET /subscriptions/{id}` | `payments:read` | none | no | One subscription. |
| `POST /subscriptions/{id}/cancel` | `payments:write` | optional | no | End a subscription now or at the end of the paid period. |
| `POST /meters` | `payments:write` | optional | no | A usage meter on a customer's merchant account, for billing by use. |
| `GET /meters` | `payments:read` | none | no | Meters, newest first. |
| `POST /meters/{id}/events` | `payments:write` | optional | no | Record usage by a payer against a meter. |
| `GET /meters/{id}/summary` | `payments:read` | none | no | What a payer has used over a period. |

## Checkout sessions

```text
POST /checkout-sessions
Authorization: Bearer sk_test_…
Idempotency-Key: 4c2a…

{ customer_id, amount | line_items, currency, ui?: skerry | hosted | embedded, success_url?, cancel_url?, methods?, payment_instructions?: { methods: [stablecoin | bank_transfer], wallet_id, chain?, coin? }, authentication?, capture?, save_method?, payer_id? | payer?, expires_at?, reference?, external_ref?, external_kind?, metadata? }
```

`ui` picks where the payer pays:

- `skerry`: Skerry's own checkout. `url` is Skerry's page for the session on Skerry's host (`https://api.skerry.xyz/checkout/{id}`), and the same session can be mounted on your own page with Skerry's script or React package (below). `success_url` is optional: once the payment is confirmed the payer goes on to it, or sees Skerry's page saying it is paid. Open in an environment once Skerry's publishable key for it is set; until then the request answers 409 `ui_unavailable`.
- `hosted` (the default): the card processor's own page. `success_url` is required.
- `embedded`: the card processor's own embedded form; the response carries `client_params` for it.

The session carries its page's URL and `share_url`. The page offers the methods enabled for the business at the processor: cards and wallets always, bank debit and stablecoin only where the processor reports them active on the merchant account. `methods` is checked against that and does not narrow what the page shows; the response says what is offered. `capture: "manual"` holds funds for `POST /payments/{id}/capture`; `save_method` with a payer saves the method; `authentication` is `automatic` or `required`. `expires_at` must be between 30 minutes and 24 hours from now.

Build orders from `payment.succeeded`, never from the payer's browser returning to `success_url`. While a session is open, `GET /checkout-sessions/{id}` also asks the processor, so a missed webhook cannot mislead.

Under a mandate, a session or a payment link above the mandate's `checkout_above` is checked as `checkout.create` or `payment_link.create`, and a credential that may only act under a policy has its operation list checked whatever the amount.

`POST /sandbox/checkout-sessions/{id}/complete` with `{ outcome }` acts as the payer: succeed, decline, run short of funds, or open a dispute.

## Payment links

```text
POST /payment-links

{ customer_id, amount, currency, description?, reusable?, max_uses?, expires_at?, reference?, external_ref?, external_kind?, success_url? }
```

Single-use, capped or reusable. `PATCH /payment-links/{id}` with `{ status }` pauses, resumes or disables one.

Where Skerry's own checkout is open, the link's `share_url` is Skerry's page for it: who is paid, how much, and a pay button. Pressing the button opens a `ui: "skerry"` session for the link (`POST /pay-link/{id}/session`), and the form appears in its place; `success_url` is where the payer goes once paid. A single-use or capped link is never over-sold: while its uses and the sessions still open for it reach the cap, the open session is handed out again, and once it is used up the link is completed, its other open sessions are closed and its page at the processor is switched off. Where Skerry's own checkout is not open, `share_url` sends the payer to the processor's page, as `url` does. A link also has a `share_url`; see [agentic-checkout.md](agentic-checkout.md) for what it answers a client that asks for JSON.

## Skerry's form and pay button on your page

A `ui: "skerry"` session can be paid on your own page. Skerry's script draws the form in the Praecise look, light or dark, at any width. The card and wallet fields in it are the card processor's own embedded elements: the script loads the processor's script from the processor and mounts its fields with the processor's publishable key, so card data never reaches Skerry or you.

```html
<div data-skerry-checkout="{checkout_session_id}"></div>
<div data-skerry-link="{payment_link_id}"></div>
<script type="module" src="https://api.skerry.xyz/js/skerry.js"></script>
```

Or from code, with `@skerry/js` (`mountCheckout(element, { session, onComplete })`, `mountPayButton(element, { session | link, inline? })`) or `@skerry/react` (`<SkerryCheckout session={id} />`, `<SkerryPayButton link={id} />`). Both are in skerry-clients. Without `onComplete`, the payer goes on to the session's return address, which goes on to `success_url`. `data-skerry-theme` (`light`, `dark`, `auto`) picks the look; a page may set the `--skerry-*` CSS variables on `.skerry` to adjust it. `data-skerry-accent` (or `accent`) gives the pay button the page's brand colour, used only where the words on it reach WCAG AA. `data-skerry-locale` (or `locale`, a BCP 47 tag; the browser's language by default) sets the language the amounts are written in and the processor's fields speak; `messages` gives the page's own words for Skerry's text, which is English, the source.

The script reads `GET /checkout/{id}/client`, which any origin may read: the amount, the lines, the merchant's name, and while the session is open the processor's script, publishable key, account and the session's client secret, which can pay this one session and nothing else. The processor sends a payer back to `GET /checkout/{id}/return`, which reads the outcome from the processor before going on. As always, build orders from `payment.succeeded`, not from the browser.

## Payments

`GET /payments/{id}` returns status, fee, amounts received and refunded, and `risk` where the processor reports it. A payment that did not come by card also carries `method` (stablecoin, bank_transfer or machine), `payer_ref` and `amount_overpaid`; one an agent made carries `agent` and `agent_identity`. `?wait=<seconds up to 30>&until=<state>` holds the request until the payment reaches a final state.

`POST /payments/{id}/capture` with `{ amount? }` collects a hold, and may capture less than the hold. `POST /payments/{id}/cancel` releases a hold or abandons a payment that has not succeeded.

### Charging a saved method

```text
POST /payments
Idempotency-Key: 9d0f…

{ customer_id, payer_id, payment_method_id, amount, currency, off_session: true, authentication?, capture?, reference?, external_ref?, external_kind?, description?, metadata? }
```

The payer must have agreed to be charged later (`mandate_required` otherwise). The call is checked by the spend guard as `payment.charge`. A decline is returned as a payment with `status: failed` and a reason, not as an error, and does not count against a limit.

The other form of the body, `{ customer_id, amount, currency, payment_token: { type: "shared_payment_token", id }, … }`, charges a delegated payment token an agent holds for its buyer. That is a preview: it answers 409 `capability_off` until it is switched on for the customer.

## Payers, saved methods and subscriptions

A payer is someone who pays a customer. `POST /customers/{id}/payment-method-setups` with `{ payer_id | payer, success_url, cancel_url }` returns a hosted page where the payer saves a method without paying; `payment_method.saved` follows. `GET /payers/{id}/payment-methods` returns brand, last four, expiry and the mandate, never a card number. `DELETE /payers/{id}/payment-methods/{method_id}` forgets the method and revokes its mandate.

```text
POST /subscriptions
Idempotency-Key: 71be…

{ customer_id, payer_id, payment_method_id, currency, interval, interval_count?, items: [{ name, amount, quantity? }], trial_days?, reference?, external_ref?, external_kind?, dry_run? }
```

Each period's charge arrives as a payment and as `subscription.payment_succeeded` or `subscription.payment_failed`. Under a mandate that covers `subscription.create`, the amount of one period is checked against the mandate and counted once. `POST /subscriptions/{id}/cancel` with `{ at_period_end? }` ends it now or at the end of the paid period.

Usage meters (`/meters`) are per account: they answer `capability_off` until a platform administrator switches them on.

## Refunds

```text
POST /payments/{id}/refunds
Idempotency-Key: a13c…

{ amount?, reason?, destination?: { address, chain? } | { payee_id }, external_ref?, external_kind? }
```

Checked by the spend guard as `refund.create`. Refused above what remains of the payment (`refund_not_possible`), in another currency (`currency_mismatch`), and for a method that cannot be refunded through the processor (`refund_not_supported`, before the processor is asked). `refund.updated` and `payment.refunded` follow.

A payment made by stablecoin or bank transfer is refunded by a payout back: to the sending address, or to the sending bank account through the banking partner's return of the deposit, where that is on record; otherwise to `destination` (`refund_destination_required` when neither exists). A bank deposit on ACH or FedNow goes back whole.

## Disputes

`GET /disputes/{id}` carries the date evidence is due. Evidence is text fields, file fields and `enhanced_evidence`, from the lists the card processor accepts; a field outside them is refused by name.

```text
POST /disputes/{id}/files
{ filename, content_type, data }

POST /disputes/{id}/evidence
{ evidence: { ... }, submit? }
```

A file is PDF, JPEG or PNG, up to 5 MB, base64-encoded; its id is then named in a file field. `GET /disputes/{id}/suggested-evidence` drafts the text evidence from what is on record (the session, what was bought, a delegated token and its limits, how the calling agent identified itself, the times) for a person to review; nothing is submitted by it. A dispute that is no longer waiting for a response refuses evidence and files with `dispute_closed`.

## Settlements and balances

`GET /settlements` lists card proceeds on their way to the business's bank; `POST /settlements` with `{ customer_id, amount, currency }` sends proceeds now and needs an Idempotency-Key. They are named settlements so they cannot be confused with payouts, which move stablecoin and bank transfers from the customer's balances at the banking partner. `GET /customers/{id}/balances` returns what the customer holds per currency: card proceeds (available, pending) and stablecoin.

## Stablecoin and bank transfer at checkout

A session created with `payment_instructions` carries `payment_instructions[]`:

- for `stablecoin`, a deposit address (and a memo where the chain uses one) for a named coin on a named chain;
- for `bank_transfer`, the details of a virtual account and a `reference` the payer must quote.

`wallet_id` is the customer's wallet the money is delivered to. The instructions are bound to the session and expire with it. A customer without card acceptance can open a session that has instructions only: it has no hosted page, and expires after 24 hours unless `expires_at` says otherwise. A coin is accepted for a session only when it is pegged to the session's currency, one for one.

The session completes when the deposit arrives, as one payment with `method`, `rail`, `amount_received`, `fee` and the usual events. The rules for a deposit are in `lib/pure/deposit-match.ts`:

| What arrives | What happens |
|---|---|
| The amount, as asked | The session completes; the payment succeeds. |
| The same deposit reported twice | Credited once. |
| Too little | The session stays open with `amount_remaining` until it expires. Then the payment fails with `underpaid`, and what arrived is refundable. |
| Too much | The session completes; the excess is `amount_overpaid` and refundable. |
| A second deposit to a session already paid | All of it is excess. |
| The wrong coin, the wrong chain, no reference, or a reference nobody issued | Never credited. It becomes an unmatched deposit (`deposit.unmatched`). |
| A deposit after the session expired | The same: an unmatched deposit. |

An unmatched deposit waits for a person:

```text
GET  /customers/{id}/unmatched-deposits?status=
POST /customers/{id}/unmatched-deposits/{deposit_id}/assign   { checkout_session_id }
POST /customers/{id}/unmatched-deposits/{deposit_id}/refund   { destination?: { address, chain? } | { payee_id } }
```

`refund` sends it back whole and needs an Idempotency-Key; `deposit.resolved` follows either. One that is already assigned or sent back answers `deposit_resolved`.

`POST /sandbox/checkout-sessions/{id}/deposit` with `{ method?, amount?, coin?, chain?, reference?, state?, at?, deposit_ref? }` acts as the payer on a session's instructions: pay it, underpay, overpay, pay late, or send the wrong coin, chain or reference.

## Events

| Event | Concerns | When |
|---|---|---|
| `checkout_session.completed` | checkout_session | A payer finished a checkout session. |
| `checkout_session.expired` | checkout_session | A checkout session expired unpaid. |
| `payment.requires_action` | payment | The payer must authenticate before the payment can proceed. |
| `payment.processing` | payment | The payer has paid by a method that settles later, such as a bank debit. Wait for payment.succeeded or payment.failed. |
| `payment.authorized` | payment | Funds are held and waiting to be captured. |
| `payment.succeeded` | payment | Funds were collected. |
| `payment.failed` | payment | The payment was declined or failed. |
| `payment.canceled` | payment | An authorisation was released before capture. |
| `payment.refunded` | payment | A payment was refunded, wholly or in part. Read `data.status` to tell which: `refunded` or `partially_refunded`. |
| `payment.disputed` | dispute | The payer's bank opened a dispute. |
| `dispute.updated` | dispute | A dispute moved: evidence due, under review, won or lost. |
| `refund.updated` | refund | A refund changed state. |
| `payment_method.saved` | payment_method | A payer saved a method for later charges. |
| `settlement.created` | settlement | Card proceeds were sent towards the business's bank. |
| `settlement.paid` | settlement | A settlement arrived. |
| `settlement.failed` | settlement | A settlement failed. |
| `subscription.updated` | subscription | A subscription was created or changed. |
| `subscription.canceled` | subscription | A subscription ended. |
| `subscription.payment_succeeded` | subscription | A recurring charge collected. |
| `subscription.payment_failed` | subscription | A recurring charge failed. |
| `deposit.unmatched` | unmatched_deposit | Money arrived that could not be credited to a checkout session: the wrong coin or chain, no known reference, or after the session expired. A person assigns it or sends it back. |
| `deposit.resolved` | unmatched_deposit | An unmatched deposit was assigned to a session, or sent back. |

The card processor's events these come from are in providers.md.
