> For the complete documentation index, see [llms.txt](https://docs.liquidcommerce.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.liquidcommerce.cloud/elements-v2/checkout.md). Agents can also search and read this documentation through its [MCP server](https://docs.liquidcommerce.cloud/~gitbook/mcp).

# Checkout

The Checkout component provides a complete purchase flow with customer info, payment (Stripe), and confirmation.

## What you get

* Customer, billing, and shipping info
* Gift and marketing preferences
* Promo codes and gift cards
* Order summary and totals
* Hosted checkout or drawer checkout

## Payment (Stripe) requirements

Checkout's payment step is built on Stripe. The SDK doesn't bundle Stripe.js — it dynamically injects `<script src="https://js.stripe.com/basil/stripe.js">` into the page the first time a payment form is created, skipping the injection if `window.Stripe` is already present.

> If your site enforces a strict Content-Security-Policy, add `js.stripe.com` to `script-src`. Without it, the script is blocked, `window.Stripe` never becomes available, and the payment form fails to initialize. Stripe's Payment Element also relies on its own iframes and network requests beyond this script — see [Stripe's CSP documentation](https://docs.stripe.com/security/guide#content-security-policy) for the complete list of hosts to allow.

## Default: drawer checkout

Checkout opens automatically from the cart drawer. No setup required.

## Hosted checkout (inject)

```js
const client = await Elements('YOUR_API_KEY', { env: 'production' });
await client.injectCheckoutElement({
  containerId: 'checkout',
  checkoutId: 'optional_checkout_id',
  hideHeader: false
});
```

For the cart's "Go to Checkout" button to redirect to this injected page (instead of opening the drawer), configure the checkout page URL on your other pages (product/cart):

```js
const client = await Elements('YOUR_API_KEY', {
  env: 'production',
  checkout: { pageUrl: 'https://yoursite.com/checkout?lce_checkout={token}' }
});
```

The `{token}` placeholder is replaced with the current checkout token — the same value passed to the API above as the `checkoutId` parameter. This is the JS-config equivalent of the `data-checkout-url` attribute shown below.

## Hosted checkout (URL param)

Hosted checkout uses two things together:

1. `data-checkout-url` on the main script (so the cart can redirect to your hosted checkout page).
2. `data-checkout-param` on the hosted page (so it can read the checkout token from the URL).

Hosted page example:

```html
<script
  defer
  data-liquid-commerce-elements
  data-token="YOUR_API_KEY"
  data-env="production"
  data-checkout-param="lce_checkout"
  type="text/javascript"
  src="https://elements.reservebar-worker.workers.dev/all/elements.js"
></script>

<div data-lce-checkout></div>
```

Main script example (cart redirects here):

```html
<script
  defer
  data-liquid-commerce-elements
  data-token="YOUR_API_KEY"
  data-env="production"
  data-checkout-url="https://yoursite.com/checkout?lce_checkout={token}"
  data-checkout-param="lce_checkout"
  type="text/javascript"
  src="https://elements.reservebar-worker.workers.dev/all/elements.js"
></script>
```

## Hosted checkout UI controls

Use these attributes on the hosted checkout page to customize the UI:

* `hide-header` on the checkout container\
  Hides the SDK header so you can render your own.

```html
<div data-lce-checkout hide-header></div>
```

* `data-lce-exit-checkout` on any element\
  Lets you build your own “Exit checkout” button or link.

```html
<button data-lce-exit-checkout>Exit checkout</button>
```

## Checkout-only build

If a page only needs hosted checkout, use the checkout-only script. It supports the same hosted-checkout attributes but ships noticeably less JavaScript for faster load time.

```html
<script
  defer
  data-liquid-commerce-elements
  data-token="YOUR_API_KEY"
  data-env="production"
  type="text/javascript"
  src="https://elements.reservebar-worker.workers.dev/checkout/checkout.js"
></script>
```

> This bundle URL also takes a partner code as the first path segment (e.g. `/<partner-code>/checkout/checkout.js`) — see [Quick Start Guide](https://docs.liquidcommerce.cloud/elements-v2/quick-start-guide.md) for details.

### Programmatic (import)

Import the tree-shaken `ElementsCheckout` client from the `/checkout` subpath instead of using the declarative script. `ElementsCheckout()` authenticates and prepares the client for you, then resolves to the checkout-only client.

```js
import { ElementsCheckout } from '@liquidcommerce/elements-sdk/checkout';

const client = await ElementsCheckout('YOUR_API_KEY', { env: 'production' });

await client.injectCheckout({
  containerId: 'checkout',
  checkoutId: new URLSearchParams(window.location.search).get('lce_checkout') ?? undefined,
  hideHeader: false
});
```

After initialization the client is also available globally at `window.LiquidCommerce.elementsCheckout`.

Its `actions.checkout` omits the drawer-navigation actions (`openCheckout`, `closeCheckout`, `toggleCheckout`) — those only exist in the full `Elements()` client. `exitCheckout` and the info/promo/gift-card actions below are all available.

## Checkout actions

```js
window.LiquidCommerce.elements.actions.checkout.openCheckout();
window.LiquidCommerce.elements.actions.checkout.closeCheckout();
window.LiquidCommerce.elements.actions.checkout.toggleCheckout();
window.LiquidCommerce.elements.actions.checkout.exitCheckout();

await window.LiquidCommerce.elements.actions.checkout.addProduct([
  { identifier: '00619947000020', fulfillmentType: 'shipping', quantity: 1 },
  // Optional: pre-fill engraving — same clamping/fallback rules as cart.addProduct.
  {
    identifier: '00619947000020',
    fulfillmentType: 'shipping',
    quantity: 1,
    engravingLines: ['For Dad']
  }
], true);

await window.LiquidCommerce.elements.actions.checkout.applyPromoCode('WELCOME10');
await window.LiquidCommerce.elements.actions.checkout.removePromoCode();

await window.LiquidCommerce.elements.actions.checkout.applyGiftCard('GIFT-1234-5678');
await window.LiquidCommerce.elements.actions.checkout.removeGiftCard('GIFT-1234-5678');

await window.LiquidCommerce.elements.actions.checkout.toggleIsGift(true);
await window.LiquidCommerce.elements.actions.checkout.toggleBillingSameAsShipping(false);
await window.LiquidCommerce.elements.actions.checkout.toggleMarketingPreferences('canEmail', true);

window.LiquidCommerce.elements.actions.checkout.updateCustomerInfo({
  firstName: 'John',
  lastName: 'Doe',
  email: 'john@example.com'
});

window.LiquidCommerce.elements.actions.checkout.updateBillingInfo({
  firstName: 'John',
  lastName: 'Doe',
  addressOne: '789 Elm St',
  city: 'Chicago',
  state: 'IL',
  zipCode: '60601'
});

// Pre-select a saved payment method (skips the card form)
window.LiquidCommerce.elements.actions.checkout.setSavedPaymentMethod({
  id: 'pm_123',
  card: { brand: 'Visa', last4: '4242', expMonth: '12', expYear: '30' }
});
```

## Checkout events (examples)

```js
window.addEventListener('lce:actions.checkout_submit_completed', (event) => {
  const { orderNumber, orderTotal } = event.detail.data;
});
```
