Skip to navigation

Create a checkout

There are three steps to create an Afterpay checkout:

  1. Call Get Configuration to retrieve your order limits
  2. Call Create Checkout to generate a checkout token
  3. Redirect the customer to Afterpay to complete the checkout flow
ActionEndpointPurpose
Get Configuration/v2/platform/configurationRetrieve Afterpay order limits (min/max values).
Create Checkout/v2/checkoutsProvide order details and generate a checkout token.

Retrieve your order limits

Call the Get Configuration endpoint to retrieve your minimum and maximum Afterpay order amounts.

We recommend calling this endpoint once a day as part of a scheduled background process, and storing the minimumAmount and maximumAmount values on your server.

Use these values to determine:

  1. The correct Afterpay Messaging to show on the Product Detail pages
  2. Whether Afterpay should be presented as an available payment method

A request to create a checkout will be declined if the order grand total is less than the minimum or more than the maximum Afterpay amount. To change your minimum and maximum order values, contact Afterpay.

Create a checkout

Call the Create Checkout endpoint to communicate the order details to Afterpay. Your request should include:

  1. Customer information
  2. Order details
  3. Order total
  4. Shipping details
  5. Redirect URLs

Afterpay uses the order total value to calculate the installment plan and to assist with the customer’s pre-approval process.

Afterpay responds with a token used to identify this checkout. For example, 002.5lmerr3k945d00c7htvcrdff83q36kp10a247m212fjpa5ju. This token is used to launch the Afterpay checkout flow using Afterpay.js.

Afterpay.js

EnvironmentURL
Sandboxhttps://portal.sandbox.afterpay.com/afterpay.js
Productionhttps://portal.afterpay.com/afterpay.js

Set up your checkout experience

Use the redirect method to launch the Afterpay checkout flow. Customers are redirected from your website to Afterpay to complete their payment. At the end of the Afterpay checkout flow, the customer is redirected back to your website.

Implement the redirect method

To use the redirect method, call the following two JavaScript functions, in order:

  1. AfterPay.initialize: Prepares the Afterpay JavaScript to start the Afterpay screenflow in the appropriate geographical region.
    • Accepts an object with a required countryCode (the two-character ISO 3166-1 country code of the merchant account)
  2. AfterPay.redirect: Redirects the customer’s browser from your website to Afterpay.
    • Accepts an object with a required token (the checkout token returned by the Create Checkout API call)
<html>
<head>
<script onload="initAfterPay()" src="https://portal.sandbox.afterpay.com/afterpay.js"></script>
</head>
<body>
<p>Your HTML here</p>
<script>
function initAfterPay () {
AfterPay.initialize({countryCode: "AU"});
AfterPay.redirect({token: "YOUR_TOKEN"});
}
</script>
</body>
</html>

If the customer successfully completes the checkout flow, they’re returned to your redirectConfirmUrl with a checkout token and a SUCCESS status appended as HTTP query parameters: www.merchant-example.com/confirm?&status=SUCCESS&orderToken=002.5lmerr3k945d00c7htvcrdff83q36kp10a247m212fjpa5ju

If the customer cancels the checkout, they’re returned to your redirectCancelUrl with a checkout token and a CANCELLED status appended as HTTP query parameters: www.merchant-example.com/confirm?&status=CANCELLED&orderToken=002.5lmerr3k945d00c7htvcrdff83q36kp10a247m212fjpa5ju

Final Afterpay checkout screen Afterpay-Checkout-final-screen