Skip to main content

Init options

These options are passed to initCheckout() (framework SDKs) or Commercengine.init() / new Checkout() (vanilla JS).

Credentials

OptionTypeDefaultDescription
storeIdstringYour Commerce Engine Store ID. Required unless url is provided.
apiKeystringYour Commerce Engine API Key. Required unless url is provided (or already embedded in url).
environment"production" | "staging""production"Determines which subdomain pattern is used: https://{storeId}.checkout.commercengine.com or https://{storeId}.staging.checkout.commercengine.com.
urlstringOverride checkout host resolution (local dev, preview builds, custom domains). If host is localhost and storeId is passed, SDK rewrites to a store-scoped host automatically.

Appearance

OptionTypeDefaultDescription
theme"light" | "dark" | "system""system"Per-session theme override for checkout UI. Primary visual config is managed in Checkout Studio.
appearance.zIndexnumber99999z-index for the checkout overlay container.

Authentication

OptionTypeDefaultDescription
authMode"managed" | "provided""managed""managed": checkout handles its own auth. "provided": your app manages tokens and syncs them to checkout (recommended when your storefront already uses Storefront SDK auth).
accessTokenstringInitial access token (JWT). Used with authMode: "provided".
refreshTokenstringInitial refresh token. Used with authMode: "provided".
When to use authMode: "provided"Use this when your app already has its own login system and you want checkout to share the same session. Pass tokens at init and call updateTokens() when they change.

Quick Buy

OptionTypeDefaultDescription
quickBuyobjectOpen checkout directly for a specific product.
quickBuy.productIdstringProduct ID. Required when using quickBuy.
quickBuy.variantIdstring | nullVariant ID, or null for products without variants. Required when using quickBuy.
quickBuy.quantitynumber1Quantity to add.
sessionMode"continue-existing" | "force-new""continue-existing"Whether to continue the user’s existing cart or start fresh.
autoDetectQuickBuybooleanfalseAutomatically detect quick buy params from the parent URL. The SDK will clean up the URL params after detection.

Managed in Checkout Studio

The following settings are configured remotely in Checkout Studio (Config API) and injected into checkout on each page load:
  • Feature flags (loyalty, coupons, collectInStore, freeShippingProgress, productRecommendations)
  • Login configuration (enabled methods, account switch behavior)
  • Drawer direction (mobile/desktop)
  • Payment provider selection
  • Brand appearance tokens (colors, typography, shape system, sizing)
These are intentionally not part of the SDK init options.

Configuration precedence (source of truth)

SettingPrimary sourceRuntime overrideNotes
Features, login methods, drawer direction, payment provider, appearance tokensCheckout StudioNone via SDK init optionsSaved config is fetched and applied by Hosted Checkout
Theme modeCheckout Studio default (ui.theme)theme in SDK initSDK theme is a per-session override
Auth tokensParent app / checkout auth flowaccessToken, refreshToken, updateTokens()Depends on authMode
Quick buy behaviorSDK init options / parent URL (if auto-detect enabled)quickBuy, sessionMode, autoDetectQuickBuyRequest-scoped behavior
Checkout host resolutionstoreId + environmenturlurl fully overrides host resolution

Methods

These methods are available on the checkout instance (vanilla JS) or returned by the framework hook/composable.
MethodDescription
openCart()Open the cart drawer.
openCheckout()Open the checkout directly, skipping the cart drawer.
close()Close the checkout overlay.
addToCart(productId, variantId, quantity?)Add an item. variantId can be null. quantity defaults to 1.
updateTokens(accessToken, refreshToken?)Sync auth tokens from your app into checkout.
getCart()Returns { count, total, currency }. Vanilla JS only.
getTokens()Returns latest { accessToken, refreshToken } received via auth:tokens-updated, or null if not received yet. Vanilla JS only.
destroy()Remove the iframe and clean up all listeners. Vanilla JS only.

Runtime properties (vanilla JS)

PropertyTypeDescription
readybooleantrue when iframe initialization has completed (or surfaced an error state).
openbooleantrue when the checkout overlay is visible.

Events

When using the vanilla JS SDK (@commercengine/js), you can listen to events with checkout.on(event, handler):
EventPayloadDescription
readyIframe loaded and ready.
openOverlay became visible.
closeOverlay was closed.
complete{ id, orderNumber }Order placed.
cart:updated{ count, total, currency }Cart changed.
auth:tokens-updated{ accessToken, refreshToken }Tokens changed (anonymous auth, login, logout, refresh).
auth:login{ user, loginMethod }User logged in (semantic event).
auth:logout{ user }User logged out (semantic event).
auth:session-errorSession invalid, tokens cleared.
error{ message }Error occurred.
checkout.on("complete", (order) => {
  console.log("Order:", order.orderNumber);
});

// Listen once
checkout.once("ready", () => {
  console.log("Checkout loaded");
});

// Remove listener
const handler = (cart) => console.log(cart.count);
checkout.on("cart:updated", handler);
checkout.off("cart:updated", handler);
If your storefront already uses @commercengine/storefront-sdk, run Hosted Checkout in provided mode and wire token sync both ways:
import StorefrontSDK, { BrowserTokenStorage } from "@commercengine/storefront-sdk";
import { initCheckout, getCheckout } from "@commercengine/checkout";

const tokenStorage = new BrowserTokenStorage("ce_");

const storefront = new StorefrontSDK({
  storeId: "store_xxx",
  apiKey: "ak_xxx",
  tokenStorage,
  onTokensUpdated: (accessToken, refreshToken) => {
    // SDK -> checkout
    getCheckout().updateTokens(accessToken, refreshToken);
  },
});

const accessToken = await tokenStorage.getAccessToken();
const refreshToken = await tokenStorage.getRefreshToken();

initCheckout({
  storeId: "store_xxx",
  apiKey: "ak_xxx",
  authMode: "provided",
  accessToken: accessToken ?? undefined,
  refreshToken: refreshToken ?? undefined,
  onTokensUpdated: ({ accessToken, refreshToken }) => {
    // checkout -> SDK
    storefront.setTokens(accessToken, refreshToken);
  },
});

Environment URLs

EnvironmentCheckout App URL Pattern
productionhttps://{storeId}.checkout.commercengine.com
staginghttps://{storeId}.staging.checkout.commercengine.com
The SDK is hosted at https://cdn.commercengine.com/v1.js (single deployment). The environment option selects the hostname pattern, and storeId is encoded in the subdomain.