Search

Are you looking for test card numbers?

Would you like to contact support?

Payment-method icon

AfterPay Component

Add AfterPay to an existing Components integration.

Our AfterPay Component renders AfterPay in your payment form, and collects the required payment information from the shopper.

When making an AfterPay payment, you also need to:

  1. Provide the shopper's IP address and information about the purchased items when making a payment request.
  2. Capture the payment after the goods have been sent. This triggers the invoice to be sent to the shopper.

Before you begin

This page explains how to add AfterPay to your existing Web Components integration. The Web Components integration works the same way for all payment methods. If you haven't done this integration yet, refer to our Components integration guide.

Before starting your integration:

  1. Make sure that you have set up your back end implementation, and created an instance of AdyenCheckout.
  2. Add AfterPay in your test Customer Area.

Show AfterPay in your payment form

To use the AfterPay Component, you need to:

  1. Specify in your /paymentMethods request one of the following combinations of countryCode and amount.currency:

    Country countryCode amount.currency
    The Netherlands NL EUR
    Belgium BE EUR

    Pass the full response to the paymentMethodsResponse object when creating an instance of the AdyenCheckout.

  2. Add the AfterPay Component:

    a. Create a DOM element for AfterPay, placing it where you want the form to be rendered:

    <div id="afterpay-container"></div>

    b. Create an instance of the AfterPay Component, and mount it. You can also include optional configuration for the visibility of the following shopper input fields:

    • personalDetails: Shopper name, date of birth, phone number, and email address.
    • billingAddress: The address where to send the invoice.
    • deliveryAddress: The address where the goods should be delivered.

    If you remove these fields from your payment form, you need to provide this information in your /payments request. For information on the required fields, refer to Make a payment.

    const afterpay = checkout.create("afterpay_default", {
      countryCode: "NL", // the country code from the
                        // `/paymentMethods` request
      visibility: { // Optional configuration
          personalDetails: "hidden", // These fields will not appear on the payment form.
          billingAddress: "readOnly", // These fields will appear on the payment form,
                                      //but the shopper can't edit them.
          deliveryAddress: "editable" //These fields will appear on the payment form,
                                      // and the shopper can edit them.
                                      //This is the default behaviour.
      },
    }).mount('#afterpay-container');;
    

Make a payment

When the shopper selects to pay, the Component calls the onChange event, which contains a state.data.

  1. If state.isValid is true, collect the state.data and pass this to your server.
  2. From your server, make a /payments, specifying:
    • paymentMethod: The state.data from the onChange event from your front end.
    • shopperIP : The shopper's IP address. AfterPay uses this for risk checks.
    • lineItems : Price and product information about the purchased items. This is included on the invoice that AfterPay sends to the shopper.
{
   "merchantAccount":"YOUR_MERCHANT_ACCOUNT",
   "countryCode":"NL",
   "amount":{
      "currency":"EUR",
      "value":"1000"
   },
   "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
   "reference":"YOUR_ORDER_NUMBER",
   "channel":"Web",
   "{hint:`state.data.paymentMethod from onChange or onSubmit}paymentMethod{/hint}":{
      "type":"afterpay_default",
      "personalDetails":{
         "firstName":"EndToEnd",
         "lastName":"lasTName",
         "gender":"M",
         "dateOfBirth":"2000-02-02",
         "telephoneNumber":"+31612345678",
         "shopperEmail":"test@tester.com"
      },
      "billingAddress":{
         "street":"Simon Carmiggeltstraat",
         "houseNumberOrName":"136",
         "city":"Amsterdam",
         "postalCode":"1011DJ",
         "country":"NL"
      },
      "separateDeliveryAddress":"false"
   },
   "shopperIP":"192.0.2.1",
   "lineItems":[
      {
         "quantity":"1",
         "amountExcludingTax":"331",
         "taxPercentage":"2100",
         "description":"Shoes",
         "id":"Item #1",
         "taxAmount":"69",
         "amountIncludingTax":"400",
         "taxCategory":"High"
      },
      {
         "quantity":"2",
         "amountExcludingTax":"248",
         "taxPercentage":"2100",
         "description":"Socks",
         "id":"Item #2",
         "taxAmount":"52",
         "amountIncludingTax":"300",
         "taxCategory":"High"
      }
   ]
}

The /payments response contains:

  • resultCode: Use this to present the payment result to your shopper.
  • pspReference: Our unique reference for the payment.
  • merchantReference: Your reference from the /payments request.

{
    "pspReference": "881567437271705K",
    "resultCode": "Authorised",
    "merchantReference": "YOUR_ORDER_NUMBER"
}

Present the payment result

Use the resultCode that you received in the /payments response to present the payment result to your shopper.
The resultCode values you can receive for AfterPay are:

