# How to keep proof of purchase when your AI agent pays, by rail

Bought by Agents desk. A ZeroClick publication (https://boughtbyagents.com/about/). Published 2026-12-01.
Format: Guide. Topic: Paying (https://boughtbyagents.com/topics/paying/).
Canonical: https://boughtbyagents.com/articles/how-to-keep-proof-of-purchase-when-your-ai-agent-pays-rail-by-rail/

When a person buys something online, the checkout page and the emailed receipt leave a trail that finance, support and the bank can all follow. When an agent pays, nobody sees a page and nobody gets an email. Whatever proof the purchase leaves comes back in the agent's response at that moment, or it sits with the seller's payment processor.

Each rail, the route a payment takes, returns something different. x402 and MPP both let a server ask for payment in an HTTP 402 response. An x402 server sends a settlement response in a header. An MPP server may send a receipt, which its own documentation calls optional. For a card paid through a Stripe shared payment token, Stripe's page describes webhook events sent to the seller and the agent, and names no receipt for the agent. AP2, the Agent Payments Protocol, adds signed mandates that show what the user authorized, and receipts that record whether the merchant and processor accepted them.

The job is to have the agent write one record per purchase from whatever its rail sends back. With that record the spend can be proved, matched to the call it paid for, and disputed. It needs two things first. The agent's raw HTTP responses must be readable, headers included. On the card route you need a Stripe account, because that is where the card record lives.

## What to keep

Keep the rail's own reference beside the request it paid for, both decoded and raw, and treat a missing receipt as unknown, never as failed.

A reference such as a transaction hash or a Stripe PaymentIntent ID points to a record that the network or processor holds. A receipt the agent writes for itself cannot do that. MPP's documentation lists the uses: logging payment confirmations, linking reference IDs to payment network records in a dispute, and matching payments to requests. The rails already produce the reference, so the work is making sure the agent doesn't lose it.

## What each rail sends back

| Rail | What comes back | When | ID it carries | Where the ID is looked up | On failure |
|---|---|---|---|---|---|
| x402 | [`PAYMENT-RESPONSE` header, Base64 JSON](https://docs.x402.org/core-concepts/http-402) | After the server attempts settlement | `transaction` hash, with `network` | The chain named in `network` | The same header, with `success: false` and an `errorReason`; a hash on `settlement_pending` |
| MPP | [`Payment-Receipt` header, base64url JSON](https://mpp.dev/protocol/receipts) | On successful responses, optional per MPP's docs | `reference` | The payment network, or Stripe for `stripe/charge` | No receipt; a 402 with a fresh challenge |
| Card via shared payment token | [Stripe webhook events](https://docs.stripe.com/agentic-commerce/concepts/shared-payment-tokens) | When the token is used, resolved or revoked | Token ID (`spt_...`); the seller holds the PaymentIntent | The seller's Stripe account | Events only; no agent receipt is described |
| AP2 | [Signed checkout and payment receipts](https://ap2-protocol.org/) | After the merchant and processor accept or reject the mandates | `order_id`, `payment_id`, PSP and network confirmation IDs | Merchant, PSP and network | Receipts with an error status and code |

## x402: read PAYMENT-RESPONSE on success and on failure

An x402 server returns `PAYMENT-RESPONSE` after it attempts settlement, whether settlement succeeded or failed. The value is Base64-encoded JSON. Here are a decoded success and a decoded failure, as given in the [x402 V2 specification](https://github.com/x402-foundation/x402/blob/main/specs/x402-specification-v2.md):

```json
{
  "success": true,
  "payer": "0x857b06519E91e3A54538791bDbb0E22373e36b66",
  "transaction": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
  "network": "eip155:84532"
}
```

```json
{
  "success": false,
  "errorReason": "insufficient_funds",
  "payer": "0x857b06519E91e3A54538791bDbb0E22373e36b66",
  "transaction": "",
  "network": "eip155:84532"
}
```

The object can also carry `errorMessage`, an optional settled `amount`, and `extensions`. The spec tells clients to match on the `errorReason` code and never on the message text, which can change between facilitators.

Two cases matter most for the record:

- **`settlement_pending`.** The transaction was broadcast but its confirmation was not observed, and it may still confirm. The spec requires this response to carry the hash. Coinbase's [reconciliation guidance](https://docs.cdp.coinbase.com/x402/seller/settlement-pending) says not to create another payment until that transaction is reconciled, because doing so can charge the buyer twice.
- **Batch settlement.** Under this scheme, x402's docs say the payment authorization is confirmed up front and value is redeemed onchain later, so a recorded success comes before the money moves.

## MPP: read Payment-Receipt when it arrives

MPP sends `Payment-Receipt` on successful responses. It is base64url-encoded JSON, not plain Base64, so it needs its own decoder. Decoded, per MPP's docs, it looks like this:

```json
{
  "method": "tempo",
  "reference": "0x789abc...",
  "status": "success",
  "timestamp": "2025-01-15T12:00:00Z"
}
```

What `reference` holds depends on the method:

- a transaction hash for `tempo/charge`
- a PaymentIntent ID for `stripe/charge`
- a channel ID for `tempo/session`

An optional `externalId` echoes a reference from the agent's own credential.

The sources differ on how dependable the receipt is. MPP's docs call the header optional and say a client works correctly without it. The [Payment authentication draft](https://datatracker.ietf.org/doc/html/draft-httpauth-payment-01) is an individual Internet-Draft with no formal standing at the IETF. It says servers SHOULD include the receipt on success and MUST NOT include it on errors. Under the draft, a failed payment comes back as a 402 with a fresh challenge and a problem-details body. Either way, a 200 with no receipt is a gap in the record, not evidence that the payment failed.

## Build the capture

1. Before paying, save the request (method and URL) and the terms the agent accepted: amount, payee, network and, on MPP, the challenge `id`.
2. When the paid response arrives, read `PAYMENT-RESPONSE` or `Payment-Receipt`.
3. Decode it with the matching decoder: Base64 for x402, base64url for MPP.
4. Store the decoded object and the raw header beside the request, under one purchase key.
   - Where the seller supports it, send an `Idempotency-Key` header.
   - On x402, you can instead use the [Payment-Identifier extension](https://docs.x402.org/extensions/overview), which attaches a unique ID to each payment for tracking, reconciliation and idempotency.
5. On an error, store the error code, not just a failed flag. If a transaction hash came back, look it up on the named network before paying again.

The MPP draft treats `Payment-Receipt` headers as sensitive data and bars servers and intermediaries from logging payment credentials. So the record keeps the receipt and leaves out the credential the agent sent.

## The record, on every rail

Each purchase record holds:

- the rail
- the reference
- the network
- the amount and currency
- the payee
- the request it paid for
- the time
- the outcome, including any error code

On x402, the settlement response's `amount` is optional. Take the amount and payee from the payment requirements the agent accepted, and the time from the agent's own clock. MPP's receipt supplies its own `timestamp`.

Some x402 sellers run the optional [Signed Offers & Receipts extension](https://docs.x402.org/extensions/offer-receipt.md). If yours does, keep the signed receipt too. It arrives only on success, inside the header's `extensions` field, and by default it leaves out the transaction hash.

## Cards: the record lives with Stripe

A shared payment token grants a seller scoped use of a customer's payment method. It is a Stripe feature in public preview in the US, Canada and select European countries. The seller charges the token by creating a PaymentIntent.

Stripe sends webhook events to both the seller and the agent when the token is used to accept a payment, resolved for a third-party processor, or revoked. A `shared_payment.granted_token.deactivated` event covers a token that was consumed, resolved, expired or revoked. Stripe's page describes no receipt for the agent.

So the agent's record holds the token ID it granted and the events it received. On the seller's side, later events on the charge, such as refunds and reporting, behave as if the seller had provided the customer's payment method directly.

## AP2: proof of authority, not of payment

AP2 adds what the other rails lack: signed evidence of what the user authorized.

- A closed [checkout mandate](https://ap2-protocol.org/ap2/checkout_mandate/) binds a hash of the merchant-signed checkout.
- The closed [payment mandate](https://ap2-protocol.org/ap2/payment_mandate/) carries that hash as `transaction_id`, along with the payee, the amount and the payment instrument.

After the purchase, two receipts come back:

- The merchant returns a checkout receipt, with an `order_id` on success.
- The processor returns a payment receipt, with a `payment_id` and, on success, payment service provider (PSP) and network confirmation IDs.

Each receipt carries a success or error status, and the [specification](https://ap2-protocol.org/ap2/specification/) has both returned to the shopping agent. Together, the mandates and receipts give dispute evidence of what the user and each party saw.

The mandates do not move money. The credential provider and processor do, so the confirmation IDs are the record's link to the payment itself. The initial version of AP2 supports cards. The spec leaves retention and retrieval out of scope.

## When this is the wrong approach

All of this assumes the agent can see its payment responses. Sometimes it can't: its payments may run through a tool that doesn't hand back headers, or a person may complete a hosted checkout. In those cases the record has to come from the seller's processor.

## Where to start

Add the decoder and the record writer at the point where the agent reads its paid responses, beginning with the rail it pays on most.

Then test the failure path first: a stalled x402 settlement and an MPP 402. That is where a duplicate payment or a missing proof starts. Two cases no header will cover, a card charge and a 200 with no receipt, are the ones to check with the seller.

## Frequently asked questions

### What does an agent get back after paying an x402 endpoint?

It gets a `PAYMENT-RESPONSE` header holding Base64-encoded JSON, with `success`, `transaction`, `network` and, on failure, an `errorReason`. The server sends this header whether settlement succeeded or failed.

### Is the MPP Payment-Receipt header required?

No. MPP's documentation calls `Payment-Receipt` optional, and the individual IETF draft behind MPP says servers SHOULD send it on success and MUST NOT send it on errors. A successful response without one is a gap in the record, not proof that the payment failed.

### Does the agent get a receipt when a seller charges a Stripe shared payment token?

Stripe's documentation describes webhook events sent to the agent and the seller when the token is used, resolved or revoked, and names no receipt for the agent. The seller's PaymentIntent holds the charge record.

### Does an AP2 mandate prove the payment went through?

No. AP2 mandates prove what the user authorized, and the credential provider and processor carry out the payment. The payment receipt's PSP and network confirmation IDs are what link the purchase to the payment itself.

### How do I match an agent payment to the API call it paid for?

Store the rail's reference, such as an x402 transaction hash or an MPP receipt `reference`, under the same purchase key as the request's method and URL. Where the seller supports it, add an `Idempotency-Key` header or x402's Payment-Identifier extension so that retries map to one payment.
