<!-- ZenPays documentation · https://docs.zenpayz.com/docs/rest-api/endpoints/ramp/buy-checkout -->

# Create Buy Checkout

Create a checkout intent to execute an on-ramp (fiat to crypto) transaction. Pass the `onramp` value from a quote response to select which quote to use.

<EndpointHeader verb="POST" path="/payment/api/v1/on-ramp/checkout" />

## Request

### Headers

<ParamTable
  label="Header"
  rows={[
    { name: "Content-Type", required: true, desc: "`application/json`" },
    { name: "x-request-id", desc: "Custom request ID for tracing" },
  ]}
/>

:::note Public Endpoint
This endpoint does not require authentication headers.
:::

### Body Parameters

<ParamTable
  rows={[
    { name: "onramp", type: "string", required: true, desc: "Identifier from quote response (e.g. `moonpay`)" },
    { name: "source", type: "string", required: true, desc: "Fiat currency (e.g. `usd`)" },
    { name: "destination", type: "string", required: true, desc: "Crypto ID (e.g. `btc_bitcoin`)" },
    { name: "amount", type: "number", required: true, desc: "Fiat amount" },
    { name: "type", type: "string", required: true, desc: "`buy`" },
    { name: "paymentMethod", type: "string", required: true, desc: "Payment method (e.g. `creditcard`)" },
    { name: "walletAddress", type: "string", desc: "Crypto wallet address for delivery. See [Wallet Addresses](/docs/rest-api/endpoints/ramp/wallet-addresses)" },
    { name: "walletMemo", type: "string", desc: "Memo/tag for XRP, XLM, etc." },
    { name: "network", type: "string", desc: "Blockchain network (e.g. `ethereum`)" },
    { name: "country", type: "string", desc: "ISO country code" },
    { name: "sessionId", type: "string", desc: "Checkout session ID for tracking" },
    { name: "walletAddresses", type: "object", desc: "Network-to-address mappings (e.g. `{ \"ethereum\": \"0x...\" }`)" },
  ]}
/>

:::tip Wallet Resolution
If `walletAddress` is not provided but `sessionId` is, ZenPays automatically resolves the wallet from your merchant settings. See [Wallet Addresses](/docs/rest-api/endpoints/ramp/wallet-addresses) for details.
:::

## Response

### Success (200 OK)

```json
{
  "success": true,
  "data": {
    "transactionId": "txn_abc123",
    "redirectUrl": "https://checkout.example.com/...",
    "status": "pending"
  },
  "message": "Checkout intent created"
}
```

### Response Fields

<ParamTable
  rows={[
    { name: "transactionId", type: "string", desc: "Unique transaction identifier" },
    { name: "redirectUrl", type: "string", desc: "URL to redirect the user to complete payment" },
    { name: "status", type: "string", desc: "Initial status (`pending`)" },
  ]}
/>

After receiving the response, redirect the user to `redirectUrl` to complete payment.

### Error Responses

<ErrorTable
  rows={[
    { code: "VALIDATION_ERROR", status: "400", message: "Invalid request body" },
    { code: "RAMP_CHECKOUT_FAILED", status: "500", message: "Failed to create checkout intent" },
  ]}
/>

<CodeRail>

## Examples

<Tabs groupId="language">
  <TabItem value="curl" label="cURL" default>

```bash
curl -X POST https://api.zenpayz.com/payment/api/v1/on-ramp/checkout \
  -H "Content-Type: application/json" \
  -d '{
    "onramp": "moonpay",
    "source": "usd",
    "destination": "btc_bitcoin",
    "amount": 100,
    "type": "buy",
    "paymentMethod": "creditcard",
    "walletAddress": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"
  }'
```

  </TabItem>
  <TabItem value="javascript" label="JavaScript">

```javascript
const response = await fetch('https://api.zenpayz.com/payment/api/v1/on-ramp/checkout', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    onramp: 'moonpay',
    source: 'usd',
    destination: 'btc_bitcoin',
    amount: 100,
    type: 'buy',
    paymentMethod: 'creditcard',
    walletAddress: 'bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh',
  }),
});

const { data } = await response.json();

// Redirect user to complete payment
window.location.href = data.redirectUrl;
```

  </TabItem>
  <TabItem value="python" label="Python">

