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.
environment"production" | "staging""production"Determines which checkout app URL is loaded.
urlstringOverride the checkout URL. Useful for local development (e.g. http://localhost:8080).

Appearance

OptionTypeDefaultDescription
theme"light" | "dark" | "system""system"Theme preference for the checkout UI.
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.
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.

Feature Flags

OptionTypeDefaultDescription
features.loyaltybooleantrueShow loyalty points redemption.
features.couponsbooleantrueShow coupon code input.
features.collectInStorebooleanfalseEnable collect-in-store fulfillment option.
features.freeShippingProgressbooleantrueShow free shipping progress bar.
features.productRecommendationsbooleantrueShow product recommendations in cart.

Callbacks

CallbackPayloadDescription
onReadyCheckout iframe is loaded and ready.
onOpenCheckout overlay became visible.
onCloseCheckout overlay was closed.
onComplete{ id, orderNumber }Order was placed successfully.
onCartUpdate{ count, total, currency }Cart contents changed.
onLogin{ accessToken, refreshToken, user, loginMethod }User logged in. loginMethod is "whatsapp", "phone", or "email".
onLogout{ accessToken, refreshToken, user }User logged out.
onTokenRefresh{ accessToken, refreshToken }Tokens were automatically refreshed.
onSessionErrorSession became invalid. All tokens are cleared.
onError{ message }A configuration or runtime error occurred.

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.
destroy()Remove the iframe and clean up all listeners. Vanilla JS only.

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:login{ accessToken, refreshToken, user, loginMethod }User logged in.
auth:logout{ accessToken, refreshToken, user }User logged out.
auth:refresh{ accessToken, refreshToken }Tokens refreshed.
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);

Environment URLs

EnvironmentCheckout App URL
productionhttps://checkout.commercengine.com
staginghttps://staging.checkout.commercengine.com
The SDK is hosted at https://cdn.commercengine.com/v1.js (single deployment). The environment option only changes which checkout app URL is loaded inside the iframe.