resultCode Description Action to take
Authorised The payment was successfully authorised. Inform the shopper that the payment was successful.
After the goods have been sent, you also need to capture the payment.
Cancelled The shopper cancelled the payment. Ask the shopper whether they want to continue with the order, or request that they select a different payment method.
Pending The shopper has completed the payment but the final result is not yet known. Inform the shopper that you've received their order, and are waiting for the payment to be completed.
To know the final result of the payment, wait for the AUTHORISATION notification.
Refused The payment was refused by AfterPay. Ask the shopper to try the payment again using a different payment method.

Capture the payment

After the goods have been sent, you also need to capture the payment. All AfterPay payments have to be manually captured, even if you have enabled automatic capture for other payment methods. Capturing the payment is what triggers the invoice to be sent to the shopper.

If you want to set up automatic capture for AfterPay payments, contact our Support Team.

Partial captures

To partially capture an AfterPay payment, specify in your /capture request:

  • modificationAmount: The amount that the shopper should pay. 
  • additionalData.openinvoicedata: Price and product information for the items that the shopper should pay for.

Although the field names are different, the information in additionalData.openinvoicedata is the same as what you provided in lineItems when making a /payments request:

openinvoicedata lineItems Description
itemAmount amountExcludingTax The price for one item, without the tax, in minor units.
itemVatAmount taxAmount The tax amount for one item, in minor units.
itemVatPercentage taxPercentage The tax percentage, in minor units.

The following example shows how to make a partial capture request if the shopper only kept one pair of socks from the two included in the original payment request.

{
   "originalReference":"COPY_PSP_REFERENCE_FROM_AUTHORISE_RESPONSE",
   "merchantAccount":"YOUR_MERCHANT_ACCOUNT",
   "modificationAmount":{
      "currency":"EUR",
      "value":"700"
   },
   "additionalData":{
      "openinvoicedata.numberOfLines":"2",
      "openinvoicedata.line1.currencyCode":"EUR",
      "openinvoicedata.line1.description":"Shoes",
      "openinvoicedata.line1.itemAmount":"331",
      "openinvoicedata.line1.itemVatAmount":"69",
      "openinvoicedata.line1.itemVatPercentage":"2100",
      "openinvoicedata.line1.numberOfItems":"1",
      "openinvoicedata.line1.vatCategory":"High",
      "openinvoicedata.line2.currencyCode":"EUR",
      "openinvoicedata.line2.description":"Socks",
      "openinvoicedata.line2.itemAmount":"248",
      "openinvoicedata.line2.itemVatAmount":"52",
      "openinvoicedata.line2.itemVatPercentage":"2100",
      "openinvoicedata.line2.numberOfItems":"1",
      "openinvoicedata.line2.vatCategory":"High"
   },
   "reference":"YOUR_CAPTURE_REFERENCE"
}

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. 

If you are using partial captures for AfterPay, include the acquirer reference in your Standard notifications. You will then receive the acquirerReference in the additionalData of a CAPTURE notification. Store this reference, as you will need it when making a (partial) refund request.

Refunds and cancellations

If an AfterPay payment has not yet been captured, you can cancel it. If the AfterPay payment has already been captured and you want to return the funds to the shopper, you need to refund it.

Partial refunds

To partially refund an AfterPay payment, specify in your /refund request:

  • modificationAmount: The amount to be refunded to the shopper.
  • additionalData.acquirerReference: The acquirerReference of the capture. This is needed if there are multiple partial captures available for the payment. When refunding in your Customer Area, you can add the acquirerReference manually as well.
  • additionalData.openinvoicedata: Price and product information about the returned items.

Although the field names are different, the information in additionalData.openinvoicedata is the same as what you provided in lineItems when making a /payments request:

openinvoicedata lineItems Description
itemAmount amountExcludingTax The price for one item, without the tax, in minor units.
itemVatAmount taxAmount The tax amount for one item, in minor units.
itemVatPercentage taxPercentage The tax percentage, in minor units.

The following example shows how to make a partial refund request if the shopper returned the shoes included in the original payment request.

{
   "merchantAccount":"YOUR_MERCHANT_ACCOUNT",
   "originalReference":"COPY_PSP_REFERENCE_FROM_AUTHORISE_RESPONSE",
   "modificationAmount":{
      "currency":"EUR",
      "value":"400"
   },
   "additionalData":{
      "openinvoicedata.numberOfLines":"1",
      "openinvoicedata.line1.currencyCode":"EUR",
      "openinvoicedata.line1.description":"Shoes",
      "openinvoicedata.line1.itemAmount":"331",
      "openinvoicedata.line1.itemVatAmount":"69",
      "openinvoicedata.line1.itemVatPercentage":"2100",
      "openinvoicedata.line1.numberOfItems":"1",
      "openinvoicedata.line1.vatCategory":"High"
   },
   "reference":"YOUR_REFUND_REFERENCE"
}

Test and go live

You need to contact AfterPay to get access to test credentials. After reviewing your test transactions, AfterPay will provide you with the credentials for processing live transactions.

You can check the status of the 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, and provide us your AfterPay live credentials.

See also