Express checkout uses the same APIs as standard checkout. Integrated shipping enhances the experience by embedding your shipping options directly into Clearpay express checkout, streamlining the process. When paired with the Buy Now flag, it creates a one-step 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 redirectCancelUrlWhen 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-afterpay-entry-point attribute. Allowed values are:
product-pagemini-cartcartdata-afterpay-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)addressMode: One of the provided address mode constantstarget: The ID or class of the button that triggers checkoutbuyNow flag to true. This shows customers a “Buy Now” button for one-step checkout.onCommenceCheckout: Retrieve the Afterpay token from your server, then call actions.resolve(TOKEN) to start checkout.onComplete: See Finalize the Order for details.onShippingAddressChange: See Listen for Address Changes for details.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:
addressMode isn’t specified, ADDRESS_WITH_SHIPPING_OPTIONS is used by default.When the customer clicks the Clearpay checkout button, a popup opens. The customer is prompted to log in and review their order details. They can select a payment method, delivery address, and shipping option.
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.
Verify the order details to ensure that the shipping address, shippingOptionIdentifier, and resulting amount are valid and match your records.
Capture payment using the immediate payment flow. For express checkout, the payload must include an amount field.
Once payment is captured, the express checkout order is complete.
The onShippingAddressChange callback lets you dynamically update shipping options and taxes based on the consumer’s shipping address. It receives two arguments: data (the address) and actions (callback functions).
Clearpay calls onShippingAddressChange when the customer first enters the Clearpay summary page, and again whenever they update their shipping address. During these calls, you should:
data to determine supported shipping options (e.g. by contacting your backend API).actions.resolve to return the options to the Clearpay express checkout, oractions.reject to signal any errors, providing an appropriate shipping constantTo indicate error scenarios, call actions.reject() with the appropriate constant. The constants are in the form Afterpay.CONSTANTS.<NAME>, where <NAME> is one of the following:
The onShippingOptionChange callback is optional, allowing you to track the customer’s chosen shipping option as it changes. It will be called with a single Shipping Option argument each time the customer selects a shipping option.
If you need to modify the shipping option amounts after the user has selected a shipping option, use onShippingOptionChange with an additional action argument to update the checkout. When onShippingOptionChange is triggered:
Use the shipping option data to perform the required modification (for example, recalculate the tax via your backend API).
Once updated, use actions.resolve to return an object containing:
id: The same shipping option id from onShippingOptionChangeshippingAmount: The updated shipping amount for the selected optiontaxAmount: The updated tax amount for the selected optionorderAmount: The updated order amount for the selected shipping optionUse actions.reject to signal any errors.
To facilitate handling of log/warning/error messages, you can optionally replace Afterpay.onMessage with a custom function. It receives the following payload:
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:
To support pickup orders using integrated shipping, follow these steps:
shipping body parameter when creating the order.initializeForPopup, set addressMode to Afterpay.ADDRESS_MODES.PICKUP_FROM_ORDER_ADDRESS.
onShippingAddressChange to return the name and description of the pickup selection. This typically means returning a single option, for example:
initializeForPopup is called before you know whether a customer has selected pickup, you can safely call initializeForPopup again. Each call overwrites the previous calls.If customers can choose a shipping option on your site before launching express checkout, you can send us this information when checkout launches.
shippingOptionIdentifier in the body parameter when creating the order. This preselects the option if it’s returned from onShippingAddressChange when checkout loads.addressMode in Afterpay.initializeForPopup() to define how the shipping address is handled.
Afterpay.ADDRESS_MODES.SHIP_TO_ORDER_ADDRESSAfterpay.ADDRESS_MODES.SHIP_TO_ORDER_ADDRESS_WITHOUT_SHIPPING_OPTIONSshipping parameter when creating the order.The following errors can occur during Clearpay express checkout with integrated shipping: