Search

Are you looking for test card numbers?

Would you like to contact support?

Payment-method icon

Affirm for API only

Add Affirm to an existing API-only integration.

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.
  2. Capture the payment after the transaction has been fulfilled. When the payment has been captured, Affirm starts the repayment period for the shopper.

Before you begin

These instructions explain how to add Affirm to your existing API-only integration. The API-only integration works the same way for all payment methods. If you haven't done this integration yet, refer to our API-only integration guide.

Before starting your integration:

  1. Make sure that you have set up your back end implementation.
  2. Add Affirm in your test Customer Area.

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.

Make a payment

From your server, make a /payments request, specifying:

Parameter name Required Description
paymentMethod.type -white_check_mark- Set to affirm.
shopperName.firstName -white_check_mark- Shopper's first name.
shopperName.lastName -white_check_mark- Shopper's last name.
telephoneNumber -white_check_mark- Shopper's telephone number.
shopperEmail -white_check_mark- Shopper's email address.
billingAddress -white_check_mark- The address where to send the invoice.
deliveryAddress -x- The address where the purchased goods should be delivered. If blank or missing, billingAddress is used by default.
lineItems -x- Price and product information about the purchased items. This is optional, but we recommend to include this data to improve approval rates.
curl https://checkout-test.adyen.com/v67/payments \
-H "x-API-key: YOUR_X-API-KEY" \
-H "content-type: application/json" \
-d '{
    "merchantAccount":"YOUR_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.com/checkout?shopperOrder=12xy..",
    "lineItems":[
       {
          "quantity": "1",
          "amountExcludingTax": "331",
          "description": "Shoes",
          "id": "Item #1",
          "taxAmount": "69",
          "productUrl": "https://your-company.com/item1/",
          "imageUrl": "https://your-company.com/item1.jpg"
       },
       {
          "quantity": "2",
          "amountExcludingTax": "248",
          "description": "Socks",
          "id": "Item #2",
          "taxAmount": "52",
          "productUrl": "https://your-company.com/item2/",
          "imageUrl": "https://your-company.com/item2.jpg"
       }
    ]
}
# Set your X-API-KEY with the API key from the Customer Area.
adyen = Adyen::Client.new
adyen.env = :test
adyen.api_key = "YOUR_X-API-KEY"

response = adyen.checkout.payments({
  :merchantAccount => "YOUR_MERCHANT_ACCOUNT",
  :returnUrl => "https://your-company.com/checkout?shopperOrder=12xy..",
  :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 => "+12123456789",
  :shopperEmail => "s.hopper@example.com",
  :billingAddress => {
      :street => "Brannan St.",
      :houseNumberOrName => "274",
      :city => "San Francisco",
      :postalCode => "94107",
      :stateOrProvince: "CA",
      :country => "US"
  },
  :deliveryAddress => {
      :street => "Brannan St.",
      :houseNumberOrName => "274",
      :city => "San Francisco",
      :postalCode => "94107",
      :stateOrProvince: "CA",
      :country => "US"
  },
  :lineItems => [
    {
      :quantity => "1",
      :amountExcludingTax => "331",
      :description => "Shoes",
      :id => "Item #1",
      :taxAmount => "69",
      :productUrl => "https://your-company.com/item1/",
      :imageUrl => "https://your-company.com/item1.jpg"
    },
    {
      :quantity => "2",
      :amountExcludingTax => "248",
      :description => "Socks",
      :id => "Item #2",
      :taxAmount => "52",
      :productUrl => "https://your-company.com/item2/",
      :imageUrl => "https://your-company.com/item2.jpg"
    }
  ]
})
Client client = new Client("YOUR_API_KEY", Environment.TEST);

Checkout checkout = new Checkout(client);

PaymentsRequest paymentsRequest = new PaymentsRequest();
paymentsRequest.setMerchantAccount("YOUR_MERCHANT_ACCOUNT");
paymentsRequest.setCountryCode("US");

Amount amount = new Amount();
amount.setCurrency("USD");
amount.setValue(1000L);

paymentsRequest.setAmount(amount);
paymentsRequest.setShopperReference("YOUR_UNIQUE_SHOPPER_ID");
paymentsRequest.setReference("YOUR_ORDER_NUMBER");
paymentsRequest.setChannel(PaymentsRequest.ChannelEnum.WEB);

