Pesquisar

Are you looking for test card numbers?

Would you like to contact support?

Atenção, esta página não se encontra disponível em Português
Payment-method icon

Affirm Drop-in integration

Add Affirm to an existing Drop-in integration.

Our Web Drop-in renders Affirm in your payment form, and collects the required payment information from the shopper.

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

This page explains how to add Affirm to your existing Web Drop-in integration. The Web Drop-in integration works the same way for all payment methods. If you haven't done this integration yet, refer to our Drop-in integration guide.

Before starting your Affirm integration:

  1. Make sure that you have set up your back end implementation, and added Drop-in to your payments form.
  2. Add Affirm in your test Customer Area.

Show Affirm in your payment form

Drop-in uses countryCode and amount.currency from the /paymentMethods request to show the available payment methods to your shopper.

To show Affirm in your payment form, you need to specify in your /paymentMethods request the following combination of countryCode and amount.currency:

Country countryCode amount.currency
United States US USD

Optional Drop-in configuration

When creating an instance of Drop-in, you can optionally configure the visibility of the shopper input fields for Affirm:

  • personalDetails: Shopper name, phone number, and email address.
  • billingAddress: The address where to send the invoice.
  • deliveryAddress: The address where the purchased goods should be delivered.

If you remove these fields from your payment form, you need to collect and provide this information in your /payments request. For information on the required fields, refer to Make a payment.

const dropin = checkout
    .create('dropin', {
        paymentMethodsConfiguration: {
            affirm: { // Optional configuration for Affirm
                visibility: {
                    personalDetails: "hidden", // These fields will not appear on the payment form.
                    billingAddress: "readOnly", // These fields will appear on the payment form,
                                              //but the shopper can't edit them.
                    deliveryAddress: "editable" //These fields will appear on the payment form,
                                              // and the shopper can edit them.
                                              //This is the default behaviour.
                }
            }
        }
    })
    .mount('#dropin');

Make a payment

When the shopper selects to pay, Drop-in calls the onSubmit event, which contains a state.data.

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

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 phone 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",
    "{hint:state.data.billingAddress from onSubmit}billingAddress{/hint}": {
      "city": "San Francisco",
      "country": "US",
      "houseNumberOrName": "274",
      "postalCode": "94107",
      "stateOrProvince": "CA",
      "street": "Brannan St."
    },
    "{hint:state.data.deliveryAddress from onSubmit}deliveryAddress{/hint}": {
      "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"
   }
}
  1. Pass the action object to your front end.

Handle the redirect result

Handling the redirect works the same way for all redirect payment methods.

Drop-in uses dropin.handleAction(action) to redirect the shopper to complete the payment. After the shopper is redirected back to your website:

  1. URL-decode the redirectResult that was appended to your returnUrl when the shopper was redirected back to your site, and pass it to your back end.
  2. Check the payment result by making a POST /payments/details request, specifying:
    • details: Object that contains the URL-decoded values of the parameters that were appended to the returnUrl 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=="
      }
    }'
    The /payments/details response contains:
    • resultCode: Use this to present the payment 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/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 successful. Inform the shopper that the payment was successful.
Cancelled The shopper cancelled the payment. Ask the shopper whether they want to continue with the order, or ask them to select a different payment method.
Pending or
Received
The shopper has completed the payment but the final result is not yet known. It may take minutes or hours to confirm this. Inform the shopper that you've received their order, and are waiting for the payment to be completed.
To know the final result of the payment, wait for the AUTHORISATION notification.
Refused The payment was refused by Affirm. Ask the shopper to try the payment again using a different payment method.

If the shopper failed to return to your website or app, wait for notification webhooks to know the outcome of the payment:

eventCode success field Description Action to take
AUTHORISATION false The transaction failed. Cancel the order and inform the shopper that the payment failed.
AUTHORISATION true The shopper successfully completed the payment. Inform the shopper that the payment has been successful and proceed with the order.

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