```python
import requests

response = requests.post(
    "https://api.zenpayz.com/payment/api/v1/on-ramp/checkout",
    json={
        "onramp": "moonpay",
        "source": "usd",
        "destination": "btc_bitcoin",
        "amount": 100,
        "type": "buy",
        "paymentMethod": "creditcard",
        "walletAddress": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
    },
)

data = response.json()["data"]
print(f"Transaction: {data['transactionId']}")
print(f"Redirect to: {data['redirectUrl']}")
```

  </TabItem>
</Tabs>

</CodeRail>

## Full Integration Flow

```
1. GET  /on-ramp/supported-assets   → Populate currency dropdowns
2. GET  /on-ramp/payment-methods/usd → Get available payment options
3. GET  /on-ramp/quotes?source=usd&destination=btc_bitcoin&amount=100
                                      → Show pricing options to user
4. POST /on-ramp/checkout            → Create checkout with selected quote
5. Redirect to redirectUrl            → User completes payment
6. GET  /on-ramp/transactions/{id}   → Poll until completed or failed
```

---

## Intent-Based Buy Checkout (Recommended)

For merchants using ramp intents, use this endpoint to create a buy checkout tied to an existing intent.

### Endpoint

```
POST /payment/api/v1/on-ramp/buy/checkout
```

### Body Parameters

<ParamTable
  rows={[
    { name: "intentId", type: "string", required: true, desc: "Ramp intent ID" },
    { name: "cryptoCurrency", type: "string", required: true, desc: "Crypto to buy (e.g. `USDT`)" },
    { name: "chain", type: "string", required: true, desc: "Blockchain network (e.g. `tron`, `ethereum`)" },
    { name: "fiatCurrency", type: "string", required: true, desc: "Fiat currency (e.g. `USD`)" },
    { name: "fiatAmount", type: "number", required: true, desc: "Amount to pay in fiat" },
    { name: "cryptoAmount", type: "number", required: true, desc: "Expected crypto amount to receive" },
    { name: "rate", type: "number", required: true, desc: "Locked exchange rate" },
    { name: "totalFee", type: "number", required: true, desc: "Total fees" },
    { name: "quoteId", type: "string", desc: "Quote ID from quotes endpoint" },
  ]}
/>

### Sample Request

```json
{
  "intentId": "ri_1710345678000_a1b2c3d4e5f6g7h8",
  "cryptoCurrency": "USDT",
  "chain": "tron",
  "fiatCurrency": "USD",
  "fiatAmount": 100,
  "cryptoAmount": 98.5,
  "rate": 1.0,
  "totalFee": 1.5
}
```

### Response (200 OK)

```json
{
  "success": true,
  "data": {
    "intentId": "ri_1710345678000_a1b2c3d4e5f6g7h8",
    "paymentIntentId": "pi_abc123def456",
    "checkoutUrl": "https://checkout.zenpayz.com/pay/pi_abc123def456",
    "fiatAmount": 100,
    "fiatCurrency": "USD",
    "cryptoAmount": 98.5,
    "cryptoCurrency": "USDT",
    "chain": "tron",
    "rate": 1.0,
    "expiresAt": "2026-03-15T10:00:00.000Z"
  },
  "message": "Buy checkout created"
}
```

### Response Fields

<ParamTable
  rows={[
    { name: "intentId", type: "string", desc: "Ramp intent ID" },
    { name: "paymentIntentId", type: "string", desc: "Payment intent for the fiat charge" },
    { name: "checkoutUrl", type: "string", desc: "URL to redirect customer for payment" },
    { name: "fiatAmount", type: "number", desc: "Fiat amount to charge" },
    { name: "fiatCurrency", type: "string", desc: "Fiat currency" },
    { name: "cryptoAmount", type: "number", desc: "Crypto amount customer will receive" },
    { name: "cryptoCurrency", type: "string", desc: "Crypto currency" },
    { name: "chain", type: "string", desc: "Blockchain network" },
    { name: "rate", type: "number", desc: "Exchange rate applied" },
    { name: "expiresAt", type: "string", desc: "Checkout expiry (ISO 8601)" },
  ]}
/>

## Next Steps

- [Transaction Status](/docs/rest-api/endpoints/ramp/transaction-status) -- Poll transaction progress
- [Buy Quotes](/docs/rest-api/endpoints/ramp/buy-quotes) -- Get quotes before checkout
- [Wallet Addresses](/docs/rest-api/endpoints/ramp/wallet-addresses) -- Understand wallet resolution
