Documentation Index
Fetch the complete documentation index at: https://www.commercengine.io/docs/llms.txt
Use this file to discover all available pages before exploring further.
NPM Package
@commercengine/checkout
React integration for Commerce Engine Checkout.
Installation
Setup
CallinitCheckout once at your app’s entry point. This creates a hidden iframe in the background — it does not block rendering. The SDK resolves the hosted URL from storeId + environment using store-specific subdomains.
App.tsx
initCheckout should be called once at the top level of your app, outside of any component. It is safe to call in SSR environments — it no-ops on the server.Feature flags, login methods, drawer direction, and payment provider are managed in Checkout Studio (Config API), not as SDK init options. Use
theme only for per-session overrides.Use the hook
useCheckout() returns reactive state and action methods. No context provider is needed.
CartButton.tsx
Full example
App.tsx
Next.js
For Next.js, callinitCheckout in a client component:
providers.tsx
layout.tsx
useCheckout() in any client component as usual.
Syncing external auth
If your app manages its own authentication, pass tokens to keep checkout in sync:authMode: "provided" in the init config when using external auth:
Hook API reference
useCheckout() returns:
| Property | Type | Description |
|---|---|---|
isReady | boolean | true when the checkout iframe is loaded and ready |
isOpen | boolean | true when the checkout overlay is visible |
cartCount | number | Number of items in the cart |
cartTotal | number | Cart subtotal |
cartCurrency | string | Currency code (e.g. "INR") |
isLoggedIn | boolean | Whether a user is logged in |
user | UserInfo | null | Current user info (decoded from JWT) |
openCart() | function | Open the cart drawer |
openCheckout() | function | Open checkout directly (skips cart) |
close() | function | Close the overlay |
addToCart(productId, variantId, quantity?) | function | Add an item to the cart |
updateTokens(accessToken, refreshToken?) | function | Sync auth tokens from your app |
