You can add Afterpay to your existing integration. The following instructions show only what you must add to your integration specifically for Afterpay.
If an instruction on this page corresponds with a step in the main integration guide, it includes a link to the corresponding step of the main integration guide.
Requirements
Requirement | Description | |
---|---|---|
Integration type | Make sure that you have an existing API-only integration. This page includes only instructions to add Afterpay to your existing integration. |
|
Checkout API | Make sure that you use Checkout API v or later. | |
Redirect handling | Make sure that your existing integration is set up to handle the redirect. action.type : redirect |
|
Limitations | Tokenization for recurring and on-file payments is only supported for Australia and New Zealand. | |
Setup steps | Before you begin, add Afterpay in your Customer Area. |
Get Afterpay as an available payment method
When you make the /paymentMethods call to get available payment methods, specify one of the following combinations of countryCode and amount.currency so that Afterpay is included in the response.
Country/region | countryCode |
amount.currency |
---|---|---|
Australia | AU | AUD |
New Zealand | NZ | NZD |
Canada | CA | CAD |
Build your payment form
We provide the logo for Afterpay that you can download.
To perform risk checks, Afterpay requires you to collect the following shopper details:
- Full name
- Email address
- Billing address and delivery address.
Accept Afterpay payments using our APIs, and build your own payment form to have full control over the look and feel of your checkout page.
Add additional parameters to your /payments request
When you make a payment, add the following parameters:
Parameter name | Required | Description |
---|---|---|
paymentMethod |
![]() |
afterpaytouch |
shopperName | ![]() |
The shopper's full name. |
shopperEmail | ![]() |
The shopper's email address. |
shopperReference | ![]() |
A unique reference to identify the shopper. Minimum length: three characters. |
countryCode | ![]() |
The shopper's country/region. |
billingAddress | ![]() |
The postal address to be included on the invoice. |
deliveryAddress | ![]() |
The postal address where the goods will be shipped. |
lineItems | ![]() |
Price and product information about the purchased items. |
telephoneNumber | The shopper's telephone number, if provided. |
Handle the redirect
You must handle the additional action.
The action.type
is redirect.
Capture the payment
Depending on your merchant account configuration, Afterpay payments are captured automatically after authorisation, or manually captured. If you prefer to capture the payment after the goods have been sent, you need to set up a capture delay or use manual capture. To partially capture a payment, you also need to use manual capture.
Afterpay payments have to be captured within 13 days after authorisation.
During authorisation, the shopper is charged for the first installment. If the payment is not captured within 13 days, before the second installment, Afterpay cancels the payment and refunds the first installment to the shopper.
For testing purposes, Afterpay authorisations expire in one day. When you use manual capture, you need to capture test Afterpay payments within one day after authorisation.
Full or partial manual captures
When you use manual capture, in your /payments/{paymentPspReference}/captures request specify:
- amount.value: the full or partial amount that the shopper should pay.
- lineItems: (optional) price and product information for the items that the shopper should pay for.
Any unclaimed amount that is left over after partially capturing a payment is automatically cancelled. When your account is enabled for multiple partial captures, the unclaimed amount after an initial capture is not automatically cancelled.
To set up multiple partial captures, contact our Support Team. Multiple partial captures will create a new invoice for each capture.
Refunds and cancellations
If a payment has not yet been captured, you can cancel it. If a payment has already been captured and you want to return the funds to the shopper, you need to refund the payment.
Full or partial refunds
To fully or partially refund a payment, in your /payments/{paymentPspReference}/refunds request specify:
- amount.value: the full or partial amount to be refunded to the shopper.
- lineItems: (optional) price and product information about the refunded items.
Discounts
To offer discounts, your payment request must include the negative amount to be added to the original price. The following example shows how to specify a discount of 1 AUD on Item #2:
{
"amount":{
"value":800,
"currency":"AUD"
},
...
"lineItems":[
{
"description":"Test Afterpay 1",
"quantity":"1",
"amountIncludingTax":"400",
"id":"Item #1"
},
{
"description":"Test Afterpay 2",
"quantity":"2",
"amountIncludingTax":"300",
"id":"Item #2"
}
{
"description":"Discount",
"quantity":"2",
"amountIncludingTax":"-100",
"id":"Item #2 Discount"
}
]
}
Recurring and on-file payments
Afterpay supports tokenization of the shopper's payment details for future recurring payments and on-file payments. On-file payments are later ad-hoc payments where you use the shopper's token. By getting the shopper's permission to save their payment details when you create the token, the shopper approval step is bypassed on future payments with the token.
Tokenization is only supported for Australia and New Zealand.
Proceed as follows:
-
Make sure you receive the tokens that we generate for your shoppers:
- Enable tokenization webhooks. You will receive the token in a recurring.token.created webhook.
-
To receive the token in the API response as well: in your Customer Area go to Developers > Additional data settings and enable Recurring details.
-
In your initial
/payments
request, add parameters to create a token. This can be a request for a payment, or a zero-value authorization without payment.
The shopper is redirected to Afterpay to approve:- Paying the first installment as well as storing the payment details for future payments.
- Only storing the payment details for future payments, in case of a zero-value authorization.
The shopper is redirected to Afterpay as usual.
-
From the recurring.token.created webhook, save the following data in your system:
storedPaymentMethodId
: the token that we generated for the shopper. For example: M5N7TQ4TG5PFWR50.shopperReference
: your unique identification of the shopper.
The
/payments/details
response returns this data in the additionalData object. -
If your request included paying the first installment, make sure the payment is captured.
-
In later payments for the same shopper, in your
/payments
request add the shopper'sstoredPaymentMethodId
. See Pay with a token for more details.The shopper is not redirected to Afterpay because they have given their approval for the use of their stored payment details.
-
In the
/payments
response, note that this includes thepspReference
. -
Make sure the payment is captured.
Test and go live
To test Afterpay payments, you need a test shopper account in the Afterpay sandbox environment. If you are testing in multiple countries or regions, create a different test account for each.
To create a test account:
- Go to https://portal.sandbox.afterpay.com/.
- Enter a real email address and select Continue. You'll get confirmations of payments and refunds like any other shopper on this email address.
- From the drop-down menu, select the country/region for which you want to create a test shopper account. Select Australia, New Zealand, US, or Canada.
- Enter any mobile telephone number that is formatted correctly, and select Continue. Check the input box for hints on the format. The phone number won't be used.
- When you are prompted to enter your SMS verification code, enter 111111.
- Follow the instructions on your screen to complete your profile, accept the terms and conditions, and select Continue.
To test payments, add a test card to your Afterpay test shopper account.
You can use the card details provided in the Afterpay developer documentation, or use one of the Adyen test cards. Use CVV 000 to simulate authorised payments, or CVV 051 to simulate refused payments.
You can check the status of test payments in your Customer Area > Transactions > Payments.
Before you can accept live Afterpay payments, you need to submit a request for Afterpay in your live Customer Area.