Checkout Browser SDK lets you integrate Checkout both on regular websites and JavaScript web applications, either implemented in libraries or frameworks like React, Vue, or Angular.
- For the Complete Checkout mode, call the
checkoutFlowmethod. - For the Payment Only mode, call the
paymentFlowmethod. - For Express Payment buttons, use the
expressPaymentobject.
checkoutFlow method.Versioning
Configuration properties
checkoutFlow or paymentFlow methods.checkoutFlow or paymentFlow method:| Property | Type | Required | Description |
|---|---|---|---|
projectKey | string | Yes | Identifier of your Checkout entity and the project_key of your Project. |
sessionId | string | Yes | Identifier of the Checkout Session. |
region | string | Yes | Region where your Checkout application is hosted. For example, europe-west1.gcp. |
locale | string | No (default: en) | Your customer’s locale. If the provided locale is not found, then English will be used. |
onInfo | function | No | For more information, see onInfo, onWarn, and onError. |
onWarn | function | No | For more information, see onInfo, onWarn, and onError. |
onError | function | No | For more information, see onInfo, onWarn, and onError. |
logInfo | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
logWarn | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
logError | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
styles | object | No | Object that contains CSS variables to customize the style of Checkout. |
languageOverrides | object | No | Object that contains properties to customize the texts and labels of Checkout. |
forms | object | No | Object that contains properties to customize the address form fields of Checkout. It applies only to the checkoutFlow method. |
tax | object | No | If set as {display: true}, then the tax information from Composable Commerce is displayed in the price summary of your checkout page. It applies only to the checkoutFlow method. |
currencyLocale | string | No | Locale for which you can set the currency formatting for prices. When it is not set, locale determines the price formatting as a default. If set, the locale for price formatting is overridden. For example, if locale is set as fr, then Swiss prices are displayed as 10,00 CHF. However, if currencyLocale is set as de-CH, then Swiss prices are displayed as CHF 10.00. |
skipPaymentSuccessPage | boolean | No | If set as true, then the payment success page is not displayed. It applies only to the checkoutFlow method. |
skipPaymentErrorPage | boolean | No | If set as true, then the payment error page is not displayed. It applies only to the checkoutFlow method. |
showExtensionErrorMessages | object | No | Object that contains the address property. If set as true, then address-related extension error messages are shown in the UI. Otherwise, a generic error message will be shown. |
Browser script
<head> tags of each page on which you want to activate the start of the checkout process.@latest serves as an alias to load the latest version of the SDK.<script>
(function (w, d, s) {
if (w.ctc) {
return;
}
var js,
fjs = d.getElementsByTagName(s)[0];
var q = [];
w.ctc =
w.ctc ||
function () {
q.push(arguments);
};
w.ctc.q = q;
js = d.createElement(s);
js.type = 'text/javascript';
js.async = true;
js.src =
'https://unpkg.com/@commercetools/checkout-browser-sdk@latest/browser/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
})(window, document, 'script');
ctc('checkoutFlow', {
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
logInfo: true, // Recommended for debugging during development.
logWarn: true, // Recommended for debugging during development.
logError: true, // Recommended for debugging during development.
});
</script>
info, warn, and error Messages for debugging purposes during development. For further information, see Message subscription and logging.npm module
Prerequisites
- Node v12.22.7 (or later)
- Either npm v6 (or later) or yarn v1.22.17 (or later)
Install the SDK package
To install the SDK package, run one of the following commands:
npm install @commercetools/checkout-browser-sdkyarn add @commercetools/checkout-browser-sdk
npm script
import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
logInfo: true, // Recommended for debugging during development.
logWarn: true, // Recommended for debugging during development.
logError: true, // Recommended for debugging during development.
});
info, warn, and error Messages for debugging purposes during development. For further information, see Message subscription and logging.checkoutFlow method
checkoutFlow method to initialize the full checkout process with the related configuration.import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
locale: `{locale}`,
logInfo: true,
logWarn: true,
logError: true,
... // Other configuration properties.
});
checkoutFlow method, the Checkout UI component for the specified sessionId opens. If the customer quits the checkout process before completing it but the Checkout Session is still valid, you can call the method again with the same sessionId. If the session has expired, you can refresh it and open the component again by getting a new sessionId.checkoutFlow method, the component appears full screen in an absolutely positioned <div> element that hides other content on your page. The component renders a header with your preconfigured logo, the input fields, and the Leave checkout button. By clicking the Leave checkout button, the component disappears and the content of your page becomes visible again.<div> or <span> element with the data-ctc attribute in it (for example, <div data-ctc />). By doing so, the header and the Leave checkout button do not appear, and you can render any other content around the component, such as a custom header or footer.checkoutFlow method displays success and error pages after a payment attempt, providing customers with clear feedback about the payment outcome. You can avoid displaying these pages by passing the skipPaymentSuccessPage and skipPaymentErrorPage properties and setting them to true. The properties are independent of each other, so you can pass just one of them, or both.paymentFlow method
paymentFlow method to initialize the payment process.import { paymentFlow } from '@commercetools/checkout-browser-sdk';
paymentFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
locale: `{locale}`,
logInfo: true,
logWarn: true,
logError: true,
... // Other configuration properties.
});
paymentFlow method, the Payment UI component for the specified sessionId opens. It creates payment sessions for all active payment methods that match your payment predicates configuration, using the current Cart total amount.reloadPaymentMethods() to create new payment sessions based on the updated amount.import { paymentFlow, reloadPaymentMethods } from '@commercetools/checkout-browser-sdk';
reloadPaymentMethods();
paymentFlow method, the component appears full screen in an absolutely positioned <div> element that hides other content on your page. It is your responsibility to implement a way to close it and show the content on the page.<div> or <span> element with the data-ctc attribute in it (for example, <div data-ctc />). By doing so, you can render other content around the component, such as the shipping and billing address forms.paymentFlow method in multi-step checkouts
paymentFlow method to render the Payment UI component on a specific step of the process.Payment as the last step
The easiest way to add the Payment UI component to your checkout process is to render it as the last step of the process.
paymentFlow method after the customer has entered other checkout information. The Payment UI component will display the list of available payment integrations and a payment button.Payment as intermediate step
You can render the Payment UI component as an intermediate step of your checkout process, for example, to display an order review step before the payment.
data-ctc-selector="confirmMethod" attribute in it, together with a custom payment button, which must be deactivated or hidden.When the customer clicks the element to select the payment integration, a Payment Integration Selection Confirmation Message generates and the Payment UI component displays a summary of the payment and the selected payment integration, but the payment process will not be triggered. Therefore, to let the customer proceed to the payment, you must react to the Message by activating or displaying the custom payment button.
paymentFlow method again with the same sessionId.paymentFlow method, it is not possible to navigate to a different page, except for single-page applications (SPAs) using React Router, Angular routing, Vue Router, or similar, which allow navigation without page reloading. In such case, do not unmount the Payment UI component when navigating to a different page, as this will interrupt the payment process.Accept terms and conditions before payment
paymentFlow method, you can request the customer to accept terms and conditions before proceeding with the payment. To do so, you must provide an HTML element with a data-ctc-selector="termsAndConditionsPending" attribute in it until the customer accepts the required terms and conditions.{
areTermsAndConditionsPending ? (
<span data-ctc-selector="termsAndConditionsPending" />
) : null;
}
React to Messages
paymentFlow method, it is important to react to the Messages generated by Checkout to provide feedback to customers and handle different scenarios that may occur during the payment process.Following is an example with some Messages that you should consider reacting to.
payment_failed and payment_cancelled Messages and to give feedback to the customer about the failure. To allow the customer to retry the payment, while also ensuring the Cart has the latest version and correct total amount, call the paymentFlow method with the same sessionId again.import { paymentFlow } from '@commercetools/checkout-browser-sdk';
paymentFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
locale: `{locale}`,
logInfo: true,
logWarn: true,
logError: true,
onError: (error) => {
switch (error.code) {
case 'payment_method_loading_error':
// Store the number of failed payment integrations on the local state.
// If the number of failed payment integrations is equal to the total number of payment integrations, display a generic error message.
break;
case 'payment_failed':
// Show a payment failed message to the customer.
// Call paymentFlow method again to restart the payment flow.
break;
}
},
onInfo: (message) => {
switch (message.code) {
case 'checkout_completed':
const {
order: { id },
} = message.payload as {
order: { id: string };
};
// Redirect to confirmation page with Order ID.
break;
case 'payment_method_selection_confirmation_failed':
// Show message to customer and allow user to try again.
break;
case 'payment_method_selection_confirmation': {
const {
method: { hasVendorButton, type },
} = message.payload as {
method: { type: string; hasVendorButton: boolean };
};
// Hide custom payment button if hasVendorButton is 'true'.
break;
}
case 'payment_methods_received': {
const { paymentMethods } = message.payload as { paymentMethods: string[] };
// Store total number of payment integrations on local state.
break;
}
case 'payment_method_loaded':
// Increment loaded payment integrations.
break;
case 'payment_started':
// Show blocking overlay with spinner to avoid user interaction with the page.
// Initialize local state errors to 'false'.
break;
case 'payment_completed':
// Hide blocking overlay.
break;
case 'payment_method_selected':
const {
method: { hasVendorButton, type },
} = message.payload as {
method: { type: string; hasVendorButton: boolean };
};
// Store selected payment integration on local state and remove local payment error state.
break;
case 'payment_cancelled':
// Hide blocking overlay.
break;
case 'external_terms_and_conditions_pending':
// Show message to the customer to accept terms and conditions.
break;
}
},
});
Express Payments BETA
Express Payments use a two-step integration pattern:
- Initialize once: call
expressPayment.init()to set up the configuration and Message handlers. - Mount multiple times: call
expressPayment.mount()for each location where you want to display express payment buttons.
Express Payment configuration properties
expressPayment.init() method:| Property | Type | Required | Description |
|---|---|---|---|
projectKey | string | Yes | Identifier of your Checkout entity and the project_key of your Project. |
sessionId | string | Yes | Identifier of the Checkout Session. |
region | string | Yes | Region where your Checkout application is hosted. For example, europe-west1.gcp. |
countryCode | string | Yes | The country code of your store (ISO 3166-1 alpha-2). For example, DE. |
locale | string | No (default: en) | Your customer's locale. If the provided locale is not found, then English will be used. |
onInfo | function | No | For more information, see onInfo, onWarn, and onError. |
onWarn | function | No | For more information, see onInfo, onWarn, and onError. |
onError | function | No | For more information, see onInfo, onWarn, and onError. |
logInfo | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
logWarn | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
logError | boolean | No (default: false) | For more information, see logInfo, logWarn, and logError. |
Initialize the Express Payment
Before mounting Express Payments buttons, you must initialize the Express Payment once with your configuration. This is typically done when the page loads or when the session is created.
import { expressPayment } from '@commercetools/checkout-browser-sdk';
expressPayment.init({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
countryCode: '{countryCode}',
locale: 'en', // Optional: defaults to 'en'
logInfo: true,
logWarn: true,
logError: true,
onInfo: (message) => {
switch (message.code) {
case 'express_payment_started':
// Show blocking overlay with spinner.
break;
case 'express_payment_cancelled':
// Hide blocking overlay.
break;
case 'express_payment_completed':
// Redirect to confirmation page with Order ID.
const { order } = message.payload as { order: { id: string } };
window.location.href = '/thank-you?orderId=' + order.id;
break;
}
},
onError: (error) => {
switch (error.code) {
case 'express_payment_failed':
// Show error message to customer.
break;
}
},
});
sessionId used for Express Payments does not need to have a Cart associated with it initially. You can create or update the Cart in the onPayButtonClick callback when the customer clicks the Express Payments button.Use Express Payments with a browser script
ctc function to initialize and mount the Express Payments:<!-- Single container: use data-ctc-express without a value -->
<div data-ctc-express></div>
<script>
(function (w, d, s) {
if (w.ctc) {
return;
}
var js,
fjs = d.getElementsByTagName(s)[0];
var q = [];
w.ctc =
w.ctc ||
function () {
q.push(arguments);
};
w.ctc.q = q;
js = d.createElement(s);
js.type = 'text/javascript';
js.async = true;
js.src =
'https://unpkg.com/@commercetools/checkout-browser-sdk@latest/browser/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
})(window, document, 'script');
// Initialize Express Payment
ctc('expressPaymentInit', {
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
countryCode: '{countryCode}',
locale: 'en', // Optional: defaults to 'en'
logInfo: true,
logWarn: true,
logError: true,
onInfo: function (message) {
if (message.code === 'express_payment_completed') {
var order = message.payload.order;
window.location.href = '/thank-you?orderId=' + order.id;
}
},
onError: function (error) {
if (error.code === 'express_payment_failed') {
console.error('Express payment failed');
}
},
});
// Mount Express Payment buttons (no expressId needed for single container)
ctc('expressPaymentMount', {
initialAmount: {
type: 'centPrecision',
currencyCode: 'EUR',
centAmount: 2999,
fractionDigits: 2,
},
onPayButtonClick: function () {
// Create a Cart with the product.
// This must return a Promise.
return createCartWithProduct(productId);
},
});
</script>
expressPaymentInit and expressPaymentMount as function names instead of expressPayment.init and expressPayment.mount.Mount options
expressPayment.mount() and expressPayment.mountMethod() methods:| Property | Type | Required | Description |
|---|---|---|---|
expressId | String | No | Identifier to find a specific container with data-ctc-express="expressId". If not provided, the SDK looks for an element with just the data-ctc-express attribute. |
initialAmount | Object | Yes | The initial amount to display on the Express Payments buttons. Contains currencyCode, centAmount, fractionDigits, and optionally type (must be 'centPrecision' if provided). |
method | Object | Only for mountMethod() | The payment method to mount. Obtained from getAvailableMethods(). Contains type, paymentIntegrationId, and connectorId. |
onPayButtonClick | Function | No | Optional hook called when the customer clicks an Express Payments button. Use this to perform async operations before the checkout starts, such as creating or updating a Cart. Must return a Promise. |
onShippingAddressSelected | Function | No | Callback function called when the customer selects a shipping address in the payment sheet. Receives a partial address (country, postalCode, city, state). If not provided, the Cart is automatically updated with the partial address. |
getShippingMethods | Function | No | Callback function to provide custom shipping methods. Must return a Promise that resolves to an array of shipping options. If not provided, shipping methods are fetched automatically from Composable Commerce. |
onShippingMethodSelected | Function | No | Callback function called when the customer selects a shipping method. If not provided, the Cart is automatically updated with the selected shipping method. |
onPaymentSubmit | Function | No | Callback function called before the payment is submitted with the complete shipping and billing addresses and customer email. If not provided, the Cart is automatically updated with the addresses and email. |
Handle shipping with Express Payment
Express Payment supports two approaches for handling shipping:
Automatic shipping handling
By default, Express Payments automatically handles shipping methods based on your Composable Commerce configuration. The shipping methods matching the customer's address are displayed in the payment sheet.
Custom shipping methods
getShippingMethods and onShippingMethodSelected callbacks.import { expressPayment } from '@commercetools/checkout-browser-sdk';
expressPayment.mount({
initialAmount: {
type: 'centPrecision',
currencyCode: 'EUR',
centAmount: 2999,
fractionDigits: 2,
},
onPayButtonClick: async () => {
// Create a Cart when the customer clicks the express button.
await createCartWithProduct(productId);
},
getShippingMethods: async () => {
// Return custom shipping methods.
return [
{
id: 'standard',
name: 'Standard Shipping',
description: '5-7 business days',
amount: {
centAmount: 499,
currencyCode: 'EUR',
},
},
{
id: 'express',
name: 'Express Shipping',
description: '1-2 business days',
isSelected: true,
amount: {
centAmount: 999,
currencyCode: 'EUR',
},
},
];
},
onShippingMethodSelected: async ({ shippingMethod }) => {
// Update the Cart with the selected shipping method.
await updateCartShippingMethod(shippingMethod.id);
},
});
getShippingMethods and onShippingMethodSelected callbacks. The getShippingMethods callback is called when the payment sheet is displayed, and onShippingMethodSelected is called when the customer selects a shipping method.Handle addresses with Express Payments
Express Payments provides callbacks to handle shipping and billing addresses:
Partial address selection
onShippingAddressSelected callback is called when the customer selects a shipping address in the payment sheet. At this stage, only a partial address is available (country, postalCode, city, and state) for privacy reasons.import { expressPayment } from '@commercetools/checkout-browser-sdk';
expressPayment.mount({
initialAmount: {
type: 'centPrecision',
currencyCode: 'EUR',
centAmount: 2999,
fractionDigits: 2,
},
onShippingAddressSelected: async ({ address }) => {
// Use the partial address to calculate shipping costs or validate delivery.
console.log('Partial address:', address.country, address.postalCode);
},
});
Complete address handling
onPaymentSubmit callback is called before the payment is submitted and provides the complete shipping and billing addresses along with the customer email. Use this callback to perform final Cart updates or validations.import { expressPayment } from '@commercetools/checkout-browser-sdk';
expressPayment.mount({
initialAmount: {
type: 'centPrecision',
currencyCode: 'EUR',
centAmount: 2999,
fractionDigits: 2,
},
onPaymentSubmit: async ({ shippingAddress, billingAddress, customerEmail }) => {
// Update the Cart with the complete addresses and customer email.
await updateCartAddresses(shippingAddress, billingAddress);
await updateCartEmail(customerEmail);
},
});
onPaymentSubmit callback, the Cart is automatically updated with the shipping and billing addresses and customer email received from the payment provider.React to Express Payments Messages
import { expressPayment } from '@commercetools/checkout-browser-sdk';
expressPayment.init({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
countryCode: '{countryCode}',
onInfo: (message) => {
switch (message.code) {
case 'express_payment_started':
// Customer clicked an express payment button.
// Show blocking overlay with spinner.
break;
case 'express_payment_cancelled':
// Customer cancelled the express payment.
// Hide blocking overlay.
break;
case 'express_payment_interrupted':
// Express payment was interrupted by the seller's callback.
// Hide blocking overlay.
break;
case 'express_payment_completed':
// Express payment completed successfully.
const { order } = message.payload as { order: { id: string } };
window.location.href = '/thank-you?orderId=' + order.id;
break;
}
},
onError: (error) => {
switch (error.code) {
case 'express_payment_failed':
// Express payment failed.
// Show error message to customer.
break;
case 'no_express_payment_integrations':
// No express payment integrations are configured.
// Hide express buttons container.
break;
case 'express_container_not_found':
// The container element was not found.
break;
case 'express_multiple_containers_found':
// Multiple elements with data-ctc-express attribute found.
// Use expressId to specify which container to use.
break;
case 'express_payment_integration_not_available':
// The requested payment integration is not available.
// This can happen when using mountMethod() with an unavailable method.
break;
}
},
});
express_payment_failed and express_payment_cancelled Messages and to give feedback to the customer. Unlike the checkoutFlow and paymentFlow methods, Express Payment does not display error pages automatically.Complete Express Payments example
mount() to render all buttons in a single container:<!-- Single container for all express buttons -->
<div data-ctc-express></div>
import { expressPayment } from '@commercetools/checkout-browser-sdk';
// Initialize Express Payment once when the page loads.
const initializeExpressPayment = (sessionId: string) => {
expressPayment.init({
projectKey: '{projectKey}',
region: '{region}',
sessionId: sessionId,
countryCode: 'DE',
locale: 'de-DE', // Optional: defaults to 'en'
logInfo: true,
logWarn: true,
logError: true,
onInfo: (message) => {
switch (message.code) {
case 'express_payment_started':
showBlockingOverlay();
break;
case 'express_payment_cancelled':
hideBlockingOverlay();
break;
case 'express_payment_completed':
hideBlockingOverlay();
const { order } = message.payload as { order: { id: string } };
window.location.href = '/thank-you?orderId=' + order.id;
break;
}
},
onError: (error) => {
hideBlockingOverlay();
if (error.code === 'express_payment_failed') {
showErrorMessage('Express payment failed. Please try again.');
}
},
});
};
// Mount express buttons (no expressId needed for single container).
const mountExpressButtons = (product: { id: string; price: number; currency: string }) => {
expressPayment.mount({
initialAmount: {
type: 'centPrecision',
currencyCode: product.currency,
centAmount: product.price,
fractionDigits: 2,
},
onPayButtonClick: async () => {
// Create a Cart with the product.
await createCartWithProduct(product.id);
},
getShippingMethods: async () => {
return getAvailableShippingMethods(product.currency);
},
onShippingMethodSelected: async ({ shippingMethod }) => {
await setCartShippingMethod(shippingMethod.id);
},
});
};
close method
close method to close the Checkout or the Payment UI component when it is not needed. Calling the close method is recommended over unmounting the component, as it ensures that the necessary cleanup is performed.paymentFlow method, where the customer decides to edit the information entered in a previous step. In such cases, you can use the close method to close the payment UI component.Once the customer moves the payment step again, you can call the
paymentFlow method with the same sessionId to render the Payment UI component again.checkoutFlow method.import { close } from '@commercetools/checkout-browser-sdk';
close();
Return URL
You can set only one return URL per Connector. If you want to use the same Connector with multiple domains, you must create different Applications in the Merchant Center and override the return URL.
paymentReference parameter is added to the return URL with the id of the Payment as its value, and the customer returns to your website. Now, you must call the checkoutFlow or paymentFlow method again by providing the same configuration parameters as before along with the paymentReference.import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
region: '{region}',
projectKey: '{projectKey}',
sessionId: '{sessionId}',
locale: '{locale}',
logInfo: true,
logWarn: true,
logError: true,
paymentReference: '{paymentReference}',
});
checkoutFlow or paymentFlow method again, the UI component appears and displays a loading status while the payment is verified. If the payment is successful, the checkout process is complete. Otherwise, the customer is prompted to either quit the checkout process or try again by editing the entered information.Checkout completion
checkoutFlow and the paymentFlow method.For example, you can react to the Message to display feedback for the customer on your website, such as a message or a dialog. Or, you can use the Message to redirect the customer to a different page, such as a Thank You page.
import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
onInfo: (message) => {
if (message.code === 'checkout_completed') {
const {
order: { id },
} = message.payload as {
order: { id: string };
};
window.location.href = '/thank-you?orderId=' + id;
}
},
});
Retry order verification
retryOrderVerification method.import { retryOrderVerification } from '@commercetools/checkout-browser-sdk';
retryOrderVerification();
Message subscription and logging
You can handle Messages by using:
onInfo, onWarn, and onError
info, warn, or error Messages by passing the optional onInfo, onWarn, or onError message handlers with the checkoutFlow or paymentFlow methods. The handlers will receive the Message as a parameter.info Messages and log a Received note followed by the Message code on the browser's developer console.import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
onInfo: (message) => {
console.error('Received: ' + message.code);
},
});
<script>
(function (w, d, s) {
if (w.ctc) {
return;
}
var js,
fjs = d.getElementsByTagName(s)[0];
var q = [];
w.ctc =
w.ctc ||
function () {
q.push(arguments);
};
w.ctc.q = q;
js = d.createElement(s);
js.type = 'text/javascript';
js.async = true;
js.src =
'https://unpkg.com/@commercetools/checkout-browser-sdk@latest/browser/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
})(window, document, 'script');
ctc('checkoutFlow', {
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
onInfo: function (message) {
console.error('Received: ' + message.code);
},
});
</script>
logInfo, logWarn, and logError
logInfo, logWarn, and logError methods to log Messages in the console for debugging purposes. We recommend not activating them in production since, usually, these logs are not useful for end users.info and error Messages, but not the warn ones.import { checkoutFlow } from '@commercetools/checkout-browser-sdk';
checkoutFlow({
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
logInfo: true,
logWarn: false,
logError: true,
});
<script>
(function (w, d, s) {
if (w.ctc) {
return;
}
var js,
fjs = d.getElementsByTagName(s)[0];
var q = [];
w.ctc =
w.ctc ||
function () {
q.push(arguments);
};
w.ctc.q = q;
js = d.createElement(s);
js.type = 'text/javascript';
js.async = true;
js.src =
'https://unpkg.com/@commercetools/checkout-browser-sdk@latest/browser/sdk.js';
fjs.parentNode.insertBefore(js, fjs);
})(window, document, 'script');
ctc('checkoutFlow', {
projectKey: '{projectKey}',
region: '{region}',
sessionId: '{sessionId}',
logInfo: true,
logWarn: false,
logError: true,
});
</script>