Express checkout uses the same APIs as standard checkout. To set it up:
Before launching Clearpay express checkout, create an order token by calling the Create Checkout endpoint. This lets you specify the order amount, items, and other details.
The backend call is triggered when the express checkout button is clicked. A new token is required for each order. If you store the token in a database, be sure to support arbitrary string length and content, as a token’s format can change.
For express checkout orders, there are two key differences from standard checkout:
mode to expresspopupOriginUrl instead of redirectConfirmUrl and redirectCancelUrl. With deferred shipping, you can also use a redirect.When a customer clicks this button on a cart or product page, it launches Clearpay checkout in a popup.
<button> element wherever you want it to appear on your website.Clearpay-express-button). This allows you to have multiple buttons on the same page.data-Clearpay-entry-point attribute. Allowed values are:
product-pagemini-cartcartdata-Clearpay-checkout-button-label attribute. This identifies the button for analytics or tracking purposes.Multiple button styles are available, each clearly communicating the next step to the customer.

Add the Afterpay.js script to your website. Set the onload attribute to point to a custom function that will initialize the popup (for example, initAfterpay).
Define your initAfterpay() function before loading the script. This function uses Afterpay.initializeForPopup() to configure the express checkout behavior. Configure the following properties:
countryCode: Your merchant account’s two-character ISO 3166-1 code (use “GB” for United Kingdom)target: The ID or class of the button that triggers checkoutshippingOptionRequired to falseonCommenceCheckout: Retrieve the Clearpay token from your server, then call actions.resolve(TOKEN) to start checkout.onComplete: See “finalize the order” for details.When the customer clicks the Clearpay checkout button, a popup opens or they’re sent to your redirect link. The customer is prompted to log in and review their order details. They can select a payment method and delivery address.
After confirming their order, the popup closes and the customer returns to your site. Checkout completion is communicated via the onComplete callback.
When the customer completes Clearpay express checkout, the onComplete Javascript function is called. It receives an event argument with a data field containing the following properties:
orderInfo data properties
Retrieve the transaction details by calling the Get Checkout endpoint. This is the source of truth for the order. It includes the user’s name, email address, delivery address, phone number, and order total.
After getting the order details, continue the checkout on your site. To continue:
You can capture payment using either the immediate payment flow or the deferred payment flow. For express checkout, the payload must include an amount field, which verifies that the final amount matches the amount including the shipping and taxes.
For deferred shipping, in addition to the required amount field, include these additional fields in the payload. These are required to verify that the final order amount and payment schedule match the submitted order details.
isCheckoutAdjusted: Indicates whether changes were made since order creationitems: Updated list of order items (if changed)shipping: Updated shipping address (if changed)paymentScheduleChecksum: Latest value from your widget’s onChange call (see Getting the widget’s state)If the final amount (including shipping and taxes) or the paymentScheduleChecksum doesn’t match the expected values, the request will be rejected.
Once payment is captured, the express checkout order is complete.
If you have multiple checkout buttons on the same page, these can be targeted by adding a common class to each of these buttons:
Then, set the target in the Afterpay.js initialize function with the common class. For example, set target in initializeForPopup:
With deferred shipping, you can also use a redirect flow with express checkout. There are a few main differences when setting up the button for redirect, including:
initializeForRedirect methodTo set up your redirect flow, first create a Clearpay order token using the Create Checkout API. Make sure to set the mode to express.
Then, start by creating the Clearpay express checkout button, adding an entry point, and loading Clearpay.js. This is similar to the popup flow.
In your onload function, initialize the redirect flow by calling initializeForRedirect and configure the following:
countryCode: The two-character ISO 3166-1 code for your merchant account (use “GB” for United Kingdom)addressMode: Use a mode without shipping options, as integrated shipping isn’t supported for redirect flows.target: The ID or class of the button that initiates checkoutonCommenceCheckout: Retrieve the Clearpay token from your server, then call actions.resolve(TOKEN) to start the checkout process.To support different shipping types in the checkout, configure the addressMode property using one of the provided constants in the format Afterpay.ADDRESS_MODES.<NAME>, where <NAME> is one of the following:
Next, finalize the order. When you created the Clearpay order token for redirect, you defined the properties redirectConfirmUrl and redirectCancelUrl. After the customer completes Clearpay express checkout, these properties are used to direct them to the specified URL:
redirectConfirmUrlredirectCancelUrlOnce the customer returns to your site, follow the steps to get the order details.
The following errors can occur during Clearpay express checkout with deferred shipping: