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 the shopper's IP address and information about the purchased items when making a payment request.
  2. Capture the payment after the goods have been sent. This triggers the invoice to be sent to the shopper.

Before you begin

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 not sent, billingAddress is used by default.
shopperIP -white_check_mark- The shopper's IP address. Affirm uses this for risk checks.
lineItems -white_check_mark- Price and product information about the purchased items. This is included on the invoice that Affirm sends to the shopper.
curl https://checkout-test.adyen.com/v64/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",
    "{hint:state.data.billingAddress from onSubmit}billingAddress{/hint}": {
      "city": "Boulder",
      "country": "US",
      "houseNumberOrName": "242",
      "postalCode": "80302",
      "stateOrProvince": "CO",
      "street": "Silver Cloud Lane"
    },
    "{hint:state.data.deliveryAddress from onSubmit}deliveryAddress{/hint}": {
      "city": "Boulder",
      "country": "US",
      "houseNumberOrName": "242",
      "postalCode": "80302",
      "stateOrProvince": "CO",
      "street": "Silver Cloud Lane"
    },
    "shopperIP": "192.0.2.1",
    "lineItems":[
       {
          "quantity": "1",
          "amountExcludingTax": "331",
          "taxPercentage": "2100",
          "description": "Shoes",
          "id": "Item #1",
          "taxAmount": "69",
          "amountIncludingTax": "400",
          "taxCategory": "High"
       },
       {
          "quantity": "2",
          "amountExcludingTax": "248",
          "taxPercentage": "2100",
          "description": "Socks",
          "id": "Item #2",
          "taxAmount": "52",
          "amountIncludingTax": "300",
          "taxCategory": "High"
       }
    ]
}
# 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",
  :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 => {
      :street => "Silver Cloud Lane",
      :houseNumberOrName => "242",
      :city => "Boulder",
      :postalCode => "80302",
      :stateOrProvince: "CO",
      :country => "US"
  },
  :deliveryAddress => {
      :street => "Silver Cloud Lane",
      :houseNumberOrName => "242",
      :city => "Boulder",
      :postalCode => "80302",
      :stateOrProvince: "CO",
      :country => "US"
  },
  :shopperIP => "192.0.2.1",
  :lineItems => [
    {
      :quantity => "1",
      :amountExcludingTax => "331",
      :taxPercentage => "2100",
      :description => "Shoes",
      :id => "Item #1",
      :taxAmount => "69",
      :amountIncludingTax => "400",
      :taxCategory => "High"
    },
    {
      :quantity => "2",
      :amountExcludingTax => "248",
      :taxPercentage => "2100",
      :description => "Socks",
      :id => "Item #2",
      :taxAmount => "52",
      :amountIncludingTax => "300",
      :taxCategory => "High"
    }
  ]
})
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("+31612345678");
paymentsRequest.setShopperEmail("s.hopper@example.com");

paymentsRequest.setShopperIP("192.0.2.1");

Address billingAddress = new Address();
billingAddress.setStreet("Silver Cloud Lane");
billingAddress.setHouseNumberOrName("242");
billingAddress.setCity("Boulder");
billingAddress.setPostalCode("80302");
billingAddress.setStateOrProvince("CO");
billingAddress.setCountry("US");

paymentsRequest.setBillingAddress(billingAddress);

Address deliveryAddress = new Address();
billingAddress.setStreet("Silver Cloud Lane");
billingAddress.setHouseNumberOrName("242");
billingAddress.setCity("Boulder");
billingAddress.setPostalCode("80302");
billingAddress.setStateOrProvince("CO");
billingAddress.setCountry("US");

paymentsRequest.setDeliveryAddress(deliveryAddress);

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

lineItems.add(
        new LineItem()
                .quantity(1L)
                .amountExcludingTax(331L)
                .taxPercentage(2100L)
                .description("Shoes")
                .id("Item #1")
                .taxAmount(69L)
                .amountIncludingTax(400L)
                .taxCategory(LineItem.TaxCategoryEnum.HIGH)
);

lineItems.add(
        new LineItem()
                .quantity(2L)
                .amountExcludingTax(248L)
                .taxPercentage(2100L)
                .description("Socks")
                .id("Item #2")
                .taxAmount(52L)
                .amountIncludingTax(300L)
                .taxCategory(LineItem.TaxCategoryEnum.HIGH)
);

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" => "+31612345678",
  "shopperEmail" => "s.hopper@example.com",
  "billingAddress" => [
        "city" => "Boulder",
        "country" => "US",
        "houseNumberOrName" => "242",
        "postalCode" => "80302",
        "stateOrProvince" => "CO",
        "street" => "Silver Cloud Lane"
  ],
  "deliveryAddress" => [
        "city" => "Boulder",
        "country" => "US",
        "houseNumberOrName" => "242",
        "postalCode" => "80302",
        "stateOrProvince" => "CO",
        "street" => "Silver Cloud Lane"
  ],
  "shopperIP" => "192.0.2.1",
  "lineItems" => [
     [
        "quantity" => "1",
        "amountExcludingTax" => "331",
        "taxPercentage" => "2100",
        "description" => "Shoes",
        "id" => "Item #1",
        "taxAmount" => "69",
        "amountIncludingTax" => "400",
        "taxCategory" => "High"
     ],
     [
        "quantity" => "2",
        "amountExcludingTax" => "248",
        "taxPercentage" => "2100",
        "description" => "Socks",
        "id" => "Item #2",
        "taxAmount" => "52",
        "amountIncludingTax" => "300",
        "taxCategory" => "High"
     ]
  ]
];

