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

# Affirm for API only

Add Affirm to an existing API-only integration.

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

Accept Affirm payments using our APIs, and build your own payment form to have full control over the look and feel of your checkout page.

When making an Affirm payment, you also need to:

1. Provide details about the items being purchased [when making a payment request](#make-a-payment).
2. [Capture](#capture-the-payment) the payment after the transaction has been fulfilled. When the payment has been captured, Affirm starts the repayment period for the shopper.

## Requirements

| Requirement          | Description                                                                                                                                          |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Integration type** | Make sure that you have built an [API-only integration](/online-payments/build-your-integration/advanced-flow?platform=Web\&integration=API%20only). |
| **Setup steps**      | Before you begin, [add Affirm in your test Customer Area](/payment-methods/add-payment-methods).                                                     |

## Build your payment form for Affirm

To make an Affirm payment, you need to collect the following shopper details:

| Name              | Description                                                |
| ----------------- | ---------------------------------------------------------- |
| `firstName`       | Shopper's first name.                                      |
| `lastName`        | Shopper's last name.                                       |
| `telephoneNumber` | Shopper's phone number.                                    |
| `shopperEmail`    | Shopper's email address.                                   |
| `billingAddress`  | The address where to send the invoice.                     |
| `deliveryAddress` | The address where the purchased goods should be delivered. |

We provide an Affirm logo which you can use in your payment form. For more information, refer to [Downloading logos](/online-payments/build-your-integration/advanced-flow/?platform=Web\&integration=API%20only#downloading-logos).

## Make a payment

From your server, make a [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) request, specifying:

| Parameter name                                                                                                 | Required                                                                                    | Description                                                                                                                                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `paymentMethod.type`                                                                                           | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | Set to **affirm**.                                                                                                                                                                                                                          |
| [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-") | Shopper's first name and last name.                                                                                                                                                                                                         |
| [telephoneNumber](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-telephoneNumber)   | ![-white\_check\_mark-](/user/data/smileys/emoji/white_check_mark.png "-white_check_mark-") | The shopper's phone number.                                                                                                                                                                                                                 |
| [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)           |                                                                                             | The shopper's country in two-letter [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) format.Required when transacting in Canada or the United Kingdom, because the default **US** is used if you omit this parameter. |
| [billingAddress](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-billingAddress)     |                                                                                             | The address where to send the invoice. The `stateOrProvince` address field is required for Canada and the US, and optional for the UK.                                                                                                      |
| [deliveryAddress](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-deliveryAddress)   |                                                                                             | The address where the purchased goods should be delivered. The `stateOrProvince` address field is required for Canada and the US, and optional for the UK. If blank or missing, `billingAddress` is used by default.                        |
| [lineItems](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments#request-lineItems)               |                                                                                             | Price and product information about the purchased items. This is optional, but we recommend to include this data to improve approval rates.                                                                                                 |

#### curl

```bash
curl https://checkout-test.adyen.com/v68/payments \
-H 'x-api-key: ADYEN_API_KEY' \
-H 'content-type: application/json' \
-d '{
    "merchantAccount":"ADYEN_MERCHANT_ACCOUNT",
    "countryCode":"US",
    "amount":{
       "currency":"USD",
       "value": 1000
    },
    "shopperReference":"YOUR_UNIQUE_SHOPPER_ID",
    "reference":"YOUR_ORDER_NUMBER",
    "channel": "Web",
    "paymentMethod": {
        "type": "affirm"
      },
    "shopperName": {
      "firstName": "Simon",
      "lastName": "Hopper"
    },
    "telephoneNumber": "+31612345678",
    "shopperEmail": "s.hopper@example.com",
    "billingAddress": {
      "city": "San Francisco",
      "country": "US",
      "houseNumberOrName": "274",
      "postalCode": "94107",
      "stateOrProvince": "CA",
      "street": "Brannan St."
    },
    "deliveryAddress": {
      "city": "San Francisco",
      "country": "US",
      "houseNumberOrName": "274",
      "postalCode": "94107",
      "stateOrProvince": "CA",
      "street": "Brannan St."
    },
	  "returnUrl":"https://your-company.example.com/checkout?shopperOrder=12xy..",
    "lineItems":[
       {
          "quantity": "1",
          "amountExcludingTax": "331",
          "description": "Shoes",
          "id": "Item #1",
          "taxAmount": "69",
          "productUrl": "https://your-company.example.com/item1/",
          "imageUrl": "https://your-company.example.com/item1.jpg"
       },
       {
          "quantity": "2",
          "amountExcludingTax": "248",
          "description": "Socks",
          "id": "Item #2",
          "taxAmount": "52",
		      "productUrl": "https://your-company.example.com/item2/",
          "imageUrl": "https://your-company.example.com/item2.jpg"
       }
    ]
}'
```

#### 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("USD")
  .value(1000L);

LineItem lineItem1 = new LineItem()
  .quantity(1L)
  .amountExcludingTax(331L)
  .imageUrl("https://your-company.example.com/item1.jpg")
  .description("Shoes")
  .id("Item #1")
  .taxAmount(69L)
  .productUrl("https://your-company.example.com/item1/");

LineItem lineItem2 = new LineItem()
  .quantity(2L)
  .amountExcludingTax(248L)
  .imageUrl("https://your-company.example.com/item2.jpg")
  .description("Socks")
  .id("Item #2")
  .taxAmount(52L)
  .productUrl("https://your-company.example.com/item2/");

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

DeliveryAddress deliveryAddress = new DeliveryAddress()
  .country("US")
  .stateOrProvince("CA")
  .city("San Francisco")
  .houseNumberOrName("274")
  .street("Brannan St.")
  .postalCode("94107");

PaymentDetails paymentDetails = new PaymentDetails()
  .type(PaymentDetails.TypeEnum.AFFIRM);

BillingAddress billingAddress = new BillingAddress()
  .country("US")
  .stateOrProvince("CA")
  .city("San Francisco")
  .houseNumberOrName("274")
  .street("Brannan St.")
  .postalCode("94107");

PaymentRequest paymentRequest = new PaymentRequest()
  .amount(amount)
  .telephoneNumber("+31612345678")
  .channel(PaymentRequest.ChannelEnum.WEB)
  .shopperEmail("s.hopper@example.com")
  .reference("YOUR_ORDER_NUMBER")
  .lineItems(Arrays.asList(lineItem1, lineItem2))
  .shopperName(name)
  .merchantAccount("ADYEN_MERCHANT_ACCOUNT")
  .deliveryAddress(deliveryAddress)
  .countryCode("US")
  .paymentMethod(new CheckoutPaymentMethod(paymentDetails))
  .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("USD")
  ->setValue(1000);

$lineItem1 = new LineItem();
$lineItem1
  ->setQuantity(1)
  ->setAmountExcludingTax(331)
  ->setImageUrl("https://your-company.example.com/item1.jpg")
  ->setDescription("Shoes")
  ->setId("Item #1")
  ->setTaxAmount(69)
  ->setProductUrl("https://your-company.example.com/item1/");

$lineItem2 = new LineItem();
$lineItem2
  ->setQuantity(2)
  ->setAmountExcludingTax(248)
  ->setImageUrl("https://your-company.example.com/item2.jpg")
  ->setDescription("Socks")
  ->setId("Item #2")
  ->setTaxAmount(52)
  ->setProductUrl("https://your-company.example.com/item2/");

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

$deliveryAddress = new DeliveryAddress();
$deliveryAddress
  ->setCountry("US")
  ->setStateOrProvince("CA")
  ->setCity("San Francisco")
  ->setHouseNumberOrName("274")
  ->setStreet("Brannan St.")
  ->setPostalCode("94107");

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

$billingAddress = new BillingAddress();
$billingAddress
  ->setCountry("US")
  ->setStateOrProvince("CA")
  ->setCity("San Francisco")
  ->setHouseNumberOrName("274")
  ->setStreet("Brannan St.")
  ->setPostalCode("94107");

$paymentRequest = new PaymentRequest();
$paymentRequest
  ->setAmount($amount)
  ->setTelephoneNumber("+31612345678")
  ->setChannel("Web")
  ->setShopperEmail("s.hopper@example.com")
  ->setReference("YOUR_ORDER_NUMBER")
  ->setLineItems(array($lineItem1, $lineItem2))
  ->setShopperName($name)
  ->setMerchantAccount("ADYEN_MERCHANT_ACCOUNT")
  ->setDeliveryAddress($deliveryAddress)
  ->setCountryCode("US")
  ->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 = "USD",
  Value = 1000
};

LineItem lineItem1 = new LineItem
{
  Quantity = 1,
  AmountExcludingTax = 331,
  ImageUrl = "https://your-company.example.com/item1.jpg",
  Description = "Shoes",
  Id = "Item #1",
  TaxAmount = 69,
  ProductUrl = "https://your-company.example.com/item1/"
};

LineItem lineItem2 = new LineItem
{
  Quantity = 2,
  AmountExcludingTax = 248,
  ImageUrl = "https://your-company.example.com/item2.jpg",
  Description = "Socks",
  Id = "Item #2",
  TaxAmount = 52,
  ProductUrl = "https://your-company.example.com/item2/"
};

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

DeliveryAddress deliveryAddress = new DeliveryAddress
{
  Country = "US",
  StateOrProvince = "CA",
  City = "San Francisco",
  HouseNumberOrName = "274",
  Street = "Brannan St.",
  PostalCode = "94107"
};

PaymentDetails paymentDetails = new PaymentDetails
{
  Type = PaymentDetails.TypeEnum.Affirm
};

BillingAddress billingAddress = new BillingAddress
{
  Country = "US",
  StateOrProvince = "CA",
  City = "San Francisco",
  HouseNumberOrName = "274",
  Street = "Brannan St.",
  PostalCode = "94107"
};

PaymentRequest paymentRequest = new PaymentRequest
{
  Amount = amount,
  TelephoneNumber = "+31612345678",
  Channel = PaymentRequest.ChannelEnum.Web,
  ShopperEmail = "s.hopper@example.com",
  Reference = "YOUR_ORDER_NUMBER",
  LineItems = new List<LineItem>{ lineItem1, lineItem2 },
  ShopperName = name,
  MerchantAccount = "ADYEN_MERCHANT_ACCOUNT",
  DeliveryAddress = deliveryAddress,
  CountryCode = "US",
  PaymentMethod = new CheckoutPaymentMethod(paymentDetails),
  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 = {
  merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  countryCode: "US",
  amount: {
    currency: "USD",
    value: 1000
  },
  shopperReference: "YOUR_UNIQUE_SHOPPER_ID",
  reference: "YOUR_ORDER_NUMBER",
  channel: "Web",
  paymentMethod: {
    type: "affirm"
  },
  shopperName: {
    firstName: "Simon",
    lastName: "Hopper"
  },
  telephoneNumber: "+31612345678",
  shopperEmail: "s.hopper@example.com",
  billingAddress: {
    city: "San Francisco",
    country: "US",
    houseNumberOrName: "274",
    postalCode: "94107",
    stateOrProvince: "CA",
    street: "Brannan St."
  },
  deliveryAddress: {
    city: "San Francisco",
    country: "US",
    houseNumberOrName: "274",
    postalCode: "94107",
    stateOrProvince: "CA",
    street: "Brannan St."
  },
  returnUrl: "https://your-company.example.com/checkout?shopperOrder=12xy..",
  lineItems: [ {
    quantity: "1",
    amountExcludingTax: "331",
    description: "Shoes",
    id: "Item #1",
    taxAmount: "69",
    productUrl: "https://your-company.example.com/item1/",
    imageUrl: "https://your-company.example.com/item1.jpg"
  }, {
    quantity: "2",
    amountExcludingTax: "248",
    description: "Socks",
    id: "Item #2",
    taxAmount: "52",
    productUrl: "https://your-company.example.com/item2/",
    imageUrl: "https://your-company.example.com/item2.jpg"
  } ]
}

// 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: "USD",
  Value: 1000,
}

lineItem1 := checkout.LineItem{
  Quantity: common.PtrInt64(1),
  AmountExcludingTax: common.PtrInt64(331),
  ImageUrl: common.PtrString("https://your-company.example.com/item1.jpg"),
  Description: common.PtrString("Shoes"),
  Id: common.PtrString("Item #1"),
  TaxAmount: common.PtrInt64(69),
  ProductUrl: common.PtrString("https://your-company.example.com/item1/"),
}

lineItem2 := checkout.LineItem{
  Quantity: common.PtrInt64(2),
  AmountExcludingTax: common.PtrInt64(248),
  ImageUrl: common.PtrString("https://your-company.example.com/item2.jpg"),
  Description: common.PtrString("Socks"),
  Id: common.PtrString("Item #2"),
  TaxAmount: common.PtrInt64(52),
  ProductUrl: common.PtrString("https://your-company.example.com/item2/"),
}

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

deliveryAddress := checkout.DeliveryAddress{
  Country: "US",
  StateOrProvince: common.PtrString("CA"),
  City: "San Francisco",
  HouseNumberOrName: "274",
  Street: "Brannan St.",
  PostalCode: "94107",
}

paymentDetails := checkout.PaymentDetails{
  Type: common.PtrString("affirm"),
}

billingAddress := checkout.BillingAddress{
  Country: "US",
  StateOrProvince: common.PtrString("CA"),
  City: "San Francisco",
  HouseNumberOrName: "274",
  Street: "Brannan St.",
  PostalCode: "94107",
}

paymentRequest := checkout.PaymentRequest{
  Amount: amount,
  TelephoneNumber: common.PtrString("+31612345678"),
  Channel: common.PtrString("Web"),
  ShopperEmail: common.PtrString("s.hopper@example.com"),
  Reference: "YOUR_ORDER_NUMBER",
  LineItems: []checkout.LineItem{
      lineItem1, lineItem2,
  },
  ShopperName: &name,
  MerchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  DeliveryAddress: &deliveryAddress,
  CountryCode: common.PtrString("US"),
  PaymentMethod: checkout.PaymentDetailsAsCheckoutPaymentMethod(&paymentDetails),
  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 = {
  "merchantAccount": "ADYEN_MERCHANT_ACCOUNT",
  "countryCode": "US",
  "amount": {
    "currency": "USD",
    "value": 1000
  },
  "shopperReference": "YOUR_UNIQUE_SHOPPER_ID",
  "reference": "YOUR_ORDER_NUMBER",
  "channel": "Web",
  "paymentMethod": {
    "type": "affirm"
  },
  "shopperName": {
    "firstName": "Simon",
    "lastName": "Hopper"
  },
  "telephoneNumber": "+31612345678",
  "shopperEmail": "s.hopper@example.com",
  "billingAddress": {
    "city": "San Francisco",
    "country": "US",
    "houseNumberOrName": "274",
    "postalCode": "94107",
    "stateOrProvince": "CA",
    "street": "Brannan St."
  },
  "deliveryAddress": {
    "city": "San Francisco",
    "country": "US",
    "houseNumberOrName": "274",
    "postalCode": "94107",
    "stateOrProvince": "CA",
    "street": "Brannan St."
  },
  "returnUrl": "https://your-company.example.com/checkout?shopperOrder=12xy..",
  "lineItems": [ {
    "quantity": "1",
    "amountExcludingTax": "331",
    "description": "Shoes",
    "id": "Item #1",
    "taxAmount": "69",
    "productUrl": "https://your-company.example.com/item1/",
    "imageUrl": "https://your-company.example.com/item1.jpg"
  }, {
    "quantity": "2",
    "amountExcludingTax": "248",
    "description": "Socks",
    "id": "Item #2",
    "taxAmount": "52",
    "productUrl": "https://your-company.example.com/item2/",
    "imageUrl": "https://your-company.example.com/item2.jpg"
  } ]
}

# 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 = {
  :merchantAccount => 'ADYEN_MERCHANT_ACCOUNT',
  :countryCode => 'US',
  :amount => {
    :currency => 'USD',
    :value => 1000
  },
  :shopperReference => 'YOUR_UNIQUE_SHOPPER_ID',
  :reference => 'YOUR_ORDER_NUMBER',
  :channel => 'Web',
  :paymentMethod => {
    :type => 'affirm'
  },
  :shopperName => {
    :firstName => 'Simon',
    :lastName => 'Hopper'
  },
  :telephoneNumber => '+31612345678',
  :shopperEmail => 's.hopper@example.com',
  :billingAddress => {
    :city => 'San Francisco',
    :country => 'US',
    :houseNumberOrName => '274',
    :postalCode => '94107',
    :stateOrProvince => 'CA',
    :street => 'Brannan St.'
  },
  :deliveryAddress => {
    :city => 'San Francisco',
    :country => 'US',
    :houseNumberOrName => '274',
    :postalCode => '94107',
    :stateOrProvince => 'CA',
    :street => 'Brannan St.'
  },
  :returnUrl => 'https://your-company.example.com/checkout?shopperOrder=12xy..',
  :lineItems => [ {
    :quantity => '1',
    :amountExcludingTax => '331',
    :description => 'Shoes',
    :id => 'Item #1',
    :taxAmount => '69',
    :productUrl => 'https://your-company.example.com/item1/',
    :imageUrl => 'https://your-company.example.com/item1.jpg'
  }, {
    :quantity => '2',
    :amountExcludingTax => '248',
    :description => 'Socks',
    :id => 'Item #2',
    :taxAmount => '52',
    :productUrl => 'https://your-company.example.com/item2/',
    :imageUrl => 'https://your-company.example.com/item2.jpg'
  } ]
}

# 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: "USD",
  value: 1000
};

const lineItem1: Types.checkout.LineItem = {
  quantity: 1,
  amountExcludingTax: 331,
  imageUrl: "https://your-company.example.com/item1.jpg",
  description: "Shoes",
  id: "Item #1",
  taxAmount: 69,
  productUrl: "https://your-company.example.com/item1/"
};

const lineItem2: Types.checkout.LineItem = {
  quantity: 2,
  amountExcludingTax: 248,
  imageUrl: "https://your-company.example.com/item2.jpg",
  description: "Socks",
  id: "Item #2",
  taxAmount: 52,
  productUrl: "https://your-company.example.com/item2/"
};

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

const deliveryAddress: Types.checkout.DeliveryAddress = {
  country: "US",
  stateOrProvince: "CA",
  city: "San Francisco",
  houseNumberOrName: "274",
  street: "Brannan St.",
  postalCode: "94107"
};

const paymentDetails: Types.checkout.PaymentDetails = {
  type: Types.checkout.PaymentDetails.TypeEnum.Affirm
};

const billingAddress: Types.checkout.BillingAddress = {
  country: "US",
  stateOrProvince: "CA",
  city: "San Francisco",
  houseNumberOrName: "274",
  street: "Brannan St.",
  postalCode: "94107"
};

const paymentRequest: Types.checkout.PaymentRequest = {
  amount: amount,
  telephoneNumber: "+31612345678",
  channel: Types.checkout.PaymentRequest.ChannelEnum.Web,
  shopperEmail: "s.hopper@example.com",
  reference: "YOUR_ORDER_NUMBER",
  lineItems: [lineItem1, lineItem2],
  shopperName: name,
  merchantAccount: "ADYEN_MERCHANT_ACCOUNT",
  deliveryAddress: deliveryAddress,
  countryCode: "US",
  paymentMethod: paymentDetails,
  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" });
```

In the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) response, check the `action` object for the information that you must use to redirect the shopper.

**/payments response**

```json
{
  "resultCode":"RedirectShopper",
  "action":{
    "paymentMethodType":"affirm",
    "method":"GET",
    "url":"https://checkoutshopper-test.adyen.com/checkoutshopper/checkoutPaymentRedirect?redirectData=...",
    "type":"redirect"
  }
}
```

## Handle the redirect

1. To complete the payment, redirect the shopper to the `action.url` returned in the [/payments](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments) response, taking into account the following recommendations:

   * **When using the HTTP GET method:**\
     For security reasons, when showing the redirect in the app, we recommend that you use [SFSafariViewController](https://developer.apple.com/documentation/safariservices/sfsafariviewcontroller) for iOS or [Chrome Custom Tabs](https://developer.chrome.com/multidevice/android/customtabs) for Android, instead of WebView objects. Also refer to the [security best practices](https://developer.android.com/topic/security/best-practices#webview) for WebView.

   * **Redirection for mobile integrations:**\
     For mobile integrations, we strongly recommended that you redirect the shopper to the default browser of their device. Redirecting to the default browser ensures the best compatibility, handling of multi-factor authentication, app-to-app redirection, and error handling.

2. After the shopper is redirected back to your website, check the payment result by making a POST [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) request, specifying:

   * `details`: object that contains the URL-decoded `redirectResult` returned when the shopper was redirected back to your site.

   **/payments/details request**

   ```bash
   curl https://checkout-test.adyen.com/v72/payments/details \
   -H 'x-api-key: ADYEN_API_KEY' \
   -H 'content-type: application/json' \
   -d '{
      "details": {
         "redirectResult": "eyJ0cmFuc1N0YXR1cyI6IlkifQ=="
      }
   }'
   ```

3. In the response note the following:

   * `resultCode`: use this to present the result to your shopper.
   * `pspReference`: our unique identifier for the transaction.

   **/payments/details response**

   ```json
   {
      "resultCode": "Authorised",
      "pspReference": "V4HZ4RBFJGXXGN82"
   }
   ```

## Present the payment result

Use the  [resultCode](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details#responses-200-resultCode) that you received in the [/payments/details](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/details) response to present the payment result to your shopper.

The `resultCode` values you can receive for Affirm 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](#capture-the-payment) the payment.                                                                                     |
| **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**    | The shopper has completed the payment but the final result is not yet known. | Inform the shopper that you have received their order, and are waiting for the payment to be completed. To know the final result of the payment, wait for the [AUTHORISATION webhook](/development-resources/webhooks/webhook-types). |
| **Refused**    | The payment was refused by Affirm.                                           | 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 Affirm payments have to be captured within 28 days. Capturing the payment is what triggers the installment payment schedule for the shopper. If you do not capture the payment within 28 days, the authorization will expire.

If for any reason you need to capture a lesser amount than what was authorised, you need to issue a [refund](/online-payments/refund) for the difference after the capture. For example, a customer purchases two items of USD 500 each, totaling USD 1,000, but only one is fulfilled. After capturing USD 1,000, you should issue a subsequent refund for the unfulfilled item of USD 500.

## Refunds and cancellations

If an Affirm payment hasn't been captured yet, you can [cancel](/online-payments/cancel) it. If the Affirm payment has already been captured and you want to return the funds to the shopper, you need to [refund](/online-payments/refund) it.

### Partial refunds

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

* [amount](https://docs.adyen.com/api-explorer/Checkout/latest/post/payments/\(paymentPspReference\)/refunds#request-amount): The amount to refund to the shopper.

## Test and go live

To receive your test credentials, contact Affirm. After reviewing your test transactions, Affirm will provide you with the credentials for processing live transactions.

You can check the status of the test payments in your [test Customer Area](https://ca-test.adyen.com/) > **Transactions** > **Payments**.

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

## See also

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