DefaultPaymentMethodDetails defaultPaymentMethodDetails = new DefaultPaymentMethodDetails();
defaultPaymentMethodDetails.setType("affirm");
paymentsRequest.setPaymentMethod(defaultPaymentMethodDetails);

Name shopperName = new Name();
shopperName.setFirstName("Simon");
shopperName.setLastName("Hopper");

paymentsRequest.setTelephoneNumber("+12121234567");
paymentsRequest.setShopperEmail("s.hopper@example.com");

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

paymentsRequest.setBillingAddress(billingAddress);

Address deliveryAddress = new Address();

deliveryAddress.setStreet("Brannan St.");
deliveryAddress.setHouseNumberOrName("274");
deliveryAddress.setCity("San Francisco");
deliveryAddress.setPostalCode("94107");
deliveryAddress.setStateOrProvince("CA");
deliveryAddress.setCountry("US");

paymentsRequest.setDeliveryAddress(deliveryAddress);
paymentsRequest.setReturnUrl("https://your-company.com/checkout?shopperOrder=12xy..");

List<LineItem> lineItems = new ArrayList<>();

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

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

paymentsRequest.setLineItems(lineItems);

PaymentsResponse paymentsResponse = checkout.payments(paymentsRequest);
// Set your X-API-KEY with the API key from the Customer Area.
$client = new \Adyen\Client();
$client->setXApiKey("YOUR_X-API-KEY");
$service = new \Adyen\Service\Checkout($client);

$params = [
  "merchantAccount" => "YOUR_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" => "+12123456789",
  "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.com/checkout?shopperOrder=12xy..",
  "lineItems" => [
     [
        "quantity" => "1",
        "amountExcludingTax" => "331",
        "description" => "Shoes",
        "id" => "Item #1",
        "taxAmount" => "69",
        "productUrl" => "https://your-company.com/item1/",
        "imageUrl" => "https://your-company.com/item1.jpg"
     ],
     [
        "quantity" => "2",
        "amountExcludingTax" => "248",
        "description" => "Socks",
        "id" => "Item #2",
        "taxAmount" => "52",
        "productUrl" => "https://your-company.com/item2",
        "imageUrl" => "https://your-company.com/item2.jpg"
     ]
  ]
];

$result = $service->payments($params);

// Check if further action is needed
if (array_key_exists("action", $result)){
   // Pass the action object to your frontend.
   // $result["action"]
}
else {
   // No further action needed, pass the resultCode to your front end
   // $result['resultCode']
}
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Set your X-API-KEY with the API key from the Customer Area.

adyen = Adyen.Adyen()
adyen.client.xapikey = "YOUR_X-API-KEY"

