# AIPAY as a payment provider — answers to a capability assessment

Audience: a platform evaluating AIPAY as its payment channel. This document
answers the ten questions in the assessment dated 2026-11-11 one by one, with
the exact endpoints and the parts that are genuinely missing. It is written to
be read as evidence, not as sales material: every limit below is also stated in
the public docs it links to.

Canonical URLs: <https://aipay.im/docs/merchant-order-service.md> ·
<https://aipay.im/docs/integration.md> · <https://aipay.im/docs/security.md> ·
live discovery <https://api.aipay.im/v1> · agent index <https://aipay.im/agent.json> ·
machine index for crawlers <https://aipay.im/llms.txt> (relative: ../llms.txt).

## 0. First, why the assessment could not see the merchant product

The assessment was written from **MCP tool contracts** exposed in a local Pi
environment. Those tools are the *payer-side* surface: they let an agent read a
wallet, quote a payment, create a payment request and look at its own orders.
The merchant product is a separate HTTP API at `https://api.aipay.im/v1`
(API key auth) and it is deliberately **not** exposed through those tools —
`agent.json` says so explicitly (`agent_tools.available = false`, with
`not_available` listing the merchant-channel tools).

So "no webhooks / no automatic confirmation / no state machine" was a correct
reading of the tool list and an incorrect reading of the product. Everything in
§1–§7 below exists today; §8 lists what really is missing.

## 1. What AIPAY is, as a merchant

Non-custodial crypto payment requests plus chain reconciliation, with an
off-chain (fiat) orchestration layer that **never touches the money**.

| Endpoint | Auth | Purpose |
| --- | --- | --- |
| `POST /v1/merchants` | none (5/day/IP) | create a merchant, returns `apiKey` (+ `webhookSecret`) once |
| `GET \| PATCH \| DELETE /v1/merchants/me` | key | profile, quota, notification readiness; delete = hard delete |
| `POST /v1/merchants/me/keys/rotate` | key | new key, old key keeps 1–72 h grace |
| `POST /v1/orders` | key | create an order (idempotent on `merchantOrderId`) |
| `GET /v1/orders` | key | list with `status`, `from`/`to`, `confirmedFrom`/`confirmedTo`, cursor |
| `GET /v1/orders/export.csv` | key | reconciliation CSV (19 columns, see §7) |
| `GET /v1/orders/:reference` | key (richer) / none | receipt; merchant view adds notifications |
| `GET /v1/orders/:reference/status` | none | payer-side poll |
| `POST /v1/orders/:reference/confirm` | key | server-verified confirmation from a tx hash |
| `POST /v1/orders/:reference/cancel` | key | idempotent cancel |
| `GET \| POST /v1/channels`, `PATCH \| DELETE /v1/channels/:id` | key | register the merchant's own off-chain channel |
| `POST /v1/orders/:ref/offchain-confirm`, `POST /v1/offchain/confirmations` | key / channel HMAC | merchant receipt confirms an off-chain order |
| `GET \| POST /v1/offchain/statements` + `adopt`/`ignore` | key | CSV statement import (proposes only) |
| `GET /v1`, `GET /v1/health` | none | discovery + liveness/sweeper mode |

**Fiat money is not collected by AIPAY.** On an off-chain channel, AIPAY stores
*your* payment link and *your* settlement currency, and records the order. The
customer pays through your provider; you confirm with a receipt (manual, signed
webhook with a channel secret, or an adopted statement row). The fiat on-ramp
feature is shipped disabled.

## 2. Order state machine

Statuses: `pending`, `confirmed`, `expired`, `cancelled`. There is **no**
`partial`, `overpaid`, `wrong_asset`, `failed`, `refunded` or `disputed` status.

```
pending ──► confirmed
   │  └───► expired
   ├──────► cancelled
expired | cancelled ──► confirmed     (late payment, only with the observed status)
```

Guarantees: a terminal order never leaves its terminal state through the normal
path; every transition is a compare-and-set in the database (so two concurrent
confirmations cannot both win); `expired` is also reported lazily by `/status`
for a stale pending row. Late confirmation requires the caller to name the
status it observed and re-verifies the transaction, and it is recorded as a
`confirmed_late` event so your ledger can distinguish it.

## 3. What "confirmed" means

At confirm time the server re-reads the receipt and requires all of:

- receipt exists and `status == 0x1`;
- token orders: a `Transfer` log with **this order's token**, **this order's
  recipient** and `amount >= expected`; native orders: `tx.to == recipient` and
  `tx.value >= amount`;
- `latest_block - tx_block + 1 >= chain.confirmations`;
- the transaction is not already used by another order.

