# Authorize agent payments

Carry a person's authorization into AP2, x402 and ACP agent payments, as a claim on AP2 Checkout and Payment Mandates, an x402 v2 payment extension or an ACP checkout extension, and verify it at the merchant.

Use `@provenanceauth/rails` to carry a person's authorization into the agent-payment protocols. A [grant](https://provenanceauth.com/docs/mandate/concepts/grants.md) becomes AP2 open Payment Mandate content or an ACP payment allowance. An intent token travels on AP2 Checkout and Payment Mandates, in an x402 payment's `extensions` or on the ACP checkout completion, where the merchant verifies it. Provenance verifies the authorization; your payment provider moves the money.

**Before you begin:** export the sandbox account key and install the rails package.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

**This package isn't on npm yet.** Until then, every request in these docs runs over HTTP against the [sandbox](https://provenanceauth.com/docs/get-started/sandbox.md).

With access to the private Provenance repository, which your Provenance contact grants, install from it:

```bash
git clone https://github.com/michaelnbane-jpg/provenance.git provenance
cd provenance && pnpm install && pnpm build
node scripts/check-publishable.mjs --out ../provenance-packs
cd ../your-project
npm install ../provenance-packs/provenanceauth-sdk-1.0.0.tgz ../provenance-packs/provenanceauth-rails-1.0.0.tgz
```

