JS Lite Checkout
Tonder’s JS SDK Lite Checkout gives you freedom to build your own checkout interface while taking advantage of our core functionalities. 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:
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:
Initialize Tonder's SDK Instance
Initialize Tonder’s JS SDK instance with the following parameters:
Field | Description |
---|---|
mode | Environment mode. Options: stage , production , sandbox . Default: stage |
apiKey | The API key used for authentication and authorization. |
returnUrl | The URL to which the user is redirected after the checkout process, regardless of success or failure. |
customization | This 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. |
styles | Custom 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. |
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.
Inject checkout method
Call the injectCheckout
method with your inlineCheckout instance, with the code below:
With this, you can render the checkout to your customers.
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 liteCheckout
instance, sending the checkout data as payload, like presented below:
After Completing these steps, you can use the Lite Checkout available methods to manage your user’s experience.
Class Methods
With your Lite Checkout instance configured, you’ll have at your disposal the following methods:
Cards
Tonder’s SDK offers the following methods to manage customer cards:
getCustomerCards
saveCustomerCard
removeCustomerCard
secureToken
to be able to manage cards with Tonder’s SDK. Refer to the How to Use secureToken for Secure Card Saving to learn how to do this.Get Customer Cards
Use the getCustomerCards
method to retrieve previously saved customer cards:
Save Customer Card
Use the saveCustomerCard
method to save a new card into the system. This method requires an object as parameter to define the card’s properties:
Sure! Here’s a markdown table with the keys and their descriptions:
Key | Description |
---|---|
card_number | The credit card number without spaces or dashes. |
cvv | The card verification value, a 3 or 4-digit code. |
expiration_month | The month when the card expires. |
expiration_year | The year when the card expires. |
cardholder_name | The full name of the cardholder as on the card. |
Remove Customer Card
Use the removeCustomerCards
method to delete a previously saved customer card by passing the card ID as parameter:
Get Customer Payment Methods
Use this method to retrieve the customer previously registered payment methods:
Payment
To create a new payment with the Lite SDK, use the payment
method. This method requires an object as parameter with the following data:
Key | Description |
---|---|
customer | An object containing customer information |
cart | An object containing cart and item details |
currency | The currency code for the transaction (e.g., “MXN”) |
metadata | An object for additional metadata (e.g., order ID) |
card | An object containing card details for a new card |
payment_method | The selected payment method (optional) |
3DS Verification
You can use the verify3dsTransaction()
method to validate if a 3DS challenge was successful or not. Use the example below to call the method and handle the response as needed:
Field Validation
Tonder’s SDK provides validation functions to ensure the integrity of card data before submitting them:
Function | Description |
---|---|
validateCardNumber(cardNumber) | Validates the card number using the Luhn algorithm. |
validateCardholderName(name) | Checks if the cardholder name is valid. |
validateCVV(cvv) | Ensures the CVV is in the correct format. |
validateExpirationDate(expirationDate) | Validates the expiration date in MM/YY format. |
validateExpirationMonth(month) | Checks if the expiration month is valid. |
validateExpirationYear(year) | Validates the expiration year. |
Full Integration Example
For full integration example codes, refer to the Code Examples page.