> ## 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.

# Validate Cart

> Build and validate cart with shipping, taxes, and discounts

# Validate Cart

Validates cart items, calculates shipping, applies discounts, and returns a `cart_unique_id` required for creating a payment intent.

**This endpoint must be called before `/payment/intent`.**

## Request

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

### Body Parameters

<ParamField body="cart" type="array" required>
  Array of cart items

  Each item should have:

  * `product_id` (integer): Product ID
  * `quantity` (integer): Quantity
  * `price` (integer): Price in smallest currency unit (cents)
  * `least_sub_variant_id` (string): Variant ID if applicable
</ParamField>

<ParamField body="currency" type="string" required>
  Currency code (e.g., "USD")
</ParamField>

<ParamField body="delivery_details" type="object">
  Shipping address for physical products

  * `first_name` (string)
  * `last_name` (string)
  * `email` (string)
  * `phone` (string)
  * `address` (string)
  * `city` (string)
  * `state` (string)
  * `zip_code` (string)
  * `country_code` (string)
</ParamField>

<ParamField body="coupons" type="array">
  Array of coupon codes to apply
</ParamField>

<ParamField body="user_country" type="string">
  Customer's country code for regional pricing
</ParamField>

## Response

<ResponseExample>
  ```json theme={null}
  {
    "status": true,
    "message": "Cart Details",
    "data": {
      "cart_unique_id": "bc59bc1f-e1b0-4ee5-a9cb-b966042ce38f",
      "cart_items": [
        {
          "product_id": 12345,
          "product_title": "Premium T-Shirt",
          "quantity": 2,
          "product_price": 2999,
          "line_item_subtotal": 5998,
          "line_item_discount_amount": 600,
          "line_item_total_after_discounts": 5398,
          "coupons_applied": ["SAVE10"]
        }
      ],
      "subtotal": 5998,
      "discount_total": 600,
      "shipping_fee": 599,
      "tax": 432,
      "tax_rate": 8,
      "total": 5829,
      "currency": "USD"
    }
  }
  ```
</ResponseExample>

## Example

```bash theme={null}
curl -X POST "https://api.khaime.com/api/v1/cart/validate" \
  -H "X-API-Key: pk_live_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "cart": [
      {
        "product_id": 12345,
        "quantity": 2,
        "price": 2999,
        "least_sub_variant_id": "var_001"
      }
    ],
    "currency": "USD",
    "delivery_details": {
      "first_name": "John",
      "last_name": "Doe",
      "email": "john@example.com",
      "phone": "+1234567890",
      "address": "123 Main St",
      "city": "New York",
      "state": "NY",
      "zip_code": "10001",
      "country_code": "US"
    },
    "coupons": ["SAVE10"]
  }'
```

## Notes

* The `cart_unique_id` is valid for 24 hours
* Save this ID and pass it to `/payment/intent`
* Prices are validated against the database to prevent tampering
* Currency conversion is applied automatically if multicurrency is enabled
