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

# End-to-End Flow

> Watch one complete purchase play out: an AI agent buys a concert ticket from discovery to on-chain settlement.

An AI agent buys one "Coldplay World Tour - Floor Standing GA" ticket (\$120.00), paying in FDUSD on BSC. Each step shows what the agent sends, what the merchant does behind the scenes, and what Prism returns.

***

## 1. Discovery

The agent checks the merchant's UCP profile. The merchant fetches the current handler definition from Prism and returns it.

**Agent → Merchant**

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET /.well-known/ucp
UCP-Agent: profile="https://platform.example/ucp/profile"
```

**Merchant → Prism** (background)

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
GET https://prism-gw.fd.xyz/api/v2/merchant/ucp/handlers
X-API-Key: prism_live_...
```

**Agent receives:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "ucp": {
    "version": "2026-01-23",
    "payment_handlers": {
      "xyz.fd.prism_payment": [
        { "id": "prism_default", "version": "2026-01-23" }
      ]
    }
  }
}
```

The agent confirms `xyz.fd.prism_payment` is present and proceeds to checkout.

***

## 2. Checkout Session

The agent sends their cart. The merchant calls Prism to get x402 payment requirements and returns them in the session.

**Agent → Merchant**

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /checkout-sessions
Content-Type: application/json
UCP-Agent: profile="https://platform.example/ucp/profile"

{
  "line_items": [
    { "item": { "id": "ticket_floor_ga" }, "quantity": 1 }
  ]
}
```

**Merchant → Prism** (background)

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST https://prism-gw.fd.xyz/api/v2/merchant/ucp/payment-requirements
X-API-Key: prism_live_...
Content-Type: application/json

{
  "amount": "120.00",
  "currency": "USD",
  "resource": {
    "url": "https://merchant.example/checkout-sessions/sess_abc123",
    "description": "Coldplay World Tour - Floor Standing GA"
  }
}
```

**Agent receives:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "session_id": "sess_abc123",
  "payment_handlers": {
    "xyz.fd.prism_payment": [
      {
        "id": "prism_default",
        "version": "2026-01-23",
        "config": {
          "x402Version": 2,
          "resource": {
            "url": "https://merchant.example/checkout-sessions/sess_abc123",
            "description": "Coldplay World Tour - Floor Standing GA"
          },
          "accepts": [
            {
              "scheme": "exact",
              "network": "eip155:56",
              "amount": "120000000000000000000",
              "asset": "0xaB27f55DB008704Ed8098f0dfBCf5e1aA387b9d9",
              "payTo": "0x40a01003f7543a3a3ee64fFB05504173BDb1C4fD",
              "maxTimeoutSeconds": 300,
              "extra": { "name": "First Digital USD", "version": "1" }
            },
            {
              "scheme": "exact",
              "network": "eip155:8453",
              "amount": "120000000",
              "asset": "0x036cbd53842c5426634e7929541ec2318f3dcf7e",
              "payTo": "0x40a01003f7543a3a3ee64fFB05504173BDb1C4fD",
              "maxTimeoutSeconds": 300,
              "extra": { "name": "USDC", "version": "2" }
            }
          ]
        }
      }
    ]
  }
}
```

The agent extracts `config` and passes it to the wallet.

***

## 3. Payment Authorization

The agent's wallet receives the `config` as `paymentRequirements`. No HTTP request goes out at this step — everything happens locally inside the TEE.

```
Wallet receives:  config.accepts — two options (BSC FDUSD, Base USDC)
Wallet selects:   eip155:56 (BSC), FDUSD — sufficient balance available
Wallet signs:     ERC-3009 transferWithAuthorization inside the secure enclave
Wallet returns:   complete signed x402 payment object
```

The private key never leaves the enclave. Only the signed authorization exits.

***

## 4. Complete Checkout

The agent submits the signed wallet output verbatim as the credential.

**Agent → Merchant**

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST /checkout-sessions/sess_abc123/complete
Content-Type: application/json
UCP-Agent: profile="https://platform.example/ucp/profile"

{
  "payment": {
    "instruments": [
      {
        "id": "wallet_bsc_fdusd",
        "handler_id": "prism_default",
        "type": "default",
        "credential": {
          "type": "default",
          "paymentPayload": {
            "signature": "0x...",
            "authorization": {
              "from":        "0xAgentWalletAddress",
              "to":          "0x40a01003f7543a3a3ee64fFB05504173BDb1C4fD",
              "value":       "120000000000000000000",
              "validAfter":  "0",
              "validBefore": "1760000000",
              "nonce":       "0x..."
            }
          },
          "paymentRequirements": { "...": "config from step 2" }
        }
      }
    ]
  }
}
```

**Merchant → Prism** (background)

```http theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
POST https://prism-gw.fd.xyz/api/v2/payment/settle
X-API-Key: prism_live_...
Content-Type: application/json

{ ...credential object verbatim... }
```

Prism executes the ERC-3009 `transferWithAuthorization` on BSC, verifies the transfer, and returns:

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "success": true,
  "transaction": "0xe80c...674b",
  "network": "eip155:56"
}
```

**Agent receives:**

```json theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
{
  "order": {
    "id": "ord_abc123",
    "status": "confirmed",
    "payment": {
      "handler_id": "prism_default",
      "status": "settled",
      "transaction": "0xe80c...674b",
      "network": "eip155:56"
    }
  }
}
```

The ticket is reserved. 120 FDUSD has settled on-chain to the merchant's wallet.

***

## Testing

Use the production Prism gateway (`https://prism-gw.fd.xyz`) with your own account and small amounts to validate the full flow end-to-end against real on-chain settlement.

<CardGroup cols={2}>
  <Card title="Merchant Guide" icon="store" href="/prism/integrations/ucp/merchants">
    Step-by-step implementation for the merchant server
  </Card>

  <Card title="Agent Guide" icon="robot" href="/prism/integrations/ucp/agents">
    Step-by-step implementation for the agent platform
  </Card>
</CardGroup>
