Tonder’s JS SDK Inline Checkout brings you a easy to integrate, pre-built, customizable interface. This guide will take you step-by-step into integrating it.

If you haven’t installed and pre-configured Tonder’s JS SDK, refer to the Installation guide here.

Configuration

Before initializing an instance of Tonder SDK, ensure that you have configured it properly. Follow the usage example below:

1

Add the required ID to your HTML

Tonder’s JS SDK needs an entry point to operate. This entry point is defined by adding a tonder-checkout ID to an empty div, like the example below:

<div>
    <h1>Checkout</h1>
    <!-- You have to add an entry point with the ID 'tonder-checkout' -->
    <div id="tonder-checkout">
    </div>
</div>
2

Initialize Tonder's SDK Instance

Initialize Tonder’s JS SDK instance with the following parameters:

FieldDescription
modeEnvironment mode. Options: stage, production, sandbox. Default: stage
apiKeyThe API key used for authentication and authorization.
returnUrlThe URL to which the user is redirected after the checkout process, regardless of success or failure.
customizationThis object is designed to customize the behavior of the checkout. It is used to adjust both the interface options and operational parameters. Refer to the Customizations section for more details.
stylesCustom styles object that allows you to customize the appearance of the inline checkout. It may include properties such as colors, fonts, and other styling options. Refer to the Styling section for more details.
3

Configure checkout method (Optional)

You can use the configureCheckout method to set initial customer information, such as their email address, allowing to retrieve the respectives user’s saved cards.

inlineCheckout.configureCheckout({ customer: { email: "example@email.com" } });
4

Inject checkout method

Call the injectCheckout method with your inlineCheckout instance, with the code below:

inlineCheckout.injectCheckout();

This method will use the element with id tonder-checkout added in Step 1 to render the checkout elements, as exemplified by the image below:

With this, you can render the checkout to your customers.

5

Add 3DS verification

Use Tonder’s SDK verify3dsTransaction() method to validate if the 3DS challenge was successful or not. Use the example below to call the method and handle the response as needed:

inlineCheckout.verify3dsTransaction().then(response => {
  console.log('Verify 3ds response', response);
  
  if (response.transaction_status === 'Success') {
    alert('3DS Transaction verified.');
    // Proceed with normal payment flow
  } else if (response.transaction_status === 'Failed') {
    alert('3DS Transaction Failed');
  }
});
6

Add a pay button

Lastly, you need to create a button to submit the form. This button needs to have an event listener that calls the payment method from the inlineCheckout instance, sending the checkout data as payload, like presented below:

document.getElementById('your-pay-button').addEventListener('click', async () => {
  try {
    response = await inlineCheckout.payment(checkoutData);
    if (response.transaction_status === 'Success') {
      alert('Payment successful.');
    } else if (response.transaction_status === 'Pending') {
      alert('Payment pending. Redirecting to 3DS...');
      // The redirection to 3DS occurs automatically
    } else {
      alert('Payment declined.');
    }
  } catch (error) {
    alert('Error with payment.');
  }
});

Checkout data

The payment function payload needs to be an object with detailed information about the customer, currency and cart. Below you find details abou each needed field:

Checkout data example

Below you find an example of a checkout data object:

Customizations

Tonder’s SDK customization object allows you to personalize the checkout behavior. You can change the following properties:

Styling

To learn how you can add your own styles to the checkout elements, refer to the SDK Styles page.

Full Integration Example

For full integration example codes, refer to the Code Examples page.