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

# Create Payment Intent

> Create a payment intent for checkout

# Create Payment Intent

Creates a PaymentIntent (or equivalent for other gateways) for processing the payment.

**Requires `cart_unique_id` from `/cart/validate`.**

## Request

<ParamField header="X-API-Key" type="string" required>
  Your API key
</ParamField>

### Body Parameters

<ParamField body="product_id" type="integer" required>
  Primary product ID in the cart
</ParamField>

<ParamField body="cart_unique_id" type="string" required>
  Cart ID from `/cart/validate` response
</ParamField>

<ParamField body="email" type="string" required>
  Customer's email address
</ParamField>

<ParamField body="first_name" type="string" required>
  Customer's first name
</ParamField>

<ParamField body="last_name" type="string" required>
  Customer's last name
</ParamField>

<ParamField body="currency" type="string" required>
  Currency code (must match cart validation)
</ParamField>

<ParamField body="delivery_details" type="object">
  Shipping details (for physical products)
</ParamField>

## Response

<ResponseExample>
  ```json theme={null}
  {
    "status": true,
    "message": "Payment intent created",
    "data": {
      "secret": "pi_3abc123_secret_xyz789",
      "publishable_key": "pk_live_abc123...",
      "payment_method_types": ["card"],
      "currency": "usd",
      "amount_to_pay": 5829,
      "data": {
        "transaction_id": "txn_abc123",
        "product_title": "Premium T-Shirt",
        "customer_email": "john@example.com"
      }
    }
  }
  ```
</ResponseExample>

## Frontend Integration

Use the `secret` (client\_secret) with Khaime Payment SDK to complete the payment:

```javascript theme={null}
const khaime = Khaime(response.publishable_key);

const { error, paymentIntent } = await khaime.confirmPayment(
  response.secret,
  {
    payment_method: {
      card: cardElement,
      billing_details: {
        name: 'John Doe',
        email: 'john@example.com'
      }
    }
  }
);

if (error) {
  console.error(error.message);
} else if (paymentIntent.status === 'succeeded') {
  // Redirect to order confirmation
  window.location.href = `/order/${response.data.transaction_id}`;
}
```

## Errors

| Error Code              | Description                   |
| ----------------------- | ----------------------------- |
| `CART_EXPIRED`          | Cart ID is no longer valid    |
| `CART_NOT_FOUND`        | Invalid cart ID               |
| `PRODUCT_NOT_FOUND`     | Product no longer available   |
| `PAYMENT_GATEWAY_ERROR` | Error creating payment intent |

## Example

```bash theme={null}
curl -X POST "https://api.khaime.com/api/v1/payment/intent" \
  -H "X-API-Key: pk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "product_id": 12345,
    "cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
    "email": "john@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "currency": "USD"
  }'
```
