Add The Button
We provide two buttons, one is a sandbox button for testing. The other is a production button for live use.
Import the JavaScript
This script tag is used to load Afterpay’s button JavaScript SDK into a webpage. Import the AfterpayButton.js script as a script tag.
Test your integration with the Sandbox Button. When you’re satisfied, switch to the Production Button.
Sandbox Button
Production Button
Note
All regions load the same afterpay-button.js script URL script The differentiation occurs through the region attribute in the afterpay-button element.
Add the Afterpay Button Element
Insert the following HTML to initialize the afterpay-button element.
You need your merchant public key, provided by Afterpay. Public keys are safe to publish in JavaScript code or mobile applications.
Region Specific Configuration
If you are a merchant based in Australia, or the United Kingdom, include region="AU" or region="UK". Merchants in the United States or Canada do not need a regional setting.
Changing the appearance of the button - optional
See the Changing the Appearance page to cutomize the button.
Set Order Attributes
Before a customer can checkout with Afterpay, we need to know, at a minimum:
Merchant Reference- The merchant’s unique order id/reference that this payment corresponds to. This is used to reconcile orders in the Afterpay merchant portalAmount- The total amount of the order to be charged to the customer. This includes any shipping and tax, minus any discounts. This is the maximum amount that you can charge to the virtual Visa card (US, UK, and Canada) or the virtual Mastercard (Australia)Currency- The currency in ISO 4217 format. The value provided must correspond to the currency of the Merchant account making the requestConsumer details- The customer’s phone number, name, and email addressShipping details- The shipping name and shipping addressItems- This contains information about the line items in the order
Buy Now Flag
Enabling buyNow = true shows a Buy Now button at checkout. If not set, the button displays Confirm instead.
Increase Conversion Rates
Providing customer details speeds up checkout by pre-filling name and address fields.
Object Types
In-Store Pickup
If the customer chooses in-store pickup, no shipping address is needed. Instead, set instorePickup = true.
Money Object
Item object
Consumer object
Contact Object
Note
The information on this page also applies to Cash App Afterpay (US) and Clearpay (UK).