An RPC error can never confirm anything (fail-closed). Confirmation depths come
from the chain registry and are visible in `GET /v1`: ethereum 12, bsc 15,
polygon 30, arbitrum 1, optimism 1, avalanche 1, base 1, xlayer 10, solana 1
(commitment level), tron 19.

**Post-confirmation re-check (warning only).** Each confirmed **EVM** order is
re-read once, 30 minutes to 6 hours after confirmation. If the transaction is
gone or its depth dropped, we append a `confirmation_regressed` event and set
`last_error`; the status stays `confirmed` and **no webhook is sent**, because a
merchant may already have shipped and because no one wants an integration that
can be un-paid by a notification. Solana and Tron rely on the depth taken at
confirm time. Choose depths accordingly; if you need stronger finality, wait
longer on your side before releasing value.

## 4. Matching and edge cases

An order is bound to chain + token/asset + recipient + **minimum** amount +
a time window derived from creation, and there is one recipient per merchant.

**On Solana, every order also carries its own on-chain reference.** The reference
is *derived* from the order id (`sha256`-backed, reproducible by the server, the
browser and any wallet — no stored secret), and the checkout link hands it to the
payer, who attaches it to the transaction as a read-only account. Two pending
orders for the same amount are therefore told apart on chain: a transaction that
names **another** order's reference is rejected even when the amount matches.
A payment that carries no reference at all still matches by amount (someone may
have copied the address instead of scanning the QR) — so on **EVM and Tron**,
two pending orders for the same amount and recipient remain ambiguous: use
distinct amounts or confirm explicitly when that matters.

| Case | Behaviour |
| --- | --- |
| Tx used by another order | `409 order_conflict` |
| Re-confirm same hash | `200 { idempotent: true }` |
| Wrong token / recipient / too little | `409 transaction_mismatch` |
| Overpayment | confirmed; the difference is not tracked or credited |
| Too shallow | `202 insufficient_confirmations` — keep polling |
| Payment after expiry | chain: `POST /confirm` with the hash still confirms (`late: true`); off-chain: a receipt/statement still confirms (`late: true`, `previousStatus`) — only the automatic sweep refuses to resurrect it |
| Native coins (ETH/BNB/POL…) | no transfer log to scan: stays `pending` until you `POST /confirm` with the hash |
| Off-chain receipt replayed twice | idempotent; a different receipt on the same order is `409 channel_conflict` |

## 5. Push: signed webhooks exist

```
POST <your webhookUrl>
X-AIPAY-Signature: sha256=<hex HMAC-SHA256(secret, "<timestamp>.<raw body>")>
X-AIPAY-Timestamp: <unix seconds>
X-AIPAY-Event: order.confirmed | order.expired | order.cancelled
X-AIPAY-Delivery: <delivery id, stable across retries>
X-AIPAY-Attempt: <1-based>
User-Agent: AIPAY-Webhook/1.0
```

- The signature covers `<timestamp>.<raw body>` — no scheme, no headers. Verify
  against the **raw** body bytes, then reject timestamps older than ~5 minutes.
- Events: `order.confirmed`, `order.expired` (customer never paid), and
  `order.cancelled` (you cancelled). Creation is silent.
- Retries: 60 s, 5 min, 30 min, 2 h, 6 h (6 attempts). Retried on 408/425/429/5xx
  and network errors; other 4xx are terminal.
- Duplicates: one delivery row per `(reference, event, channel, target)`, claimed
  with a compare-and-set lease before sending, so a concurrent sweep cannot send
  twice.
- Delivery log: `order.notifications[]` in the merchant view (`delivered`,
  `pending`, `failed`, `disabled` + reason) and the CSV `webhook` column.
- **There is a resend endpoint for one delivery, but no separate event stream.**
  `POST /v1/orders/:reference/notifications/:deliveryId/replay` (merchant key)
  re-sends one recorded delivery now: it keeps the same delivery id (so a
  receiver dedupes on `X-AIPAY-Delivery`), restarts that delivery's retry
  budget, and writes `notification_replayed` to the order's timeline — including
  when the replay fails again. It is limited to 10/min. There is still **no
  event stream** and no bulk replay: bulk recovery is still pull-based
  (`GET /v1/orders` + `GET /v1/orders/export.csv`).

## 6. Polling, quotas, idempotency

- Poll `GET /v1/orders/:reference/status` (no key) or the merchant list.
- The server sweeps pending orders on a backoff: 60 s, then 120 s, then every
  240 s (a Worker cron; `GET /v1/health.sweeper` reports `mode`, and `GET /v1`
  documents the push + poll contract). Worst-case discovery for a payment nobody
  reports is therefore about 4 minutes; `/confirm` (from your own watcher) and the
  payer's browser check are immediate. **30 s polling is enough**; faster polling
  only burns quota.
