> Source: https://developers.terrawallet.us/docs/pay/payment-intents . Terra Wallet developer docs (early access).

# Payment intents

A payment intent is one payment for one amount. Your server creates it, your customer pays it on hosted checkout,
and Terra marks it `succeeded` only when the chain proves the payment.

> **Preview.** The API is in early access and may change before launch.

## Create one

`POST /v1/payment_intents` with your secret key and an `Idempotency-Key`:

| Field | Type | Required | Notes |
|---|---|---|---|
| `amount` | decimal string | yes | For example `"10.50"`. Never a float |
| `currency` | string | yes | A fiat ISO code: `USD`, `EUR`, `INR` and so on |
| `accepted_assets` | array of assets | yes | What the customer may pay with (see below) |
| `description` | string | no | Plain text shown to the customer |
| `metadata` | object | no | Up to 20 keys; string values up to 500 characters. Never shown on checkout |
| `expires_in_s` | integer | no | 300 to 86400 seconds. Default 900 (15 minutes) |
| `success_url` | URL | no | Where checkout sends the customer after paying |
| `cancel_url` | URL | no | Where checkout sends the customer if they leave |
| `customer_email` | string | no | The customer's email |

Unknown fields are rejected, so a typo fails loudly instead of being ignored.

### Assets

An asset names a token by chain and contract:

```json
{ "chain": "tron", "symbol": "USDT", "contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "decimals": 6 }
```

- `chain` is a chain id such as `tron`, `bsc`, `ethereum`, `polygon`, `base`, `arbitrum` or `solana`.
- `contract` is the token contract or mint, or `null` for the chain's native coin.
- Terra matches tokens by **contract**, never by symbol. A token called "USDT" at another address is not USDT.
- Copy contracts from [Supported networks and assets](https://developers.terrawallet.us/docs/networks.md) or the MCP tool
  `list_supported_networks`. Never type them by hand.

### Example

```js
// Preview: create a payment intent (Node 18 or later).
const res = await fetch("https://terrawallet.us/api/v1/payment_intents", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.TERRA_SECRET_KEY}`,
    "Content-Type": "application/json",
    "Idempotency-Key": `order-${order.id}-checkout`,
  },
  body: JSON.stringify({
    amount: order.total,            // "120.00"
    currency: "USD",
    accepted_assets: [
      { chain: "tron", symbol: "USDT", contract: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", decimals: 6 },
      { chain: "solana", symbol: "USDC", contract: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v", decimals: 6 },
    ],
    description: `Order ${order.id}`,
    metadata: { order_id: String(order.id) },
    success_url: `https://shop.example.com/orders/${order.id}/thanks`,
    cancel_url: "https://shop.example.com/cart",
  }),
});
const intent = await res.json();
// Redirect the customer to intent.checkout_url
```

## The response

```json
{
  "id": "pi_...",
  "status": "requires_payment",
  "checkout_url": "https://pay.terrawallet.us/c/pi_...",
  "amount": "120.00",
  "currency": "USD",
  "quotes": [
    {
      "asset": { "chain": "tron", "symbol": "USDT", "contract": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", "decimals": 6 },
      "amount_base_units": "...",
      "pay_address": "...",
      "expires_at": "..."
    }
  ]
}
```

- `quotes` holds one exact amount per accepted asset. `amount_base_units` is an integer string in the token's
  smallest unit; divide by `10^decimals` to display it. Never use floats for money.
- `pay_address` is where that asset is paid: your payout wallet on that chain.
- Each quote is valid until `expires_at`.

## Statuses

| Status | Meaning |
|---|---|
| `requires_payment` | Waiting for the customer to pay |
| `processing` | A matching payment was seen and is waiting for the chain's confirmation policy |
| `succeeded` | Paid in full and verified on chain |
| `expired` | The window ended without a full payment |
| `canceled` | The intent was canceled |
| `underpaid` | The customer paid less than the quote |
| `overpaid` | The customer paid more than the quote |

## How verification works

- **An exact, unique amount per intent.** That is what ties a payment to one intent, so nobody watching your
  wallet can claim another customer's payment.
- **A confirmation policy per chain.** For example, EVM payments wait for a number of blocks, Tron payments
  wait until solidified and Solana payments until confirmed.
- **One transaction per intent.** A transaction can never pay two intents.
- **Chain truth only.** A transaction hash sent by a client is a hint to look, never proof. A network error
  leaves a payment pending: it never accepts or rejects it.

## Edge cases

- **Underpaid:** the intent becomes `underpaid` and you get `payment_intent.underpaid`. Checkout can offer the
  customer a top-up for the remainder.
- **Overpaid:** the intent becomes `overpaid` and is flagged for a refund. See [Refunds](https://developers.terrawallet.us/docs/pay/refunds.md).
- **Paid after expiry:** re-quoted, or accepted under your rule.

## Webhooks for payment intents

`payment_intent.succeeded`, `payment_intent.expired` and `payment_intent.underpaid`. See
[Webhooks](https://developers.terrawallet.us/docs/webhooks.md).
