Custom JavaScript Checkout integration steps
Perform the following steps to complete a custom JavaScript Checkout integration:
Copy the Zonos JavaScript snippet
You can retrieve your Zonos JavaScript snippet via Dashboard:
- Go to Dashboard -> Settings -> Checkout.
- At the bottom of the page, locate the Integration script section
- Copy your integration script.
Add to your site's HTML
Once you have located and copied your JavaScript snippet, insert right before your site's closing <body>
tag.
It is important for the Zonos JS script to be loaded in your checkout page's body
tag so that when the script runs, your page's content is available and Checkout can properly bind to your checkout button.
We recommend using a server-side template engine or other secure techniques to insert your API key into your HTML with an environment variable. This will avoid exposing your API key in your HTML source code.
Configure the Zonos JavaScript snippet
You can configure all Checkout settings in Dashboard and the JavaScript snippet will load them automatically. If you would like to override any settings per-page or do more advanced dynamic configuration, you can do so by passing in an object to the zonos.init()
function.
Zonos JS snippet
<script src="YOUR SCRIPT URL HERE" />
<script>
zonos.init({
// .. other fields
placeOrderButtonSelector: '#checkout-button', // Replace with your actual checkout button selector
});
</script>
Pass your shopper's cart to Checkout
In order for Checkout to work, you need to pass your shopper's cart to Checkout. This is achieved by passing a buildCartDetail function to the zonos.init() function. This function is called when the shopper clicks your checkout button, allowing you to build the cart details dynamically.
Cart Item Schema
The buildCartDetail function should return an array of cart items. Below is a table detailing the structure of each CartItem object:
Field Name | Type | Required | Description |
---|---|---|---|
amount | Number | Yes | The price amount of the item. |
countryOfOrigin | String | No | The country of origin of the item. |
currencyCode | String | Yes | The currency code for the amount. |
description | String | No | Description of the item. |
hsCode | String | No | The Harmonized System code for the item. |
imageUrl | String | No | URL of the item's image. |
measurements | ItemMeasurement[] | No | Array of item measurements. |
metadata | Object (string/number pairs) | No | Additional metadata about the item. |
name | String | Yes | Name of the item. |
productId | String | No | The product ID. |
quantity | Number | Yes | Quantity of the item in the cart. |
sku | String | No | Stock Keeping Unit identifier. |
Example usage
Zonos JS snippet
<script src="YOUR SCRIPT URL HERE" />
<script>
zonos.init({
// .. other fields
buildCartDetail: async () => {
const cartItems = await getCartItems(); // Replace with your actual cart items
return cartItems.map(item => ({
amount: item.salePrice,
currencyCode: data.currency.code,
imageUrl: item.imageUrl,
name: item.name,
quantity: item.quantity,
}));
},
});
</script>
Test your integration
If you've configured everything properly, you should see the Zonos Checkout modal appear when you click your checkout button. If you don't see the modal, check your browser's console for any errors. See our Testing guide for full testing instructions.
JavaScript integration
How to do a custom JavaScript Checkout integration.Beta
If your website uses an ecommerce platform that we don't have a pre-built plugin for, you can integrate Zonos Checkout with JavaScript. This gives you the most flexibility in terms of customizing the look and feel of your checkout page.
This guide assumes that you have already created a Zonos account and that you are familiar with the basics of JavaScript/HTML. If you are not familiar with JavaScript/HTML, we recommend that you use one of our pre-built plugins instead if possible, or contact our Professional Services team for a custom development quote.