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

# Checkout Cart

> Convert a cart into an order and process payment

<Note>
  This endpoint initiates the checkout process, converting a cart into an order. It validates inventory, calculates final totals, and processes payment.
</Note>

## Authentication

This endpoint requires a valid API key with `carts:write` and `orders:write` permissions.

```bash theme={null}
Authorization: Bearer YOUR_API_KEY
```

## Path Parameters

<ParamField path="id" type="string" required>
  The unique identifier of the cart to checkout
</ParamField>

## Request Body

<ParamField body="payment_method" type="object" required>
  Payment method details

  <Expandable title="Payment method properties">
    <ParamField body="type" type="string" required>
      Payment type: "card", "ach", "wire", "purchase\_order"
    </ParamField>

    <ParamField body="payment_method_id" type="string">
      Saved payment method ID
    </ParamField>

    <ParamField body="card" type="object">
      Card details (if not using saved method)

      <Expandable title="Card properties">
        <ParamField body="number" type="string">
          Card number
        </ParamField>

        <ParamField body="exp_month" type="integer">
          Expiration month
        </ParamField>

        <ParamField body="exp_year" type="integer">
          Expiration year
        </ParamField>

        <ParamField body="cvc" type="string">
          CVC code
        </ParamField>
      </Expandable>
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="billing_address" type="object" required>
  Billing address

  <Expandable title="Address properties">
    <ParamField body="line1" type="string" required>
      Street address
    </ParamField>

    <ParamField body="line2" type="string">
      Apartment, suite, etc.
    </ParamField>

    <ParamField body="city" type="string" required>
      City
    </ParamField>

    <ParamField body="state" type="string" required>
      State/Province code
    </ParamField>

    <ParamField body="postal_code" type="string" required>
      Postal/ZIP code
    </ParamField>

    <ParamField body="country" type="string" required>
      ISO 3166-1 alpha-2 country code
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="shipping_address" type="object">
  Shipping address (uses billing if not provided)

  <Expandable title="Address properties">
    Same structure as billing address
  </Expandable>
</ParamField>

<ParamField body="shipping_method_id" type="string" required>
  Selected shipping method ID
</ParamField>

<ParamField body="customer_note" type="string">
  Special instructions for the order
</ParamField>

<ParamField body="po_number" type="string">
  Purchase order number (for B2B)
</ParamField>

<ParamField body="metadata" type="object">
  Additional order metadata
</ParamField>

### Response

Returns the created order object.

<RequestExample>
  ```bash cURL theme={null}
  curl --location --request POST 'https://api.stateset.com/v1/carts/cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30/checkout' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_API_KEY' \
  --data-raw '{
      "payment_method": {
          "type": "card",
          "payment_method_id": "pm_saved_123"
      },
      "billing_address": {
          "line1": "123 Main St",
          "city": "San Francisco",
          "state": "CA",
          "postal_code": "94105",
          "country": "US"
      },
      "shipping_method_id": "ship_standard",
      "customer_note": "Please leave at front door"
  }'
  ```

  ```javascript Node.js theme={null}
  const order = await stateset.carts.checkout(
    'cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    {
      payment_method: {
        type: "card",
        payment_method_id: "pm_saved_123"
      },
      billing_address: {
        line1: "123 Main St",
        city: "San Francisco",
        state: "CA",
        postal_code: "94105",
        country: "US"
      },
      shipping_method_id: "ship_standard",
      customer_note: "Please leave at front door"
    }
  );
  ```

  ```python Python theme={null}
  order = stateset.carts.checkout(
    'cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30',
    payment_method={
      "type": "card",
      "payment_method_id": "pm_saved_123"
    },
    billing_address={
      "line1": "123 Main St",
      "city": "San Francisco",
      "state": "CA",
      "postal_code": "94105",
      "country": "US"
    },
    shipping_method_id="ship_standard",
    customer_note="Please leave at front door"
  )
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "order_123456",
    "object": "order",
    "cart_id": "cart_0901f083-aa1c-43c5-af5c-0a9d2fc64e30",
    "order_number": "ORD-2024-123456",
    "customer_id": "cust_abc123",
    "status": "processing",
    "payment_status": "paid",
    "fulfillment_status": "unfulfilled",
    "items": [
      {
        "id": "oi_abc123",
        "product_id": "prod_123",
        "variant_id": "var_blue_large",
        "product_name": "Wireless Headphones",
        "variant_name": "Blue - Large",
        "sku": "WH-BL-L",
        "quantity": 3,
        "unit_price": 9999,
        "discount_amount": 2999,
        "subtotal": 26997
      },
      {
        "id": "oi_def456",
        "product_id": "prod_789",
        "variant_id": "var_red_medium",
        "product_name": "T-Shirt",
        "variant_name": "Red - Medium",
        "sku": "TS-RD-M",
        "quantity": 1,
        "unit_price": 2499,
        "discount_amount": 250,
        "subtotal": 2249
      }
    ],
    "subtotal": 32496,
    "discount_amount": 3249,
    "tax_amount": 2268,
    "shipping_amount": 599,
    "total": 32114,
    "currency": "USD",
    "payment": {
      "id": "pay_xyz789",
      "method": "card",
      "last4": "4242",
      "brand": "visa",
      "status": "succeeded",
      "amount": 32114
    },
    "shipping_address": {
      "line1": "123 Main St",
      "city": "San Francisco",
      "state": "CA",
      "postal_code": "94105",
      "country": "US"
    },
    "shipping_method": {
      "id": "ship_standard",
      "name": "Standard Shipping",
      "amount": 599,
      "estimated_delivery": "2024-06-25"
    },
    "customer_note": "Please leave at front door",
    "created_at": "2024-06-20T17:00:00Z",
    "updated_at": "2024-06-20T17:00:00Z",
    "metadata": {
      "source": "web_checkout"
    }
  }
  ```
</ResponseExample>
