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:
- Provide details about the items being purchased when making a payment request.
- Capture 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. |
Setup steps | Before you begin, 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 |
Set to affirm. | |
shopperName.firstName |
Shopper's first name. | |
shopperName.lastName |
Shopper's last name. | |
telephoneNumber |
Shopper's telephone number. | |
shopperEmail |
Shopper's email address. | |
billingAddress |
The address where to send the invoice. | |
deliveryAddress |
The address where the purchased goods should be delivered. If blank or missing, billingAddress is used by default. |
|
lineItems |
Price and product information about the purchased items. This is optional, but we recommend to include this data to improve approval rates. |
In the /payments response, note the `action` object. This contains the information needed to redirect the shopper.
<div data-component-wrapper="code-sample">
<code-sample
:title="'/payments response'"
:id="''"
:code-data="[{"language":"json","tabTitle":"","content":"{\n \"resultCode\":\"RedirectShopper\",\n \"action\":{\n \"paymentMethodType\":\"affirm\",\n \"method\":\"GET\",\n \"url\":\"https:\/\/checkoutshopper-test.adyen.com\/checkoutshopper\/checkoutPaymentRedirect?redirectData=...\",\n \"type\":\"redirect\"\n }\n}"}]"
:enable-copy-link-to-code-block="true"
:code-sample-card-size="'fullsize'"
></code-sample>
Handle the redirect
-
To complete the payment, redirect the shopper to the
action.url
returned in the /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 for iOS or Chrome Custom Tabs for Android, instead of WebView objects. Also refer to the security best practices 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.
-
-
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-decodedredirectResult
returned when the shopper was redirected back to your site.
-
In the response note the following:
resultCode
: use this to present the result to your shopper.pspReference
: our unique identifier for the transaction.
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 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. |
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 within 28 days, 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 do not manually 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 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 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
: TheacquirerReference
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 theacquirerReference
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.
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.