result = adyen.checkout.payments({
    "merchantAccount": "YOUR_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": "+12121234567",
    "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.com/checkout?shopperOrder=12xy..",
    "lineItems": [
    {
        "quantity": "1",
        "amountExcludingTax": "331",
        "description": "Shoes",
        "id": "Item #1",
        "taxAmount": "69",
        "productUrl": "https://your-company.com/item1/",
        "imageUrl": "https://your-company.com/item1.jpg"
        },
        {
        "quantity": "2",
        "amountExcludingTax": "248",
        "description": "Socks",
        "id": "Item #2",
        "taxAmount": "52",
        "productUrl": "https://your-company.com/item2/",
        "imageUrl": "https://your-company.com/item2.jpg"
        }
    ]
})
var paymentRequest = new Adyen.Model.Checkout.PaymentRequest
{
    MerchantAccount = "YOUR_MERCHANT_ACCOUNT",
    CountryCode = "US",
    Amount = new Adyen.Model.Checkout.Amount("USD", 1000),
    ShopperReference = "YOUR_UNIQUE_SHOPPER_ID",
    Reference = "YOUR_ORDER_NUMBER",
    Channel = Adyen.Model.Checkout.PaymentRequest.ChannelEnum.Web,
    TelephoneNumber = "+12121234567",
    ShopperEmail= "s.hopper@example.com",
    ReturnUrl = "https://your-company.com/checkout?shopperOrder=12xy..",

    LineItems = new List<LineItem>
    {
        new LineItem(AmountExcludingTax: 331, Quantity: 1, Id: "Item #1", TaxAmount: 69, Description: "Shoes", ProductUrl: "https://your-company.com/item1/", ImageUrl: "https://your-company.com/item1.jpg"),
        new LineItem(AmountExcludingTax: 248, Quantity: 2, Id: "Item #2", TaxAmount: 52, Description: "Socks", ProductUrl: "https://your-company.com/item2/", ImageUrl: "https://your-company.com/item2.jpg")
    },
    PaymentMethod = new DefaultPaymentMethodDetails
    {
        Type = "affirm",

        BillingAddress = new Address(Country: "US")
        {
            City = "San Francisco",
            HouseNumberOrName = "274",
            PostalCode = "94107",
            StateOrProvince = "CA",
            Street = "Brannan St."
        },
        DeliveryAddress = new Address
        {
            City = "San Francisco",
            HouseNumberOrName = "274",
            PostalCode = "94107",
            StateOrProvince = "CA",
            Street = "Brannan St."
        },
    },
    ShopperName = new Name
    {
        FirstName = "Simon",
        LastName = "Hopper"
    }
};
// Set your X-API-KEY with the API key from the Customer Area.
const {Client, Config, CheckoutAPI} = require('@adyen/api-library');
const config = new Config();
// Set your X-API-KEY with the API key from the Customer Area.
config.apiKey = '[API_KEY]';
config.merchantAccount = '[MERCHANT_ACCOUNT]';
const client = new Client({ config });
client.setEnvironment("TEST");
const checkout = new CheckoutAPI(client);
checkout.payments({
  merchantAccount: "YOUR_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: "+12121234567",
  shopperEmail: "s.hopper@example.com",
  billingAddress: {
     street: "Brannan St.",
     houseNumberOrName: "274",
     city: "San Francisco",
     postalCode: "94107",
     stateOrProvince: "CA",
     country: "US"
  },
  deliveryAddress: {
     street: "Brannan St.",
     houseNumberOrName: "274",
     city: "San Francisco",
     postalCode: "94107",
     stateOrProvince: "CA",
     country: "US"
  },
  returnUrl: "https://your-company.com/checkout?shopperOrder=12xy..",
  lineItems: [
     {
        quantity: "1",
        amountExcludingTax: "331",
        taxPercentage: "2100",
        description: "Shoes",
        id: "Item 1",
        taxAmount: "69",
        productUrl: "https://your-company.com/item1/",
        imageUrl: "https://your-company.com/item1.jpg"
     },
     {
        quantity: "2",
        amountExcludingTax: "248",
        taxPercentage: "2100",
        description: "Socks",
        id: "Item 2",
        taxAmount: "52",
        productUrl: "https://your-company.com/item2/",
        imageUrl: "https://your-company.com/item2.jpg"
     }
  ]
}).then(res => res);

The /payments response contains an action object with the information needed to redirect the shopper.

/payments response
{
   "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 response.
    When using the HTTP GET method:
    For security reasons, when displaying the redirect in the app, we recommend that you use SFSafariViewController for iOS or Chrome Custom Tabs for Android, instead of WebView objects. Also refer to the security best practices for WebView.
  2. After the shopper is redirected back to your website, check the payment result by making a 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
    curl https://checkout-test.adyen.com/v67/payments/details \
    -H "x-API-key: YOUR_X-API-KEY" \
    -H "content-type: application/json" \
    -d '{
       "details": {
         "redirectResult": "eyJ0cmFuc1N0YXR1cyI6IlkifQ=="
     }
    }'

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"
    }

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 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 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'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 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 manually captured, even if you have enabled automatic capture for other payment methods. Capturing the payment is what triggers the installment payment schedule for the shopper.

If for any reason you need to capture a lesser amount than what was authorised, you need to issue a refund for the difference after the capture. For example, a customer purchases two items of $500 each, totaling $1.000, but only one is fulfilled. After capturing $1.000, you should issue a subsequent refund for the unfulfilled item of $500.

Refunds and cancellations

If an Affirm payment hasn't been captured yet, you can cancel it. If the Affirm 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 Affirm payment, specify in your /payments/{paymentPspReference}/refunds 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.

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

/refund request
{
   "merchantAccount":"YOUR_MERCHANT_ACCOUNT",
   "originalReference":"COPY_PSP_REFERENCE_FROM_AUTHORISE_RESPONSE",
   "modificationAmount":{
      "currency":"USD",
      "value":"400"
   },
   "reference":"YOUR_REFUND_REFERENCE"
}

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 > Transactions > Payments.

Before you can accept live Affirm payments, you need to submit a request for Affirm in your live Customer Area, and provide us with your Affirm live credentials.

See also