**Limitations:** the AP2 mapping maps to AP2 0.2, exported as `AP2_SPEC_VERSION`. AP2 mandates are SD-JWTs signed by a Trusted Surface the verifier trusts. Provenance can be that surface after a passkey approval (see [Issue AP2 mandates](https://provenanceauth.com/docs/mandate/guides/issue-ap2-mandates.md)); otherwise your own Trusted Surface signs, with Provenance's content and intent token inside. The x402 mapping maps to x402 v2, exported as `X402_VERSION`. The ACP mapping maps to ACP 2026-04-17, exported as `ACP_SPEC_VERSION`.

## 1. Give the agent a grant

A grant is a person's standing, bounded authority for an agent: a per-payment limit, a monthly budget and allowed merchants. Grant it with [`POST /v1/mandate/grants`](https://provenanceauth.com/docs/api/grants.md#post-v1-mandate-grants):

**curl**

```bash
curl -s $PROVENANCE_API/v1/mandate/grants \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "device_id": "dev_00000000000000000000000000000001",
    "agent_session_id": "sess_buyer_1",
    "constraints": {
      "max_amount": 200,
      "budget_amount": 500,
      "budget_window": "month",
      "allowed_action_types": ["payment"],
      "allowed_counterparties": ["merchant_acme"],
      "expires_at": "2027-12-31T23:59:59Z"
    }
  }' | tee mandate.json
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const mandate = await prov.mandate.grants.create({
  deviceId: "dev_00000000000000000000000000000001",
  agentSessionId: "sess_buyer_1",
  constraints: {
    maxAmount: 200,
    budgetAmount: 500,
    budgetWindow: "month",
    allowedActionTypes: ["payment"],
    allowedCounterparties: ["merchant_acme"],
    expiresAt: "2027-12-31T23:59:59Z",
  },
});
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
mandate = prov.mandate.grants.create(
    device_id="dev_00000000000000000000000000000001",
    agent_session_id="sess_buyer_1",
    constraints={
        "max_amount": 200,
        "budget_amount": 500,
        "budget_window": "month",
        "allowed_action_types": ["payment"],
        "allowed_counterparties": ["merchant_acme"],
        "expires_at": "2027-12-31T23:59:59Z",
    },
)
```

The response, trimmed:

```json
{
  "id": "grt_01M5Q2QMTMZK4271Z95VG4RCDN",
  "object": "grant",
  "status": "active",
  "agent_session_id": "sess_buyer_1",
  "remaining_budget": 500,
  "expires_at": "2027-12-31T23:59:59Z",
  "mandate_token": "eyJhbGciOiJFUzI1NiIsInR5cCI6Im1hbmRhdGUrand0Iiwia2lkIjoiNzUyNjk2ZmYwZjVlNGY1MyJ9.eyJpc3MiOiJwcm92ZW5hbmNlLWF1dGhvcml6ZSJ9.HBZ1gq7tZyq7p7KhKbGDj3Rrcn9DRckwHHvkF7B-L7plT84vCNY1BVBAKlAv5Y8LywQwU0I3rxTBG3qQCk0bCQ"
}
```

## 2. Map the grant to an AP2 open Payment Mandate

AP2 0.2 authorizes a purchase with two mandates: a Checkout Mandate for what is bought and a Payment Mandate for how it is paid. When the agent shops on its own, the person approves open mandates that set limits, and the agent closes them for each purchase.

`provenanceMandateToAp2OpenPayment` turns the grant into open Payment Mandate content (`mandate.payment.open.1`). AP2 binds an open mandate to the agent's public key, so pass it as `agentKey`. Allowed merchants need a name in AP2, so pass them as `payees`. `ap2OpenPaymentToProvenance` maps the content back.

**Node**

```ts
import { provenanceMandateToAp2OpenPayment } from "@provenanceauth/rails/ap2";

const { mandate: openPayment, not_mapped } = provenanceMandateToAp2OpenPayment(
  { mandate_id: mandate.id, agent_session_id: "sess_buyer_1", constraints: { max_amount: 200, budget_amount: 500, budget_window: "month", allowed_counterparties: ["merchant_acme"], expires_at: "2027-12-31T23:59:59Z" }, mandate_token: mandate.mandateToken },
  {
    currency: "usd",
    agentKey, // the agent's P-256 public JWK
    payees: [{ id: "merchant_acme", name: "Acme", website: "https://acme.example" }],
    checkoutReference, // the open Checkout Mandate's digest, once the agent has it
  },
);
// Your Trusted Surface shows openPayment to the person and signs it as an SD-JWT.
```

The content, trimmed:

```json
{
  "vct": "mandate.payment.open.1",
  "constraints": [
    { "type": "payment.amount_range", "currency": "USD", "max": 20000 },
    { "type": "payment.allowed_payees", "allowed": [{ "id": "merchant_acme", "name": "Acme", "website": "https://acme.example" }] },
    { "type": "payment.reference", "conditional_transaction_id": "FzLoxbbtgQGYZxoSM2NJYJtkFTSsdfUBoVEQ12k7JN8" }
  ],
  "cnf": { "jwk": { "kty": "EC", "crv": "P-256", "x": "QpSyxPQHy38xckyvDr54gZ3T42zj9iLtV4koyb5U27c", "y": "37HLd7JJinxjJIn8J7HijssoecBlfhdW-gUL7feI9lw" } },
  "exp": 1830297599,
  "com.provenanceauth.mandate": { "token": "eyJhbGciOiJFUzI1NiIs..." }
}
```

The fields map like this:

| Provenance | AP2 0.2 |
| --- | --- |
| `constraints.max_amount` | `payment.amount_range` `max`, in minor units for the currency |
| `constraints.allowed_counterparties` | `payment.allowed_payees` `allowed`, as merchant objects with the same ids |
| `constraints.expires_at` | `exp` |
| `mandate_token` | The `com.provenanceauth.mandate` claim, which AP2 carries unchanged into the closed mandate |

The grant's budget stays with Provenance, which enforces it each time the agent authorizes. AP2's `payment.budget` caps the total over an open mandate's whole life, while a Provenance budget renews each day, week or month, so `not_mapped` lists it.

## 3. Put the intent token on AP2 mandates

The merchant signs a Checkout JWT for the cart. Authorize with `ap2BindingPayload` as the action payload, so the token binds the Checkout's hash, the payee and the amount. Then attach the token to the closed Checkout Mandate (`mandate.checkout.1`) and Payment Mandate (`mandate.payment.1`) content, in a `com.provenanceauth.intent` claim.

**Node**

```ts
import { ap2BindingPayload, ap2CheckoutMandateContent, ap2PaymentMandateContent } from "@provenanceauth/rails/ap2";

const payee = { id: "merchant_acme", name: "Acme", website: "https://acme.example" };
const payment_amount = { amount: 19900, currency: "USD" };
const auth = await prov.mandate.intents.create({
  actionDescription: "Buy SuperShoe Limited Edition Gold for $199.00 at Acme",
  actionPayload: ap2BindingPayload({ checkout_jwt: checkoutJwt, payee, payment_amount }),
  agentSessionId: "sess_buyer_1",
  deviceId: "dev_00000000000000000000000000000001",
  mandateToken: mandate.mandateToken,
});

const jwksUrl = `${process.env.PROVENANCE_API}/.well-known/jwks.json`;
const checkoutMandate = ap2CheckoutMandateContent(checkoutJwt, auth.intentToken, { jwksUrl });
const paymentMandate = ap2PaymentMandateContent(
  { checkout_jwt: checkoutJwt, payee, payment_amount, payment_instrument: { id: "pi_1", type: "card", description: "Card 4242" } },
  auth.intentToken,
  { mandateToken: mandate.mandateToken },
);
// Sign both with your Trusted Surface (the person is present) or the agent's key (an open mandate).
```

The closed Checkout Mandate content, trimmed:

```json
{
  "vct": "mandate.checkout.1",
  "checkout_jwt": "eyJhbGciOiAiRVMyNTYiLCAidHlwIjogIkpXVCIs...",
  "checkout_hash": "NivWhuqfzcvZNapvIEJ2-3tsdQLkiuIcye2g46WVgX8",
  "com.provenanceauth.intent": { "token": "eyJhbGciOiJFUzI1NiIs...", "jwks_url": "https://sandbox-api.provenanceauth.com/.well-known/jwks.json" }
}
```

| Provenance | AP2 0.2 |
| --- | --- |
| The intent token | The `com.provenanceauth.intent` claim on the closed Checkout and Payment Mandates |
| The issuer's published keys URL | `com.provenanceauth.intent.jwks_url`, a hint |
| The token's `payload_hash` | The Checkout's `checkout_hash` (the Payment Mandate's `transaction_id`), the payee id, the amount in minor units and the currency |

## 4. Verify an AP2 mandate at the merchant

Your AP2 stack verifies the mandate's SD-JWT signature and key binding. Pass the content it returns to `verifyAp2Mandate`, with `expected` built from the Checkout you signed. It recomputes `checkout_hash`, checks your facts, evaluates any open mandates the agent presented, and checks the token against the issuer's published keys and its binding. Pass `onlineStatus` to also check revocation. The same call verifies a Payment Mandate at the credential provider.

**Node**

```ts
import { ap2ReceiptClaims, verifyAp2Mandate } from "@provenanceauth/rails/ap2";
import { publicVerify } from "@provenanceauth/rails/checkout";
import { fetchJwks } from "@provenanceauth/sdk";

const issuer = process.env.PROVENANCE_API!;
const jwks = await fetchJwks(issuer);

const result = await verifyAp2Mandate(checkoutMandateContent, {
  jwks,
  expected: { checkout_jwt: myCheckoutJwt, payee_id: "merchant_acme", amount: 19900, currency: "usd" },
  open: openCheckoutMandates, // when the agent shops on its own
  onlineStatus: publicVerify(issuer),
});
if (result.hand_back) {
  // AP2 unresolved_constraint: ask the agent for a mandate the person approved directly.
}
const receipt = ap2ReceiptClaims(result, { iss: "https://acme.example", reference: mandateHash, order_id });
// Sign the receipt with your key and return it to the agent.
```

`result.ap2_error` is the AP2 error code for your receipt:

| `result.reason` | `ap2_error` | Means |
| --- | --- | --- |
| `checkout_hash_mismatch` | `invalid_mandate` | `checkout_hash` isn't the hash of `checkout_jwt` |
| `checkout_mismatch`, `payment_mismatch` | `invalid_mandate` | The Checkout, payee, amount or currency differs from your own |
| `constraint_failed` | `invalid_mandate` | The closed mandate breaks an open mandate's limit, such as the amount range or allowed payees |
| `claim_changed` | `invalid_mandate` | A claim of the open mandate changed in the closed one |
| `unresolved_constraint` | `unresolved_constraint` | An open mandate has a constraint this check can't evaluate, such as `payment.budget`, which needs the mandate's spending history |
| `no_intent` | `unresolved_constraint` | The mandate carries no intent token |
| `token_expired`, `token_invalid`, `token_revoked` | `invalid_credential` | The intent token is past its expiry, didn't verify against the published keys, or was revoked |
| `payload_unbound`, `payload_hash_mismatch` | `invalid_mandate` | The token binds no payload, or a different Checkout or payment |
| `unsupported_mandate` | `mandates_not_supported` | The `vct` isn't a mandate type of AP2 0.2 |

**Mandates Provenance signed.** An agent can present closed Checkout and Payment Mandates Provenance signed after a passkey approval. Verify the whole SD-JWT with `verifyAp2UserMandate`, listing Provenance's AP2 keys (`/.well-known/ap2/jwks.json`) as an issuer, or add that URL to `external_confirmations.ap2_issuers` on your agent policy. See [Issue AP2 mandates](https://provenanceauth.com/docs/mandate/guides/issue-ap2-mandates.md).

`hand_back: true` comes with `unresolved_constraint`. AP2 uses it to bring the person back: the agent asks them to approve this exact Checkout, authorizes a new intent token bound to it, and presents mandates they approved directly.

## 5. Ask for an intent in the 402

The x402 mapping maps to x402 v2. The payment scheme (`exact`, `upto` and others) stays the payment, and your facilitator verifies and settles it. The intent token travels beside it, in an x402 extension named `com.provenanceauth.intent`.

On the merchant's side, add the extension to the `PaymentRequired` you already send. `x402Challenge` builds the 402 from your own payment requirements and sets the base64 `PAYMENT-REQUIRED` header. `withIntentExtension` adds the extension to a `PaymentRequired` your x402 server builds.

**Node**

```ts
import { x402Challenge } from "@provenanceauth/rails/x402";

const accepts = [{
  scheme: "exact",
  network: "eip155:84532",
  amount: "25000000",
  asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
  payTo: "0x209693Bc6afc0C5328bA36FaF03C514EF312287C",
  maxTimeoutSeconds: 60,
}];
const resource = { url: "https://merchant.example/reports/q3", description: "Q3 report" };
const challenge = x402Challenge({ resource, accepts });
// new Response("{}", { status: challenge.status, headers: challenge.headers })
```

The decoded header carries the extension next to your payment requirements, trimmed:

```json
{
  "x402Version": 2,
  "resource": { "url": "https://merchant.example/reports/q3", "description": "Q3 report" },
  "accepts": [{ "scheme": "exact", "network": "eip155:84532", "amount": "25000000" }],
  "extensions": {
    "com.provenanceauth.intent": {
      "info": { "required": true },
      "schema": { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object" }
    }
  }
}
```

Pass `required: false` to let clients without Provenance pay as usual.

To tell agents your rules in the same answer, pass `profile: discoveryFields(profile).x402.profile`. The extension's `info.profile` then carries the amount above which a person approves, your selling agent and its key ids, and `profile_url`; an older client ignores it ([Be findable by agents](https://provenanceauth.com/docs/authorize/guides/be-findable-by-agents.md)).

## 6. Pay with x402 from the agent

On the agent's side, wrap `fetch` with `intentPaymentFetch`. It acts only on a `402` whose `PAYMENT-REQUIRED` header lists the extension. Any other `402` comes back to you unchanged.

- `getToken` authorizes under the grant, with the payment's facts as the action payload, so the token binds this resource, amount, asset, network and recipient.
- `createPayment` builds the signed payment with your x402 client.

The wrapper appends the token to the extension's `info`, keeps the merchant's `info` as sent, and retries once with the `PAYMENT-SIGNATURE` header.

**Node**

```ts
import { intentPaymentFetch, x402BindingPayload } from "@provenanceauth/rails/x402";

const payingFetch = intentPaymentFetch(
  fetch,
  async ({ paymentRequired }) => {
    const [requirements] = paymentRequired.accepts;
    const auth = await prov.mandate.intents.create({
      actionDescription: `Pay for ${paymentRequired.resource.url}`,
      actionPayload: x402BindingPayload(paymentRequired.resource, requirements),
      agentSessionId: "sess_buyer_1",
      deviceId: "dev_00000000000000000000000000000001",
      mandateToken: mandate.mandateToken,
    });
    return auth.intentToken;
  },
  {
    createPayment: ({ paymentRequired }) => x402Client.createPaymentPayload(paymentRequired),
    jwksUrl: `${process.env.PROVENANCE_API}/.well-known/jwks.json`,
  },
);
const report = await payingFetch("https://merchant.example/reports/q3");
```

`x402Client` stands for your x402 client library. Return `null` from either callback to stop and get the `402` back.

The fields map like this:

| Provenance | x402 v2 |
| --- | --- |
| The merchant asks for an intent | `PaymentRequired.extensions["com.provenanceauth.intent"].info.required` |
| The intent token | `PaymentPayload.extensions["com.provenanceauth.intent"].info.token` |
| The issuer's published keys URL | `PaymentPayload.extensions["com.provenanceauth.intent"].info.jwks_url`, a hint |
| The token's `payload_hash` | `resource.url` plus the chosen requirements' `scheme`, `network`, `amount`, `asset` and `payTo` |

## 7. Verify the payment at the merchant

On the merchant's side, `verifyX402Payment` reads the `PAYMENT-SIGNATURE` header and checks the token against the issuer's published keys before you settle. Pass `expected`, built from the requirements you advertised, to check that the token binds this payment and that the payment's `accepted` requirements match. Pass `onlineStatus` to also check revocation, which an offline check can't see. Use it for any payment of real value.

**Node**

```ts
import { verifyX402Payment, x402BindingPayload, x402Challenge } from "@provenanceauth/rails/x402";
import { publicVerify } from "@provenanceauth/rails/checkout";
import { fetchJwks } from "@provenanceauth/sdk";

const issuer = process.env.PROVENANCE_API!;
const jwks = await fetchJwks(issuer);

export async function handle(req: Request): Promise<Response> {
  const result = await verifyX402Payment(req.headers.get("payment-signature"), {
    jwks,
    expected: x402BindingPayload(resource, accepts[0]),
    onlineStatus: publicVerify(issuer), // the free, keyless POST /v1/verify
  });
  if (!result.accepted) {
    const challenge = x402Challenge({ resource, accepts });
    return new Response("{}", { status: challenge.status, headers: challenge.headers });
  }
  // Verify and settle the payment with your facilitator, then serve.
  return new Response("the report");
}
```

**Python**

```python
import base64, json, os
import httpx
from provenanceauth import fetch_jwks, verify_intent_token_offline

issuer = os.environ["PROVENANCE_API"]
jwks = fetch_jwks(issuer)

def accept_intent(payment_signature: str) -> bool:
    payment = json.loads(base64.b64decode(payment_signature))
    if payment.get("x402Version") != 2:
        return False
    info = payment.get("extensions", {}).get("com.provenanceauth.intent", {}).get("info", {})
    result = verify_intent_token_offline(info.get("token", ""), jwks)
    if not result.valid:
        return False
    return httpx.post(f"{issuer}/v1/verify", json={"token": info.get("token", "")}).json()["valid"]
```

| `result.reason` | Means |
| --- | --- |
| `no_payment` | The `PAYMENT-SIGNATURE` header is missing or malformed |
| `invalid_x402_version` | The payment isn't `x402Version: 2` |
| `no_intent` | The payment has no `com.provenanceauth.intent` token |
| `token_expired` | The intent token is past its expiry |
| `token_invalid` | The signature didn't verify against the published keys |
| `payload_unbound` | The token was authorized without an action payload |
| `payload_hash_mismatch` | The resource, amount, asset, network or recipient differs from what the person authorized |
| `accepted_mismatch` | The payment was made under different requirements than the token binds |
| `token_revoked` | The online check found the token revoked |

For browser clients, the merchant's CORS headers expose `PAYMENT-REQUIRED` and `PAYMENT-RESPONSE` and allow `PAYMENT-SIGNATURE`.

The grant's budget and merchant limits are enforced when the agent authorizes and when your executor calls [`POST /v1/mandate/assessments`](https://provenanceauth.com/docs/api/intent-tokens.md#post-v1-mandate-assessments); an offline check proves only that the token is genuine and current.

## 8. Map the grant to an ACP allowance

The Agentic Commerce Protocol (ACP) has the agent ask the merchant's payment provider for a delegated payment token, bounded by an `allowance`. `provenanceToAcpAllowance` builds that allowance from the grant, so the token can't exceed what the person agreed to. It refuses a merchant that isn't in the mandate's `allowed_counterparties`.

**Node**

```ts
import { provenanceToAcpAllowance } from "@provenanceauth/rails/acp";

const allowance = provenanceToAcpAllowance(mandate, {
  checkoutSessionId: session.id,
  merchantId: "merchant_acme",
  currency: session.currency,
});
```

The allowance, for a grant with a `max_amount` of 200:

```json
{
  "reason": "one_time",
  "max_amount": 20000,
  "currency": "usd",
  "checkout_session_id": "checkout_session_123",
  "merchant_id": "merchant_acme",
  "expires_at": "2027-12-31T23:59:59Z"
}
```

The fields map like this:

| Provenance | ACP 2026-04-17 |
| --- | --- |
| `constraints.max_amount`, or the authorized amount of an intent token | `allowance.max_amount`, in minor units for the currency |
| `constraints.expires_at`, or the intent token's `exp` | `allowance.expires_at` |
| `constraints.allowed_counterparties` | `allowance.merchant_id` must be in the list when the list is set |
| The intent token | `provenance_intent.token` on the complete-checkout request |
| The token's `payload_hash` | The checkout session id, total, currency, merchant id and store origin |

## 9. Attach the intent to the checkout completion

Authorize the purchase with the checkout's facts as the action payload, so the token's payload hash binds this session, its total, its currency, its merchant and the store's origin. `acpBindingFromSession` reads the first four from the checkout session (the total is the session's `total` line in minor units) and takes the origin as its third argument: the scheme and host of the store's checkout endpoint, such as `https://acme.example`. Then add the token to the complete-checkout request with `withProvenanceIntent`.

**Node**

```ts
import { acpBindingFromSession, acpExtension, withProvenanceIntent } from "@provenanceauth/rails/acp";

const binding = acpBindingFromSession(session, "merchant_acme", "https://acme.example");
const auth = await prov.mandate.intents.create({
  actionDescription: `Complete checkout ${session.id} at merchant_acme`,
  actionPayload: binding,
  agentSessionId: "sess_buyer_1",
  deviceId: "dev_00000000000000000000000000000001",
  mandateToken: mandate.mandateToken,
});

const jwksUrl = `${process.env.PROVENANCE_API}/.well-known/jwks.json`;
const body = withProvenanceIntent({ payment_data: paymentData }, auth.intentToken, { jwksUrl });
const { declaration } = acpExtension(auth.intentToken, { jwksUrl });
```

The request carries the token in an ACP extension field, `com.provenanceauth.intent`. The merchant lists the extension in its `capabilities.extensions`:

```json
{
  "name": "com.provenanceauth.intent@2026-10-24",
  "extends": ["$.CheckoutSessionCompleteRequest.provenance_intent"],
  "schema": "https://provenanceauth.com/schemas/acp/provenance-intent/2026-10-24.json"
}
```

Pass `schemaUrl` to point the declaration at your own copy of the schema. Card details and the payment token stay with the payment provider.

## 10. Verify the completion at the merchant

On the merchant's side, `verifyAcpCompletion` checks the token against the issuer's published keys and checks that its payload hash matches your own record of the session. Pass the facts from your checkout session, never from the request.

**Node**

```ts
import { acpBindingFromSession, verifyAcpCompletion } from "@provenanceauth/rails/acp";
import { publicVerify } from "@provenanceauth/rails/checkout";
import { fetchJwks } from "@provenanceauth/sdk";

const issuer = process.env.PROVENANCE_API!;
const jwks = await fetchJwks(issuer);

export async function complete(sessionId: string, body: Record<string, unknown>) {
  const session = await loadCheckoutSession(sessionId);
  const result = await verifyAcpCompletion(body, {
    jwks,
    expected: acpBindingFromSession(session, "merchant_acme", "https://acme.example"),
    onlineStatus: publicVerify(issuer), // the free, keyless POST /v1/verify
  });
  if (!result.accepted) throw new Error(result.reason);
  return placeOrder(session, body);
}
```

| `result.reason` | Means |
| --- | --- |
| `no_intent` | The request has no `provenance_intent.token` |
| `token_expired` | The intent token is past its expiry |
| `token_invalid` | The signature didn't verify against the published keys |
| `payload_unbound` | The token was authorized without an action payload |
| `payload_hash_mismatch` | The session, total, currency, merchant or origin differs from what the person authorized |
| `merchant_id_mismatch`, `total_mismatch` | The same, naming the field, when the request includes `provenance_intent.binding` |
| `binding_tampered` | The request's `provenance_intent.binding` doesn't match the token |
| `token_revoked` | The online check found the token revoked |

The third argument to `acpBindingFromSession` is your store's origin, and both sides pass it. An approval for another store that uses the same merchant id fails with `payload_hash_mismatch`.

## 11. Buy from another agent under a signed offer

When the seller is another company's agent, it sells under a signed offer and the acceptance is a deal ([Deals between agents](https://provenanceauth.com/docs/authorize/concepts/agent-commerce.md)). Each rail carries the acceptance token:

| Rail | How the deal rides |
| --- | --- |
| x402 v2 | The seller's `x402OfferRequired` puts the offer in the 402's `com.provenanceauth.intent` extension. `intentPaymentFetch` with `dealTokenGetter(acceptOffer)` accepts it through [`POST /v1/authorize/deals`](https://provenanceauth.com/docs/api/deals.md#post-v1-authorize-deals) and pays with the acceptance token. The seller checks it with `verifyX402DealPayment`. |
| ACP | The checkout completion's Provenance extension carries the acceptance token, as it carries any intent token. |
| AP2 (maps to AP2 0.2) | Put the deal id in the Cart Mandate's metadata. Provenance never signs AP2 mandates. |

Before an agent accepts an offer, it can check that the seller agent and its key are the ones the business's signed profile lists ([Find a business](https://provenanceauth.com/docs/authorize/guides/find-a-business.md)). Sellers publish the profile in each rail's answer with `discoveryFields(profile)`: `info.profile` in the x402 402, `profile` in the ACP extension declaration, and `com.provenanceauth.profile` in the AP2 merchant agent's metadata.

```ts
import { intentPaymentFetch } from "@provenanceauth/rails/x402";
import { acceptOffer, dealTokenGetter } from "@provenanceauth/rails/deals";

const pay = intentPaymentFetch(fetch, dealTokenGetter((offer) => acceptOffer(offer, { apiBase, apiKey, agent_session_id: "sess_scout_7", grant_id: mandate_id })), { createPayment });
const res = await pay("https://saltmarsh.example/reports/eu-storage");
```

Either side can then record the rail's reference with [`POST /v1/authorize/deals/{id}/payment`](https://provenanceauth.com/docs/api/deals.md#post-v1-authorize-deals-id-payment). Provenance never moves or holds the money.

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `valid: false`, `grant_constraint_violated` at verify | The payment is over `max_amount` or to a merchant not in `allowed_counterparties` | Stay within the grant, or give the agent a new one. |
| `valid: false`, `grant_budget_exceeded` | The budget for this window is spent | Wait for the next window, or grant a larger budget. |
| `provenanceToAcpAllowance` throws `not in the mandate's allowed_counterparties` | The checkout's merchant isn't one the person allowed | Use an allowed merchant, or give the agent a new grant. |
| `provenanceToAcpAllowance` throws `the mandate has no max_amount` | An ACP allowance needs a per-payment limit | Give the grant a `max_amount`. |
| `payload_hash_mismatch` at the merchant | The cart or the payment amount changed after the person authorized it | Authorize again with the new total. |
| `unresolved_constraint` from `verifyAp2Mandate` | The AP2 mandate has no intent token, or an open mandate has a constraint the check can't evaluate | Ask the person to approve this Checkout, then present the new intent token. |
| `provenanceMandateToAp2OpenPayment` throws `needs a Merchant object` | AP2 lists allowed payees as merchant objects with a name | Pass `payees` with an `id` and `name` for each allowed counterparty. |
| `intentPaymentFetch` returns the `402` without calling `getToken` | The merchant's `PAYMENT-REQUIRED` doesn't list `com.provenanceauth.intent`, or isn't x402 v2 | Pay with your x402 client alone, or ask the merchant to add the extension. |
| `token_invalid: unknown kid` at the merchant | The merchant's cached keys predate a key rotation | Fetch the keys again. |
| `402` [`trial_ended`](https://provenanceauth.com/docs/platform/errors.md#trial_ended) on the grant | The Free trial ended | Choose a plan in **Settings → Plan & usage**; see [plans and usage](https://provenanceauth.com/docs/account/plans-and-usage.md#free-trial). |

## See also

- [Verify agent checkouts](https://provenanceauth.com/docs/authorize/guides/verify-agent-checkout.md), for a plain web checkout
- [Grants](https://provenanceauth.com/docs/mandate/concepts/grants.md)
- [Issue AP2 mandates](https://provenanceauth.com/docs/mandate/guides/issue-ap2-mandates.md), with Provenance as the Trusted Surface
- [Verify tokens offline](https://provenanceauth.com/docs/authorize/guides/verify-tokens.md)
- [Execution binding](https://provenanceauth.com/docs/mandate/guides/execution-binding.md)
