Checkout SDK

Checkout SDK — a set of tools for integrating payment functionality on the frontend.

Main capabilities:

  1. creation of a DOM element with the checkout (hereinafter – the checkout);
  2. tracking events inside the checkout (for example, start of payment processing, change of payment method, etc.);
  3. triggering events inside the checkout (for example, being able to have a Submit button outside the iframe and trigger the payment submit on your page by programmatically passing the click into the iframe);
  4. automatic adjustment of the checkout size according to its content.

Important

  1. Minimum recommended flow for testing the integration:
    a. creation/deletion of the iframe;
    b. changing the payment method, correct display of the list of payment methods;
    c. form validation working in relation to the events you are subscribed to;
    d. payments with all payment methods, with and without 3DS;
    e. triggering submit if the button is on your side;
    f. correct handling of events that have a blocking nature for different parts of the interface (various “processing”, “loading”, etc. states);
    g. correct analytics;
    h. applying coupons when creating the checkout.
  2. The old way of integrating the iframe directly and manually handling events from window will continue to work for some time for backward compatibility while the migration to Checkout SDK is in progress, but it will no longer receive updates, only security or critical bug fixes.
  3. When creating an order, it is important to pass parentUrl for correct processing of payments with 3DS verification.
SDK integration

Add the SDK script to your HTML document:

 <script src="https://{ENVIROMENT}/checkout-sdk.umd.js"></script>

Possible ENVIRONMENT values:

  1. SANDBOX - checkout-sdk-sandbox.billerbase.com
  2. PROD - checkout-sdk.billerbase.com
SDK initialization

The initCheckoutSDK function is used to initialize the SDK. It configures all required subscriptions, event handlers, and settings for working with the checkout.

1const CheckoutSDK = initCheckoutSDK({
2  checkoutUrl: 'https://cart.example.com/initial-billing/${orderId}',
3  debug?: {
4    logLevel: 'info',
5    logCheckoutEvents: true,
6  },
7});
Parameters
checkoutUrl (required):

A link to the checkout page received from the billing system when the order is created.

  • You can add the priceCalculationType query parameter to checkoutUrl with the values daily | weekly | monthly | none to change how prices are displayed in the checkout.
debug (optional):
  • logLevel ('info' | 'warn' | 'error'):
    - 'info': outputs errors, warnings, and low-priority messages to the console that may be useful during integration or debugging;
    - 'warn': outputs only warnings and errors;
    - 'error': outputs errors only.
    Default: 'warn'.
  • logCheckoutEvents (boolean): enables logging of checkout events to the browser console.
    Default: false.
Notes
  1. At the moment, one SDK instance can create only one checkout. Therefore, if you need to have several checkouts on the page at the same time, you must create separate instances for each of them. Each instance works independently and their events are isolated.
  2. The value of checkoutUrl must match the URL that is currently used for directly creating an iframe with the checkout. This guarantees correct operation of the payment flow and predictable behavior.
SDK methods
1. checkout.mount

The checkout.mount method is used to add the checkout to the specified container in the DOM.

1CheckoutSDK.checkout.mount({
2  containerId: 'checkout-container', // Container identifier
3  options: {
4    selectedPaymentMethod: 'pay_pal',
5    coupon: 'COUPON123',
6    language: 'en',
7    autocharge: false,
8    mobileView: true,
9    hideFields: { email: true },
10  },
11});
Parameters
containerId (required):

Identifier of the DOM element to which the checkout will be attached. The container must exist in the DOM before the method is called. The checkout will automatically change its height according to content changes, so the container must be able to grow in both height and width; otherwise there is a risk of unwanted scrollbars appearing.

options (optional):

A set of parameters applied when the checkout is loaded.

  • selectedPaymentMethod (string): this parameter conflicts with the billing logic and currently exists only to preserve backward compatibility for the merchant Lasta; its use is not recommended.
  • coupon (string)
  • language (string)
  • autocharge (boolean)
  • mobileView (boolean)
    - forces the mobile layout to be used; otherwise, checking whether the device is mobile is done via the userAgent;
    - can be useful if on desktop the checkout container width is the same as in the mobile view.
  • hideFields (object)
    - an object with fields that must be hidden on the form during checkout rendering. Currently this is only the email field.
    - the key is the field name, and the value is a boolean: true — the field will be hidden; false — the field will be displayed (default behavior).
2. checkout.unmount

The checkout.unmount method is used to remove the checkout from the DOM. Subscriptions to events associated with it are preserved.

CheckoutSDK.checkout.unmount();
3. checkout.submit

The checkout.submit method is used to submit the form inside the checkout. It is required in cases when you need to have your own Submit button outside the checkout.

CheckoutSDK.checkout.submit();
Notes
  1. This method calls submit on the checkout form.
  2. Before calling the method, make sure that the checkout is mounted and ready to work
4. checkout.update

The checkout.update method is used to change checkout data.

1CheckoutSDK.checkout.update({
2  language: "de",
3  autocharge: false,
4  hideFields: {
5    email: true,
6  },
7});
Parameters
language (string)

Changes the language.

autocharge (boolean)

Enables or disables automatic subscription renewal.

hideFields (object)

An object with fields that must be hidden on the form during checkout rendering. Currently this is only the email field. The key is the field name, and the value is a boolean: true — the field will be hidden; false — the field will be displayed (default behavior).

5. checkout.events

The checkout.events object provides methods for working with checkout events. You can subscribe to events coming from the checkout.

5.1. checkout.events.subscribe

The subscribe method is used to subscribe to events coming from the checkout.

1CheckoutSDK.checkout.update({
2  language: "de",
3  autocharge: false,
4  hideFields: {
5    email: true,
6  },
7});
Parameters
type (string)

