DOCS

Inventory checks

/

Inventory checks

Check for item stock before completing orders with Checkout.

Checkout supports inventory checks to ensure that items are in stock before completing an order. This feature allows you to check the inventory of the items in the cart and reject the order if any items are out of stock.

How inventory checks work 

By default, Checkout doesn't know about your product inventory. By setting up an inventory check handler, Checkout will attempt to check the inventory of the items in the cart before completing the order. If the inventory check fails, the order will be rejected before payment and an error message will be displayed to the customer. The exact contents of the error message are customizable.

Set up an inventory check 

In order to add an inventory check before completing an order, you need to set up the onInventoryCheck function as part of the checkoutSettings object in Zonos.init that checks the inventory of the items in the cart. If the inventory check function returns a string or an Error, we will assume the check failed and display the error to the user. If the check is successful, simply do nothing. The actual logic of checking your inventory is up to you and your backend system.

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
window.Zonos.init({
  checkoutSettings: {
    onInventoryCheck(items) {
      const outOfStockItems = fetch("your-api.com/inventory_check", {
        body: JSON.stringify(items),
      });

      // Check inventory using the items variable and return promise
      if (outOfStockItems.length > 0) {
        // If successful, do nothing
      } else {
        return `${outOfStockItems.length} items are out of stock.`;
      }
    },
  },
});

Was this page helpful?