- Quotas: 500 orders per merchant per UTC day, **50** merchant signups per IP per
  day, 16 KiB request body, TTL 120–3600 s (default 900), 10 webhook replays per
  minute.
- Payer-facing reads are counted **per order**: 120/min for `status` and
  `receipt` (so a shared egress address — an office, a campus, a café — cannot
  spend another payer's budget), 60/min for the order list, 30/min for
  statements, 10/min for the CSV export. On top of that there is a **per-address
  ceiling** of 600/min (360/min for `confirm`) so one address cannot spray
  references; it is counted once every four requests and a refusal is remembered
  per Worker, so the ceiling is hard without a write per request. Authenticated
  callers keep one bucket per credential. `GET /v1` publishes all of this under
  `polling.limits` and `polling.payerLimits`.
- Idempotency: `merchantOrderId`, unique per merchant. Replaying the same id with
  the **same** parameters returns the original order (`200 idempotent`).
  Replaying it with a different amount/asset/chain/channel is now
  `409 merchant_order_conflict` (this was silently reusing the old order until
  2026-11-11, so check your client version notes). There is no
  `Idempotency-Key` header.

## 7. Reconciliation evidence

- `GET /v1/orders/export.csv` → RFC 4180 CSV, 19 columns:
  `reference, merchant_order_id, status, created_at, confirmed_at, amount, asset,
  decimals, amount_base_units, chain_key, token_address, channel,
  confirmed_source, channel_ref, tx_hash, block_number, confirmations, webhook,
  description`. Response headers `X-AIPAY-Rows` and `X-AIPAY-Truncated`
  (5 000 row cap). Formula-injection prefixes are neutralised.
- Every state change appends to an `order_events` audit trail (`created`,
  `channel_selected`, `confirmed`, `confirmed_late`, `expired`, `cancelled`,
  `channel_confirmed`, `channel_conflict`, `statement_matched`).
- References are stable; terminal orders are purged 90 days after creation
  (`/v1` reports `retentionDays`).

## 8. What is genuinely missing (read before designing around it)

1. **No refunds, reversals, chargebacks or disputes.** No endpoint, no state. You
   refund from your own wallet and record it in your own ledger; AIPAY cannot
   move or claw back funds.
2. **Reorg handling is a warning, not a rollback** (see §3): a regressed
   confirmation is recorded for EVM only and never changes the order.
3. **No event stream and no bulk replay** (§5). One delivery can be re-sent on
   demand; a whole day of deliveries cannot.
4. **No sandbox or test mode that cannot receive real funds.** Every accepted
   chain is mainnet. To rehearse: run the Worker locally (`wrangler dev` with
   `RPC_OVERRIDES`, see §11 of `merchant-order-service.md`) and drive it with the
   copy-paste clients in the source repository
   (`examples/merchant-node/aipay.mjs`, `examples/merchant-python/aipay.py`), or
   create a deliberately small live order on a cheap chain and refund it from
   your wallet.
5. **No SLA / uptime commitment and no status page.**
6. **One API key = full merchant scope**, no scopes, no 2FA on the recipient
   address change (the docs state this as a residual risk; treat the key like a
   wallet-level secret and rotate with `POST /v1/merchants/me/keys/rotate`).
7. **No documented read-side rate limit** (order and signup quotas only).
8. **No per-order deposit address** (§4), so amount+recipient matching is the
   only routing signal.
9. **No partial payments / overpayment credit** (§4).

## 9. How this maps onto your own settlement rules

Your assessment already requires an authoritative internal ledger and forbids
crediting spendable value from an unverified notification. AIPAY fits that model
if you treat it as **evidence**, not as a wallet:

1. Create the order with **your** `merchantOrderId` = your business reference;
   persist `reference` ↔ your order **before** the customer pays.
2. Credit only on a verified signal: a `confirmed` webhook whose signature,
   timestamp and `reference` you checked, or a `GET /v1/orders/:reference`
   response re-read at least twice with the same terminal state.
3. Never mint on `order.expired`, `order.cancelled`, or on a 202/insufficient
   confirmations answer. Late payments arrive as `confirmed` with a
   `confirmed_late` event — decide explicitly whether to honour them.
4. Keep your own state machine (`received` → `credited` → `held` → `settled`);
   AIPAY's `confirmed` is a receipt, not match finality, and not permission to
   sell a regulated product.
5. Reconcile daily with `export.csv` against your ledger; anything unexplained
   stays open on your side and is resolved by `reference`, never by creating a
   replacement order.

## 10. Question-by-question index

1. **Production provider or agent tool?** Both: a merchant HTTP API (this
   document) and a payer-side agent surface. Jurisdictions/customer types: we do
   not restrict or vet them today; we also do not collect or transmit fiat, and
   MSGChain payouts are disabled. Legal/AML/sanctions obligations of the product
   you sell are yours — we do not claim to cover them.
2. **Fiat?** No fiat collection. On-chain assets only, per chain:
   ETH/USDT/USDC/DAI (ethereum), BNB/USDT/USDC/BUSD (bsc), POL/USDT/USDC
   (polygon), ETH/USDT/USDC/ARB (arbitrum), ETH/USDT/USDC/OP (optimism),
   AVAX/USDT/USDC (avalanche), ETH/USDC (base), OKB/USDT/USDC (xlayer),
   SOL/USDT/USDC (solana), TRX/USDT-TRC20 (tron). Decimals come from the
   registry; anything else is `400 unknown_asset`.
3. **State machine?** §2. A confirmed order never reverts in the API.
4. **Depth/finality, reorgs, matching uniqueness?** §3 and §4.
5. **Signed webhooks, rotation, replay, retries, SLA, recovery?** §5. Key
   rotation exists (`POST /v1/merchants/me/keys/rotate`); the webhook secret is
   returned once at signup and can be re-issued with `POST
   /v1/channels/:id/secret` for channel receipts only.
6. **What makes an order confirmed?** Receipt + transfer + depth, re-read from an
   RPC at confirm time; independently reproducible with the `tx_hash` and
   `block_number` recorded on the order.
7. **Refunds?** Not implemented (§8.1).
8. **Custody, recipient change, MFA?** Non-custodial; recipient changes with the
   API key, no second factor, no delay; address changes never rewrite existing
   orders (each order snapshots its recipient). Keys are hashed at rest; the
   dashboard keeps your key in `localStorage`, so use the CLI/API from a trusted
   machine for production keys.
9. **Fees, limits, availability, retention, sandbox?** Zero commission;
   `billing.status = "free"` and paid plans are **not on sale** (no start date);
   limits in §6; retention 90 days; no sandbox (§8.4); no SLA (§8.5).
10. **Export/replay and outstanding links?** §7. A single delivery can be re-sent
    with `POST /v1/orders/:reference/notifications/:deliveryId/replay` (§5); there
    is no bulk replay and no event stream. Old checkout links keep rendering;
    after expiry they show `expired` and cannot confirm except through an
    explicit late `confirm`. Deleting the merchant hard-deletes orders, events,
    deliveries and keys, so export first.

## 11. What we changed because of this assessment (2026-11-11)

- `GET /v1` now publishes the notification contract (headers, canonical signed
  string, events, retry schedule, duplicate protection) and a polling block with
  a recommended interval, so an agent reading discovery cannot conclude "no push
  mechanism".
- Replaying `merchantOrderId` with different parameters is now
  `409 merchant_order_conflict` instead of silently returning the old order
  (the docs already promised this behaviour).
- `order.cancelled` is documented, listed in `agent.json`, and no longer reported
  as "order expired" in webhook/email text.
- Doc drift fixed: the 24-hour Solana TTL claim, the "Solana cloud verification
  unsupported" claim, and the "in-request sweep, not a cron" limitation.

### 2026-11-15 → 2026-11-18 (what this document now says that it did not before)

- **Solana orders carry a per-order on-chain reference** (derived from the order
  id, no stored secret) and the server rejects a transaction that names another
  order's reference, even when the amount matches. Before this, two pending
  Solana orders for the same amount were ambiguous (§4).
- **A webhook delivery can be re-sent** with
  `POST /v1/orders/:reference/notifications/:deliveryId/replay` (§5). Before
  this, recovery was pull-only.
- **Payer reads are counted per order** with a per-address ceiling on top (§6).
  Before this, every anonymous caller on one address shared one bucket, which
  made a shared network look like a scraper and refused checkout pages.
- **One transaction can no longer confirm two orders.** The uniqueness check
  used to be a read followed by a write, so two concurrent confirmations of the
  same transfer could both succeed; it is now decided inside the write itself.
- **A receipt without a status is no longer treated as a success**, and the
  server now checks that the node answered about the transaction it asked for.
- Two public pages were added for the questions this document answers:
  <https://aipay.im/trust> (what we never touch, and how to check the rest) and
  <https://aipay.im/pricing> (the limits the service actually enforces).
  <https://aipay.im/developers> lists every developer surface in one place.

If something you need is not in this document, ask for it by endpoint name — the
API is small enough that a concrete gap can usually be answered with a test.