The name of the event to subscribe to. See the “Available events” table.

handler (function)

A function that will be called when the event is received, with the payload object passed as an argument.

Returns

An object with the unsubscribe method, which allows you to cancel the subscription to the event.

subscription.unsubscribe();
Parameters
type (string)

The name of the event to subscribe to. See the “Available events” table.

handler (function)

A function that will be called when the event is received, with the payload object passed as an argument.

Important

Use subscribe to subscribe to events coming from the checkout instead of directly listening to the message event, as in the previous implementation.

Current implementation of handling messages from the checkout:

1window.addEventListener('message', (event) => {
2  if (event.data.type === 'changePaymentMethod') {
3    const payload = event.data.payload;
4    // Event handling
5  }
6})

Receiving events from the checkout via CheckoutSDK:

1const subscription = CheckoutSDK.checkout.events.subscribe(
2  'changePaymentMethod',
3  (payload) => {
4    console.log('Подія checkout:', payload); 
5    // Event data handling
6  }
7);
5.2. checkout.events.unsubscribeAll

The unsubscribeAll method is used to remove all subscriptions to checkout events.

CheckoutSDK.checkout.events.unsubscribeAll();
Notes
  1. Use this method to clear all subscriptions, for example before removing the checkout or when finishing work with the SDK.
  2. The method automatically removes all subscriptions created via checkout.events.subscribe.
General example of using subscriptions:
1// Subscribing an event handler
2const readySubscription = CheckoutSDK.checkout.events.subscribe(
3  'ready',
4  (payload) => {
5    console.log('checkout готовий:', payload);
6  }
7);
8
9
10// Cancelling handling of the `ready` event
11readySubscription.unsubscribe();
12
13// Removing all subscriptions for all events
14CheckoutSDKinstanse.checkout.events.unsubscribeAll();
Available events
Type
Description
Payload
ready

Triggered when the checkout content is fully loaded and ready for interaction. Contains information about the selected payment method, the autocharge status, and the URL that is used in the src attribute of the iframe.

1{ 
2  paymentMethod: PaymentMethodName; 
3  autocharge: boolean; 
4  iframeUrl: string; 
5}
payButtonReady

It is triggered when the payment button (Apple Pay, Google Pay, or PayPal) is displayed and ready to be clicked by the user.

1{ 
2  paymentMethod: 'apple_pay' | 'google_pay' | 'pay_pal'; 
3}
redirect

Triggered when the checkout requests a redirect to another URL.
redirectUrl – the URL to which the user must be redirected.
shouldOpenInNewTab – indicates whether the link should be opened in a new browser tab.

1{ 
2  redirectUrl: string; 
3  shouldOpenInNewTab: boolean; 
4}
changePaymentMethod

Triggered when the user changes the payment method in the checkout.

1{ 
2  paymentMethod: PaymentMethodName; 
3}
submit

Triggered when the user clicks the Submit button that initiates the payment process, including for payment methods such as Apple Pay, Google Pay, and PayPal. Also fires when checkout.submit is called.

1{ 
2  paymentMethod: PaymentMethodName; 
3  validationPassed: boolean;
4}
submitButtonLoading

Triggered when the Submit button changes its loading state. This happens, for example, during card BIN validation.

1{ 
2  isLoading: boolean;
3}
paymentProcessingStart

Triggered at the start of payment processing.

1{ 
2  paymentMethod: PaymentMethodName; 
3}
paymentProcessingFinish

Triggered after payment processing is completed. Contains information about the payment status at the moment processing finishes.

1type PaymentProcessingFinishPayload  = 
2| { 
3  status: 'success'; 
4  paymentMethod: PaymentMethodName;
5  orderId: string;
6  email: string;
7}   
8| {
9  status: 'failed';
10  paymentMethod: PaymentMethodName;
11  reason?: string;
12}
formValidationError

Triggered when a validation error occurs in the checkout form.

1{ 
2  fieldErrors: Record<string, { 
3    type: string; 
4    message?: string; 
5  }> 
6}
paymentDeclined

Triggered when the payment is declined.

1{ 
2  paymentMethod: PaymentMethodName; 
3  reason: string; 
4}
error

Triggered when an unexpected error occurs during payment processing.

1{ 
2  error: string; 
3  paymentMethod: PaymentMethodName; 
4}
paypalOverlayOpen

Triggered when the PayPal overlay is opened.

1null
paypalOverlayClosed

Triggered when the PayPal overlay is closed.

1null
Common types:
PaymentMethodName: 'card' | 'spei' | 'sofort' | 'boleto' | 'ideal' | 'wechat' | 'alipay' | 'pix' | 'paytm' | 'paysafecard' | 'google_pay' | 'apple_pay' | 'pay_pal' | 'boleto_flash' | 'oxxo' | 'mercado_pago' | 'wire_transfer' | 'web_pay' | 'upi' | 'pay_with_crypto'
cleanup method: Shutting down the SDK

The cleanup method is used to shut down the SDK. It clears all resources created while the SDK is running, including removing the checkout, clearing event subscriptions, and unsubscribing from messages. This method ensures that the SDK does not leave any active subscriptions or resources after it finishes.

What it does
  • Removes the checkout from the DOM.
  • Clears all subscriptions to checkout events.
Usage example
1const CheckoutSDK = initCheckoutSDK({
2  checkoutUrl: 'https://cart.example.com/initial-billing/${orderId}',
3  debug: { logLevel: 'info', logCheckoutEvents: true },
4});
5
6// call the cleanup method to clear the SDK
7CheckoutSDK.cleanup();
Notes
  1. After cleanup is called, the SDK instance can no longer be used. To use it again, you need to create a new instance via initCheckoutSDK.