Search

Are you looking for test card numbers?

Would you like to contact support?

Payment-method icon

Afterpay Touch Component

Add Afterpay Touch to your existing Components integration.

Our Afterpay Touch Component renders Afterpay in your payment form.

When making an Afterpay payment, you also need to:

  1. Collect shopper details, and specify these in your payment request.
    Afterpay uses these for risk checks.
  2. Provide information about the purchased items in your payment request.
  3. Use createFromAction to handle the redirect to Afterpay, and back to your website.

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 present the Afterpay Touch Component in your payment form:

  1. From your server, make a POST /paymentMethods request specifying one of the following combinations of countryCode and amount.currency:

    Country countryCode amount.currency
    Australia AU AUD
    New Zealand NZ NZD

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

  2. Add the Afterpay Touch Component:

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

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

    b. Create an instance of the Afterpay Touch Component, and mount it.

    const afterpaytouch = checkout.create('afterpaytouch').mount('#afterpaytouch-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.
  • paymentMethod: The state.data.paymentMethod from the onChange event from your front end.

{
   "{hint:`state.data.paymentMethod` from `onChange` or `onSubmit`}paymentMethod{/hint}":{
     "type":"afterpaytouch"
   },
   "amount":{
      "value":1000,
      "currency":"AUD"
   },
   "shopperName":{
      "firstName":"Happy",
      "lastName":"Testing"
   },
   "shopperEmail":"shopper@email.com",
   "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
   "reference":"YOUR_ORDER_REFERENCE",
   "merchantAccount":"YOUR_MERCHANT_ACCOUNT",
   "returnUrl":"https://www.yourshop.com/checkout/result",
   "countryCode":"AU",
   "telephoneNumber":"+85121212121",
   "billingAddress":{
      "city":"Sydney",
      "country":"AU",
      "houseNumberOrName":"123",
      "postalCode":"2000",
      "stateOrProvince":"NSW",
      "street":"Happy Street"
   },
   "deliveryAddress":{
      "city":"Sydney",
      "country":"AU",
      "houseNumberOrName":"123",
      "postalCode":"2000",
      "stateOrProvince":"NSW",
      "street":"Happy Street"
   },
   "lineItems":[
      {
         "description":"Shoes",
         "quantity":"1",
         "amountIncludingTax":"400",
         "id":"Item #1"
      },
      {
         "description":"Socks",
         "quantity":"2",
         "amountIncludingTax":"300",
         "id":"Item #2"
      }
   ]
}

The /payments response contains:

  • action.method: GET or POST. The HTTP request method that you should use. After the shopper completes the payment, they will be redirected back to your returnURL using the same method.
    The redirect method depends on your payment method configuration and the length of the data included in the request, so make sure that your integration can handle both HTTP GET and HTTP POST methods.

To verify the payment result, you also need the following from the /payments response:

  • action.paymentData: Store this on your server — this is the paymentData value that you send in your /payment/details request.
  • details: Array of parameters that you need to send in your /payment/details request. For example, payload or redirectResult.
    The parameters can vary based on the payment method configuration. Make sure to check the details array to confirm the parameters that you need to send in your next API request.

/payments response
{
   "resultCode":"RedirectShopper",
   "action":{
      "method":"GET",
      "paymentData":"abcxyz...",
      "paymentMethodType":"afterpaytouch",
      "type":"redirect",
      "url":"https://test.adyen.com/hpp/skipDetails.shtml?billingAddress. ..."
   },
   "details":[
      {
         "key":"payload",
         "type":"text"
      }
   ],
   ...
}

Handle the redirect

  1. Call createFromAction and pass the action object from the previous step. This will return a new Component that you need to mount:
       checkout.createFromAction(action).mount('#my-container');

    The Component redirects the shopper to Afterpay to complete the payment.

  2. After the shopper is redirected back to your website, check the payment result by making a /payments/details request, specifying:

    • paymentData: Value you received in the /payments response.
    • details: Object that contains the URL-decoded values of the parameters that were returned when the shopper was redirected back to your site. For example, payload. To check the parameters that you should submit, refer to the details array that you received in the /payments response.

    /payments/details request
    {
      "paymentData":"Ab02b4c0!BQABAgCJN1wRZuGJmq8dMncmypvknj9s7l5Tj...",
      "details":{
        "{hint:Verify the parameters from /payments response}payload{/hint}":"Ab02b4c0!BQABAgCW5sxB4e/=="
      }
    }

    You receive a response containing:

    • resultCode: Use this to present the result to your shopper.
    • pspReference: Our unique identifier for the transaction.

    /payments/details response
    {
      "resultCode": "Authorised",
      "pspReference": "88154795347618C"
    }
For more information and detailed instructions, refer to Handling the redirect result.

Present the payment result

Use the resultCode that you received in the /payments/details 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 successful. Inform the shopper that the payment was successful.
Cancelled The shopper cancelled the payment. Ask the shopper whether they want to continue with the order, or ask them to select a different payment method.
Pending
Received
The shopper has completed the payment but the final result is not yet known. It may take minutes or hours to confirm this. 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.
If a shopper completed the payment but failed to return to your website or app, you will receive the outcome of the payment in an AUTHORISATION notification.

Discounts

To offer discounts, specify in your /payments request the negative amount to be added to the original price. The following example shows how to specify a discount of $ 10 on Item 2:

{
  "amount":{
     "value":7850,
     "currency":"AUD"
  },
  ...
  "lineItems":[

     {
        "description":"Test Afterpay Touch 1",
        "quantity":"1",
        "amountIncludingTax":"4550",
        "id":"Item #1"
     },
     {
        "description":"Test Afterpay Touch 2",
        "quantity":"2",
        "amountIncludingTax":"2650",
        "id":"Item #2"
     }

     {
        "description":"Discount",
        "quantity":"2",
        "amountIncludingTax":"-1000",
        "id":"Item #2 Discount"
     }
  ]
}

Test and go live

While you're going through the certification process, Afterpay will provide you with a merchantID and a password that you can use for testing. After reviewing your test transactions, Afterpay will provide you the credentials for processing live transactions.

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.

See also