---
title: "Afterpay for API only"
description: "Add Afterpay to an existing API-only integration."
url: "https://docs.adyen.com/payment-methods/afterpaytouch/api-only"
source_url: "https://docs.adyen.com/payment-methods/afterpaytouch/api-only.md"
canonical: "https://docs.adyen.com/payment-methods/afterpaytouch/api-only"
last_modified: "2026-06-01T15:33:15+02:00"
language: "en"
---

# Afterpay for API only

Add Afterpay to an existing API-only integration.

[View source](/payment-methods/afterpaytouch/api-only.md)

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](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%20only). 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](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%20only#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](/payment-methods/add-payment-methods).                                                                                                                                              |   |

## Get Afterpay as an available payment method

When you make the [/paymentMethods](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods) call to [get available payment methods](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%20only#get-available-payment-methods), specify one of the following combinations of [countryCode](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods) and [amount.currency](https://docs.adyen.com/api-explorer/Checkout/latest/post/paymentMethods#request-amount) 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](/online-payments/build-your-integration/advanced-flow/?platform=Web\&integration=API%20only#downloading-logos).

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](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%20only#make-a-payment), add the following parameters:

| Parameter name                                                                                                 | Required                                                                                    | Description                                                                   |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `paymentMethod`                                                                                                | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | **afterpaytouch**                                                             |
| [shopperName](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-shopperName)           | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The shopper's full name.                                                      |
| [shopperEmail](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-shopperEmail)         | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The shopper's email address.                                                  |
| [shopperReference](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-shopperReference) | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | A unique reference to identify the shopper. Minimum length: three characters. |
| [countryCode](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-countryCode)           | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The shopper's country/region.                                                 |
| [billingAddress](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-billingAddress)     | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The postal address to be included on the invoice.                             |
| [deliveryAddress](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-deliveryAddress)   | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The postal address where the goods will be shipped.                           |
| [lineItems](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-lineItems)               | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | Price and product information about the purchased items.                      |
| [telephoneNumber](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-telephoneNumber)   |                                                                                             | The shopper's telephone number, if provided.                                  |

#### curl

```bash
curl https://checkout-test.adyen.com/v68/payments \
-H 'x-api-key: ADYEN_API_KEY' \
-H 'content-type: application/json' \
-d '{
  "paymentMethod":{
    "type":"afterpaytouch"
  },
  "amount":{
     "value":1000,
     "currency":"AUD"
  },
  "countryCode":"AU",
  "shopperName":{
     "firstName":"Simon",
     "lastName":"Hopper"
  },
  "telephoneNumber":"+61 2 8520 3890",
  "shopperEmail":"s.hopper@example.com",
  "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
  "reference":"YOUR_ORDER_REFERENCE",
  "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
  "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy..",
  "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",
        "amountExcludingTax": "331",
        "taxAmount": "69",
        "id":"Item #1"
     },
     {
        "description":"Socks",
        "quantity":"2",
        "amountIncludingTax":"300",
        "amountExcludingTax": "248",
        "taxAmount": "52",
        "id":"Item #2"
     }
  ]
}'
```

#### Java

```java
// Adyen Java API Library v27.0.0
import com.adyen.Client;
import com.adyen.enums.Environment;
import com.adyen.model.checkout.*;
import java.time.OffsetDateTime;
import java.util.*;
import com.adyen.model.RequestOptions;
import com.adyen.service.checkout.*;

// For the live environment, additionally include your liveEndpointUrlPrefix.
Client client = new Client("ADYEN_API_KEY", Environment.TEST);

// Create the request object(s)
Amount amount = new Amount()
  .currency("AUD")
  .value(1000L);

LineItem lineItem1 = new LineItem()
  .quantity(1L)
  .amountExcludingTax(331L)
  .description("Shoes")
  .id("Item #1")
  .amountIncludingTax(400L)
  .taxAmount(69L);

LineItem lineItem2 = new LineItem()
  .quantity(2L)
  .amountExcludingTax(248L)
  .description("Socks")
  .id("Item #2")
  .amountIncludingTax(300L)
  .taxAmount(52L);

Name name = new Name()
  .firstName("Simon")
  .lastName("Hopper");

DeliveryAddress deliveryAddress = new DeliveryAddress()
  .country("AU")
  .stateOrProvince("NSW")
  .city("Sydney")
  .houseNumberOrName("123")
  .street("Happy Street")
  .postalCode("2000");

AfterpayDetails afterpayDetails = new AfterpayDetails()
  .type(AfterpayDetails.TypeEnum.AFTERPAYTOUCH);

BillingAddress billingAddress = new BillingAddress()
  .country("AU")
  .stateOrProvince("NSW")
  .city("Sydney")
  .houseNumberOrName("123")
  .street("Happy Street")
  .postalCode("2000");

PaymentRequest paymentRequest = new PaymentRequest()
  .amount(amount)
  .telephoneNumber("+61 2 8520 3890")
  .shopperEmail("s.hopper@example.com")
  .reference("YOUR_ORDER_REFERENCE")
  .lineItems(Arrays.asList(lineItem1, lineItem2))
  .shopperName(name)
  .merchantAccount("ADYEN_MERCHANT_ACCOUNT")
  .deliveryAddress(deliveryAddress)
  .countryCode("AU")
  .paymentMethod(new CheckoutPaymentMethod(afterpayDetails))
  .billingAddress(billingAddress)
  .returnUrl("https://your-company.example.com/checkout?shopperOrder=12xy..")
  .shopperReference("YOUR_UNIQUE_SHOPPER_ID");

// Send the request
PaymentsApi service = new PaymentsApi(client);
PaymentResponse response = service.payments(paymentRequest, new RequestOptions().idempotencyKey("UUID"));
```

#### PHP

```php
// Adyen PHP API Library v19.0.0
use Adyen\Client;
use Adyen\Environment;
use Adyen\Model\Checkout\Amount;
use Adyen\Model\Checkout\LineItem;
use Adyen\Model\Checkout\Name;
use Adyen\Model\Checkout\DeliveryAddress;
use Adyen\Model\Checkout\CheckoutPaymentMethod;
use Adyen\Model\Checkout\BillingAddress;
use Adyen\Model\Checkout\PaymentRequest;
use Adyen\Service\Checkout\PaymentsApi;

$client = new Client();
$client->setXApiKey("ADYEN_API_KEY");
// For the live environment, additionally include your liveEndpointUrlPrefix.
$client->setEnvironment(Environment::TEST);


// Create the request object(s)
$amount = new Amount();
$amount
  ->setCurrency("AUD")
  ->setValue(1000);

$lineItem1 = new LineItem();
$lineItem1
  ->setQuantity(1)
  ->setAmountExcludingTax(331)
  ->setDescription("Shoes")
  ->setId("Item #1")
  ->setAmountIncludingTax(400)
  ->setTaxAmount(69);

$lineItem2 = new LineItem();
$lineItem2
  ->setQuantity(2)
  ->setAmountExcludingTax(248)
  ->setDescription("Socks")
  ->setId("Item #2")
  ->setAmountIncludingTax(300)
  ->setTaxAmount(52);

$name = new Name();
$name
  ->setFirstName("Simon")
  ->setLastName("Hopper");

$deliveryAddress = new DeliveryAddress();
$deliveryAddress
  ->setCountry("AU")
  ->setStateOrProvince("NSW")
  ->setCity("Sydney")
  ->setHouseNumberOrName("123")
  ->setStreet("Happy Street")
  ->setPostalCode("2000");

$checkoutPaymentMethod = new CheckoutPaymentMethod();
$checkoutPaymentMethod
  ->setType("afterpaytouch");

$billingAddress = new BillingAddress();
$billingAddress
  ->setCountry("AU")
  ->setStateOrProvince("NSW")
  ->setCity("Sydney")
  ->setHouseNumberOrName("123")
  ->setStreet("Happy Street")
  ->setPostalCode("2000");

$paymentRequest = new PaymentRequest();
$paymentRequest
  ->setAmount($amount)
  ->setTelephoneNumber("+61 2 8520 3890")
  ->setShopperEmail("s.hopper@example.com")
  ->setReference("YOUR_ORDER_REFERENCE")
  ->setLineItems(array($lineItem1, $lineItem2))
  ->setShopperName($name)
  ->setMerchantAccount("ADYEN_MERCHANT_ACCOUNT")
  ->setDeliveryAddress($deliveryAddress)
  ->setCountryCode("AU")
  ->setPaymentMethod($checkoutPaymentMethod)
  ->setBillingAddress($billingAddress)
  ->setReturnUrl("https://your-company.example.com/checkout?shopperOrder=12xy..")
  ->setShopperReference("YOUR_UNIQUE_SHOPPER_ID");

$requestOptions['idempotencyKey'] = 'UUID';

// Send the request
$service = new PaymentsApi($client);
$response = $service->payments($paymentRequest, $requestOptions);
```

#### C\#

```cs
// Adyen .net API Library v17.0.0
using Adyen;
using Environment = Adyen.Model.Environment;
using Adyen.Model;
using Adyen.Model.Checkout;
using Adyen.Service.Checkout;

// For the live environment, additionally include your liveEndpointUrlPrefix.
var config = new Config()
{
    XApiKey = "ADYEN_API_KEY",
    Environment = Environment.Test
};
var client = new Client(config);

// Create the request object(s)
Amount amount = new Amount
{
  Currency = "AUD",
  Value = 1000
};

LineItem lineItem1 = new LineItem
{
  Quantity = 1,
  AmountExcludingTax = 331,
  Description = "Shoes",
  Id = "Item #1",
  AmountIncludingTax = 400,
  TaxAmount = 69
};

LineItem lineItem2 = new LineItem
{
  Quantity = 2,
  AmountExcludingTax = 248,
  Description = "Socks",
  Id = "Item #2",
  AmountIncludingTax = 300,
  TaxAmount = 52
};

Name name = new Name
{
  FirstName = "Simon",
  LastName = "Hopper"
};

DeliveryAddress deliveryAddress = new DeliveryAddress
{
  Country = "AU",
  StateOrProvince = "NSW",
  City = "Sydney",
  HouseNumberOrName = "123",
  Street = "Happy Street",
  PostalCode = "2000"
};

AfterpayDetails afterpayDetails = new AfterpayDetails
{
  Type = AfterpayDetails.TypeEnum.Afterpaytouch
};

BillingAddress billingAddress = new BillingAddress
{
  Country = "AU",
  StateOrProvince = "NSW",
  City = "Sydney",
  HouseNumberOrName = "123",
  Street = "Happy Street",
  PostalCode = "2000"
};

PaymentRequest paymentRequest = new PaymentRequest
{
  Amount = amount,
  TelephoneNumber = "+61 2 8520 3890",
  ShopperEmail = "s.hopper@example.com",
  Reference = "YOUR_ORDER_REFERENCE",
  LineItems = new List<LineItem>{ lineItem1, lineItem2 },
  ShopperName = name,
  MerchantAccount = "ADYEN_MERCHANT_ACCOUNT",
  DeliveryAddress = deliveryAddress,
  CountryCode = "AU",
  PaymentMethod = new CheckoutPaymentMethod(afterpayDetails),
  BillingAddress = billingAddress,
  ReturnUrl = "https://your-company.example.com/checkout?shopperOrder=12xy..",
  ShopperReference = "YOUR_UNIQUE_SHOPPER_ID"
};

// Send the request
var service = new PaymentsService(client);
var response = service.Payments(paymentRequest, requestOptions: new RequestOptions { IdempotencyKey = "UUID"});
```

#### NodeJS (JavaScript)

```js
// Adyen Node API Library v18.0.0
// Require the parts of the module you want to use
const { Client, CheckoutAPI } = require('@adyen/api-library');
// Initialize the client object
// For the live environment, additionally include your liveEndpointUrlPrefix.
const client = new Client({apiKey: "ADYEN_API_KEY", environment: "TEST"});

// Create the request object(s)
const paymentRequest = {
  paymentMethod: {
    type: "afterpaytouch"
  },
  amount: {
    value: 1000,
    currency: "AUD"
  },
  shopperName: {
    firstName: "Simon",
    lastName: "Hopper"
  },
  shopperEmail: "s.hopper@example.com",
  shopperReference: "YOUR_UNIQUE_SHOPPER_ID",
  reference: "YOUR_ORDER_REFERENCE",
  merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  returnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy..",
  countryCode: "AU",
  telephoneNumber: "+61 2 8520 3890",
  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",
    amountExcludingTax: "331",
    taxAmount: "69",
    id: "Item #1"
  }, {
    description: "Socks",
    quantity: "2",
    amountIncludingTax: "300",
    amountExcludingTax: "248",
    taxAmount: "52",
    id: "Item #2"
  } ]
}

// Send the request
const checkoutAPI = new CheckoutAPI(client);
const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
```

#### Go

```go
// Adyen Go API Library v10.4.0
import (
  "context"
  "github.com/adyen/adyen-go-api-library/v9/src/common"
  "github.com/adyen/adyen-go-api-library/v9/src/adyen"
  "github.com/adyen/adyen-go-api-library/v9/src/checkout"
)
// For the live environment, additionally include your liveEndpointUrlPrefix.
client := adyen.NewClient(&common.Config{
  ApiKey:      "ADYEN_API_KEY",
  Environment: common.TestEnv,
})

// Create the request object(s)
amount := checkout.Amount{
  Currency: "AUD",
  Value: 1000,
}

lineItem1 := checkout.LineItem{
  Quantity: common.PtrInt64(1),
  AmountExcludingTax: common.PtrInt64(331),
  Description: common.PtrString("Shoes"),
  Id: common.PtrString("Item #1"),
  AmountIncludingTax: common.PtrInt64(400),
  TaxAmount: common.PtrInt64(69),
}

lineItem2 := checkout.LineItem{
  Quantity: common.PtrInt64(2),
  AmountExcludingTax: common.PtrInt64(248),
  Description: common.PtrString("Socks"),
  Id: common.PtrString("Item #2"),
  AmountIncludingTax: common.PtrInt64(300),
  TaxAmount: common.PtrInt64(52),
}

name := checkout.Name{
  FirstName: "Simon",
  LastName: "Hopper",
}

deliveryAddress := checkout.DeliveryAddress{
  Country: "AU",
  StateOrProvince: common.PtrString("NSW"),
  City: "Sydney",
  HouseNumberOrName: "123",
  Street: "Happy Street",
  PostalCode: "2000",
}

afterpayDetails := checkout.AfterpayDetails{
  Type: "afterpaytouch",
}

billingAddress := checkout.BillingAddress{
  Country: "AU",
  StateOrProvince: common.PtrString("NSW"),
  City: "Sydney",
  HouseNumberOrName: "123",
  Street: "Happy Street",
  PostalCode: "2000",
}

paymentRequest := checkout.PaymentRequest{
  Amount: amount,
  TelephoneNumber: common.PtrString("+61 2 8520 3890"),
  ShopperEmail: common.PtrString("s.hopper@example.com"),
  Reference: "YOUR_ORDER_REFERENCE",
  LineItems: []checkout.LineItem{
      lineItem1, lineItem2,
  },
  ShopperName: &name,
  MerchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  DeliveryAddress: &deliveryAddress,
  CountryCode: common.PtrString("AU"),
  PaymentMethod: checkout.AfterpayDetailsAsCheckoutPaymentMethod(&afterpayDetails),
  BillingAddress: &billingAddress,
  ReturnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy..",
  ShopperReference: common.PtrString("YOUR_UNIQUE_SHOPPER_ID"),
}

// Send the request
service := client.Checkout()
req := service.PaymentsApi.PaymentsInput().IdempotencyKey("UUID").PaymentRequest(paymentRequest)
res, httpRes, err := service.PaymentsApi.Payments(context.Background(), req)
```

#### Python

```py
# Adyen Python API Library v12.5.1
import Adyen

adyen = Adyen.Adyen()
adyen.client.xapikey = "ADYEN_API_KEY"
# For the live environment, additionally include your liveEndpointUrlPrefix.
adyen.client.platform = "test" # The environment to use library in.

# Create the request object(s)
json_request = {
  "paymentMethod": {
    "type": "afterpaytouch"
  },
  "amount": {
    "value": 1000,
    "currency": "AUD"
  },
  "shopperName": {
    "firstName": "Simon",
    "lastName": "Hopper"
  },
  "shopperEmail": "s.hopper@example.com",
  "shopperReference": "YOUR_UNIQUE_SHOPPER_ID",
  "reference": "YOUR_ORDER_REFERENCE",
  "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
  "returnUrl": "https://your-company.example.com/checkout?shopperOrder=12xy..",
  "countryCode": "AU",
  "telephoneNumber": "+61 2 8520 3890",
  "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",
    "amountExcludingTax": "331",
    "taxAmount": "69",
    "id": "Item #1"
  }, {
    "description": "Socks",
    "quantity": "2",
    "amountIncludingTax": "300",
    "amountExcludingTax": "248",
    "taxAmount": "52",
    "id": "Item #2"
  } ]
}

# Send the request
result = adyen.checkout.payments_api.payments(request=json_request, idempotency_key="UUID")
```

#### Ruby

```rb
# Adyen Ruby API Library v9.5.1
require "adyen-ruby-api-library"

adyen = Adyen::Client.new
adyen.api_key = 'ADYEN_API_KEY'
# For the live environment, additionally include your liveEndpointUrlPrefix.
adyen.env = :test # Set to "live" for live environment

# Create the request object(s)
request_body = {
  :paymentMethod => {
    :type => 'afterpaytouch'
  },
  :amount => {
    :value => 1000,
    :currency => 'AUD'
  },
  :shopperName => {
    :firstName => 'Simon',
    :lastName => 'Hopper'
  },
  :shopperEmail => 's.hopper@example.com',
  :shopperReference => 'YOUR_UNIQUE_SHOPPER_ID',
  :reference => 'YOUR_ORDER_REFERENCE',
  :merchantAccount => 'ADYEN_MERCHANT_ACCOUNT',
  :returnUrl => 'https://your-company.example.com/checkout?shopperOrder=12xy..',
  :countryCode => 'AU',
  :telephoneNumber => '+61 2 8520 3890',
  :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',
    :amountExcludingTax => '331',
    :taxAmount => '69',
    :id => 'Item #1'
  }, {
    :description => 'Socks',
    :quantity => '2',
    :amountIncludingTax => '300',
    :amountExcludingTax => '248',
    :taxAmount => '52',
    :id => 'Item #2'
  } ]
}

# Send the request
result = adyen.checkout.payments_api.payments(request_body, headers: { 'Idempotency-Key' => 'UUID' })
```

#### NodeJS (TypeScript)

```ts
// Adyen Node API Library v18.0.0
// Require the parts of the module you want to use
import { Client, CheckoutAPI, Types } from "@adyen/api-library";
// Initialize the client object
// For the live environment, additionally include your liveEndpointUrlPrefix.
const client = new Client({apiKey: "ADYEN_API_KEY", environment: "TEST"});

// Create the request object(s)
const amount: Types.checkout.Amount = {
  currency: "AUD",
  value: 1000
};

const lineItem1: Types.checkout.LineItem = {
  quantity: 1,
  amountExcludingTax: 331,
  description: "Shoes",
  id: "Item #1",
  amountIncludingTax: 400,
  taxAmount: 69
};

const lineItem2: Types.checkout.LineItem = {
  quantity: 2,
  amountExcludingTax: 248,
  description: "Socks",
  id: "Item #2",
  amountIncludingTax: 300,
  taxAmount: 52
};

const name: Types.checkout.Name = {
  firstName: "Simon",
  lastName: "Hopper"
};

const deliveryAddress: Types.checkout.DeliveryAddress = {
  country: "AU",
  stateOrProvince: "NSW",
  city: "Sydney",
  houseNumberOrName: "123",
  street: "Happy Street",
  postalCode: "2000"
};

const afterpayDetails: Types.checkout.AfterpayDetails = {
  type: Types.checkout.AfterpayDetails.TypeEnum.Afterpaytouch
};

const billingAddress: Types.checkout.BillingAddress = {
  country: "AU",
  stateOrProvince: "NSW",
  city: "Sydney",
  houseNumberOrName: "123",
  street: "Happy Street",
  postalCode: "2000"
};

const paymentRequest: Types.checkout.PaymentRequest = {
  amount: amount,
  telephoneNumber: "+61 2 8520 3890",
  shopperEmail: "s.hopper@example.com",
  reference: "YOUR_ORDER_REFERENCE",
  lineItems: [lineItem1, lineItem2],
  shopperName: name,
  merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  deliveryAddress: deliveryAddress,
  countryCode: "AU",
  paymentMethod: afterpayDetails,
  billingAddress: billingAddress,
  returnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy..",
  shopperReference: "YOUR_UNIQUE_SHOPPER_ID"
};

// Send the request
const checkoutAPI = new CheckoutAPI(client);
const response = checkoutAPI.PaymentsApi.payments(paymentRequest, { idempotencyKey: "UUID" });
```

## Handle the redirect

You must [handle the additional action](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%2Bonly\&version=71#handle-the-redirect).

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](/online-payments/capture#delayed-automatic-capture) or use [manual capture](/online-payments/capture#capture-a-payment). 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](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/captures) request specify:

* [amount.value](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/captures#request-amount-value): the full or partial amount that the shopper should pay.
* [lineItems](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/captures#request-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](https://ca-test.adyen.com/ca/ca/contactUs/support.shtml?form=other). 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](/online-payments/cancel) it. If a payment has already been captured and you want to return the funds to the shopper, you need to [refund](/online-payments/refund) the payment.

### Full or partial refunds

To fully or partially refund a payment, in your [/payments/{paymentPspReference}/refunds](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/refunds) request specify:

* [amount.value](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/refunds#request-amount-value): the full or partial amount to be refunded to the shopper.
* [lineItems](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/refunds#request-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:

```json
{
  "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](/online-payments/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:

1. Make sure you receive the tokens that we generate for your shoppers:

   * [Enable tokenization webhooks](/online-payments/tokenization/create-tokens#enable-the-webhook). You will receive the token in a [recurring.token.created](https://docs.adyen.com/api-explorer/Tokenization-webhooks/latest/post/recurring.token.created) webhook.

   * To receive the token in the API response as well: in your [Customer Area](https://ca-test.adyen.com/) go to **Developers** > **Additional data settings** and enable **Recurring details**.

2. 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.

   ### Tab: Create a token with a payment

   Make a POST `/payments` request as usual, but add the [tokenization parameters](/online-payments/tokenization/make-token-payments).

   ```bash
   curl https://checkout-test.adyen.com/v72/payments \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'content-type: application/json' \
   -X POST
   -d '{
     "paymentMethod":{
       "type":"afterpaytouch"
     },
     "amount":{
        "value":1000,
        "currency":"AUD"
     },
     "countryCode":"AU",
     "shopperName":{
        "firstName":"Simon",
        "lastName":"Hopper"
     },
     "telephoneNumber":"+61 2 8520 3890",
     "shopperEmail":"s.hopper@example.com",
     "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
     "storePaymentMethod":"true",
     "recurringProcessingModel":"CardOnFile",
     "shopperInteraction":"Ecommerce",
     "reference":"YOUR_ORDER_REFERENCE",
     "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
     "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy..",
     "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",
           "amountExcludingTax": "331",
           "taxAmount": "69",
           "id":"Item #1"
        },
        {
           "description":"Socks",
           "quantity":"2",
           "amountIncludingTax":"300",
           "amountExcludingTax": "248",
           "taxAmount": "52",
           "id":"Item #2"
        }
     ]
   }'
   ```

   ### Tab: Create a token through zero-value authorization

   Make a POST `/payments` request with:

   * The [tokenization parameters](/online-payments/tokenization/create-tokens).
   * An `amount.value` of **0** (zero).

   ```bash
   curl https://checkout-test.adyen.com/v72/payments \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'content-type: application/json' \
   -X POST
   -d '{
     "paymentMethod":{
       "type":"afterpaytouch"
     },
     "amount":{
        "value":0,
        "currency":"AUD"
     },
     "countryCode":"AU",
     "shopperName":{
        "firstName":"Simon",
        "lastName":"Hopper"
     },
     "telephoneNumber":"+61 2 8520 3890",
     "shopperEmail":"s.hopper@example.com",
     "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
     "recurringProcessingModel":"CardOnFile",
     "storePaymentMethod":"true",
     "shopperInteraction":"Ecommerce",
     "reference":"YOUR_ORDER_REFERENCE",
     "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
     "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy..",
   }'
   ```

   The shopper is **redirected to Afterpay** as usual.

3. From the [recurring.token.created](https://docs.adyen.com/api-explorer/Tokenization-webhooks/latest/post/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](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details#responses-200-additionalData-ResponseAdditionalDataCommon) object.

4. If your request included paying the first installment, make sure the payment is [captured](#capture-the-payment).

5. In later payments for the same shopper, in your `/payments` request add the shopper's `storedPaymentMethodId`. See [Pay with a token](/online-payments/tokenization/make-token-payments) for more details.

   ```bash
   curl https://checkout-test.adyen.com/v72/payments \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'content-type: application/json' \
   -X POST
   -d '{
     "paymentMethod":{
       "type":"afterpaytouch",
       "storedPaymentMethodId":"M5N7TQ4TG5PFWR50"
     },
     "amount":{
        "value":1000,
        "currency":"AUD"
     },
     "countryCode":"AU",
     "shopperName":{
        "firstName":"Simon",
        "lastName":"Hopper"
     },
     "telephoneNumber":"+61 2 8520 3890",
     "shopperEmail":"s.hopper@example.com",
     "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
     "shopperInteraction":"ContAuth",
     "recurringProcessingModel":"CardOnFile",
     "reference":"YOUR_ORDER_REFERENCE",
     "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
     "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy..",
     "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",
           "amountExcludingTax": "331",
           "taxAmount": "69",
           "id":"Item #1"
        },
        {
           "description":"Socks",
           "quantity":"2",
           "amountIncludingTax":"300",
           "amountExcludingTax": "248",
           "taxAmount": "52",
           "id":"Item #2"
        }
     ]
   }'
   ```

   The shopper is **not redirected to Afterpay** because they have given their approval for the use of their stored payment details.

6. In the `/payments` response, note that this includes the `pspReference`.

   **/payments response for a tokenized payment**

   ```json
   {
     "amount": {
       "value": 1000,
       "currency": "AUD"
     },
     "resultCode": "Authorised",
     "afterpaytouch.consumerReference": "cdc4f629fdb91725ca22d693730184e67b3a3e7f46d66d4844dedf7ecf793b53",
     "pspReference": "VK9DRSLLRCQ2WN82",
     "paymentMethod": {
       "type": "afterpaytouch"
     },
     "merchantReference": "YOUR_ORDER_REFERENCE"
   }
   ```

7. 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:

1. Go to <https://portal.sandbox.afterpay.com/>.
2. Enter a real email address and select **Continue**. You'll get confirmations of payments and refunds like any other shopper on this email address.
3. 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**.
4. Enter a unique mobile number in the correct format and select **Continue**. Ensure the number is not associated with an existing account to avoid being redirected to a login page.
5. When you are prompted to enter your SMS verification code, enter **111111**.
6. 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](https://developers.afterpay.com/afterpay-online-developer/home), or use one of the Adyen [test cards](/development-resources/test-cards-and-credentials/test-card-numbers). 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](https://ca-test.adyen.com/) > **Transactions** > **Payments**.

Before you can accept live Afterpay payments, you need to [submit a request for Afterpay](/payment-methods/add-payment-methods) in your [live Customer Area](https://ca-live.adyen.com/).

## See also

* [API-only integration guide](/online-payments/api-only)
* [Webhooks](/development-resources/webhooks)
* [API Explorer](https://docs.adyen.com/api-explorer/#/CheckoutService/latest/overview)