$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": "+31612345678",
    "shopperEmail": "s.hopper@example.com",
    "billingAddress": {
        "city": "Boulder",
        "country": "US",
        "houseNumberOrName": "242",
        "postalCode": "80302",
        "stateOrProvince": "CO",
        "street": "Silver Cloud Lane",
        },
    "deliveryAddress": {
        "city": "Boulder",
        "country": "US",
        "houseNumberOrName": "242",
        "postalCode": "80302",
        "stateOrProvince": "CO",
        "street": "Silver Cloud Lane",
        },
    "shopperIP": "192.0.2.1",
    "lineItems": [{
        "quantity": "1",
        "amountExcludingTax": "331",
        "taxPercentage": "2100",
        "description": "Shoes",
        "id": "Item #1",
        "taxAmount": "69",
        "amountIncludingTax": "400",
        "taxCategory": "High",
        }, {
        "quantity": "2",
        "amountExcludingTax": "248",
        "taxPercentage": "2100",
        "description": "Socks",
        "id": "Item #2",
        "taxAmount": "52",
        "amountIncludingTax": "300",
        "taxCategory": "High",
        }
    ]
})
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,
    ShopperIP = "192.0.2.1",
    TelephoneNumber = "+31612345678",
    ShopperEmail= "s.hopper@example.com",

    LineItems = new List<LineItem>
    {
        new LineItem(AmountIncludingTax: 400, AmountExcludingTax: 331, Quantity: 1, TaxPercentage: 2100, Id: "Item #1", TaxAmount: 69, Description: "Shoes", TaxCategory: LineItem.TaxCategoryEnum.High),
        new LineItem(AmountIncludingTax: 300, AmountExcludingTax: 248, Quantity: 2, TaxPercentage: 2100, Id: "Item #2", TaxAmount: 52, Description: "Socks", TaxCategory: LineItem.TaxCategoryEnum.High)
    },
    PaymentMethod = new DefaultPaymentMethodDetails
    {
        Type = "affirm",

        BillingAddress = new Address(Country: "US")
        {
            City = "Boulder",
            HouseNumberOrName = "242",
            PostalCode = "80302",
            StateOrProvince = "CO",
            Street = "Silver Cloud Lane"
        },
        DeliveryAddress = new Address
        {
            City = "Boulder",
            HouseNumberOrName = "242",
            PostalCode = "80302",
            StateOrProvince = "CO",
            Street = "Silver Cloud Lane"
        },
    },
    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: "+31612345678",
  shopperEmail: "s.hopper@example.com",
  billingAddress: {
     street: "Silver Cloud Lane",
     houseNumberOrName: "242",
     city: "Boulder",
     postalCode: "80302",
     stateOrProvince: "CO",
     country: "US"
  },
  deliveryAddress: {
     street: "Silver Cloud Lane",
     houseNumberOrName: "242",
     city: "Boulder",
     postalCode: "80302",
     stateOrProvince: "CO",
     country: "US"
  },
  shopperIP: "192.0.2.1",
  lineItems: [
     {
        quantity: "1",
        amountExcludingTax: "331",
        taxPercentage: "2100",
        description: "Shoes",
        id: "Item 1",
        taxAmount: "69",
        amountIncludingTax: "400",
        taxCategory: "High"
     },
     {
        quantity: "2",
        amountExcludingTax: "248",
        taxPercentage: "2100",
        description: "Socks",
        id: "Item 2",
        taxAmount: "52",
        amountIncludingTax: "300",
        taxCategory: "High"
     }
  ]
}).then(res => res);

The /payments response contains:

  • resultCode: Use this to present the payment result to your shopper.
  • pspReference: Our unique reference for the payment.
  • merchantReference: Your reference from the /payments request.
/payments response
{
   "pspReference":"881567437271705K",
   "resultCode":"Authorised",
   "merchantReference":"YOUR_ORDER_NUMBER"
}

Present the payment result

Use the resultCode that you received in the /payments response to present the payment result to your shopper.
The resultCode values you can receive for 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 you want to set up automatic capture for Affirm payments, contact our Support Team.

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 /refund request:

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

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