Checkout SDK — a set of tools for integrating payment functionality on the frontend.
Main capabilities:
parentUrl for correct processing of payments with 3DS verification.Add the SDK script to your HTML document:
<script src="https://{ENVIROMENT}/checkout-sdk.umd.js"></script>Possible ENVIRONMENT values:
checkout-sdk-sandbox.billerbase.comcheckout-sdk.billerbase.comThe 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});checkoutUrl (required):A link to the checkout page received from the billing system when the order is created.
priceCalculationType query parameter to checkoutUrl with the values daily | weekly | monthly | none to change how prices are displayed in the checkout.debug (optional):'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.'warn'.boolean): enables logging of checkout events to the browser console.false.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.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});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.
userAgent;email field.true — the field will be hidden; false — the field will be displayed (default behavior).The checkout.unmount method is used to remove the checkout from the DOM. Subscriptions to events associated with it are preserved.
CheckoutSDK.checkout.unmount();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();submit on the checkout form.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});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).
The checkout.events object provides methods for working with checkout events. You can subscribe to events coming from the checkout.
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});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.
An object with the unsubscribe method, which allows you to cancel the subscription to the event.
subscription.unsubscribe();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.
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);The unsubscribeAll method is used to remove all subscriptions to checkout events.
CheckoutSDK.checkout.events.unsubscribeAll();checkout.events.subscribe.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();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}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}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}Triggered when the user changes the payment method in the checkout.
1{
2 paymentMethod: PaymentMethodName;
3}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}Triggered when the Submit button changes its loading state. This happens, for example, during card BIN validation.
1{
2 isLoading: boolean;
3}Triggered at the start of payment processing.
1{
2 paymentMethod: PaymentMethodName;
3}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}Triggered when a validation error occurs in the checkout form.
1{
2 fieldErrors: Record<string, {
3 type: string;
4 message?: string;
5 }>
6}Triggered when the payment is declined.
1{
2 paymentMethod: PaymentMethodName;
3 reason: string;
4}Triggered when an unexpected error occurs during payment processing.
1{
2 error: string;
3 paymentMethod: PaymentMethodName;
4}Triggered when the PayPal overlay is opened.
1nullTriggered when the PayPal overlay is closed.
1nullPaymentMethodName: '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 SDKThe 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.
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();cleanup is called, the SDK instance can no longer be used. To use it again, you need to create a new instance via initCheckoutSDK.