> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sapiom.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Sapiom Pay is for platforms whose agent shops for many end users. Each end user is a buyer with their own Sapiom key and saved cards.
> Use the buyer's key for every call made on that buyer's behalf. Never use one buyer's key for another user, and never give the agent the platform key.
> Backends call the REST API at https://api.sapiom.ai/v1. Agents can also call the hosted MCP tools at https://api.sapiom.ai/v1/mcp/pay. Both take the key in an x-api-key header.
> Keys that start with sk_test_ reach the sandbox, a separate test environment with its own buyers and cards, at the same addresses. Use test card numbers only there.
> Never ask a buyer for a card number, expiry date or CVV in chat. Buyers enter card details only on Sapiom's hosted pages.
> Check the merchant before buying. Use purchase.type ucp_checkout only when the merchant check returns supported. Otherwise use browser_checkout.
> Follow the nextAction in each transaction result. Action links are secrets for the intended buyer only.
> Use one idempotency key per transaction. Resume an unanswered create with the same request and key. If a UCP update or cancellation is uncertain, stop and hand off to a person. If a browser cancellation is uncertain, read the transaction and resend the same cancellation, with the same key, only if it is not closed. Never start a new transaction to escape an uncertain outcome.
> For a ucp_checkout purchase, report an order as placed only when order.outcome is confirmed; if it is unknown, stop and hand off to a person. A browser_checkout purchase has no order confirmation (order is null): confirm the order on the merchant's page.

# How Sapiom Pay works

> Who does what in a Sapiom Pay transaction, why Sapiom needs checkout details before releasing a card, and how the real card reaches checkout.

Six parties take part in a transaction. The real card number only ever passes between Sapiom and the merchant's payment processor.

## Who does what

| Party | Role |
| - | - |
| Your backend | Creates a buyer and buyer key for each user, stores the keys, and refreshes checkouts when asked. |
| Your agent | Shops for one buyer at a time, using that buyer's key. |
| Buyer | Your user. Saves a card once, then approves each transaction. |
| Browser session | Your code that runs the merchant's checkout in a browser, with [Browser Pay](https://docs.sapiom.ai/transactions/browser-pay) attached. |
| Sapiom | Stores each buyer's cards, checks each transaction, and sends the real card to checkout. |
| Merchant | Sets prices and totals, and owns the order. |

Each buyer's cards and transactions are visible only with that buyer's key.

## A transaction

<ol>
  <li>
    1

    Request
    Your agent sends what it's buying and a card ID.

    `transactionId`
  </li>

  <li>
    2

    Follow nextAction
    Act on each result until it's ready to pay.
    ↻ Repeats: wait, security code, approval

    `nextAction`
  </li>

  <li>
    3

    Pay
    Browser Pay swaps the placeholder for the real card.

    `payment_ready`
  </li>

  <li>
    4

    Confirm the order
    Get the merchant's confirmation.

    `payment_submitted`
  </li>
</ol>

Cancel until your agent pays
`POST …/cancel`

1. **Request.** You send what's being bought and the buyer's card ID. For a UCP merchant, that's the merchant's checkout, and Sapiom opens it with the merchant. For any other merchant, it's the total and items your agent read from the checkout page.
2. **Follow `nextAction`.** Sapiom checks your spending limits and approval rules, and the buyer approves on a hosted page. Act on each `nextAction` until the transaction is `payment_ready`.
3. **Pay.** Your browser session fills checkout with a placeholder. Browser Pay relays it, and Sapiom sends the real card to the merchant's payment processor.
4. **Confirm the order.** The transaction then reads `payment_submitted`. For a UCP merchant, your backend refreshes the checkout to get the merchant's confirmation. Otherwise, confirm the order on the merchant's page.

Until your agent pays, it can [cancel the transaction](https://docs.sapiom.ai/transactions/authorize.md#change-or-cancel-a-transaction).

## Why Sapiom needs checkout details first

Sapiom releases a card only for a specific checkout. Before paying, it knows the merchant, items, total and currency. That lets Sapiom:

* check the transaction against your limits
* show the buyer exactly what they are approving
* tie the placeholder card to that one transaction
* return the decision and its reasons with each transaction

## Checkout paths

Whether the merchant supports the Universal Commerce Protocol (UCP) decides how a transaction runs.

With Browser PayThe buyer's saved card pays.

UCP merchant `ucp_checkout`The merchant's checkout states the items and total.

Rules

Buyer CVV

Agent pays

Any other merchant `browser_checkout`Your agent states what it's buying.

Agent states

Rules

Buyer CVV

Agent pays

| | UCP merchant | Any other merchant |
| - | - | - |
| Items and total | Stated by the merchant's checkout | Your agent. Sapiom doesn't check them. |
| Payment | Your browser worker opens `nextAction.continueUrl` and fills the placeholder. Browser Pay relays it. | Your browser worker fills the placeholder on the checkout page it is on. Browser Pay relays it. |
| Order confirmation | `order.outcome` from the merchant's checkout | None (`order` is `null`). Check the merchant's page. |


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