---
title: "Spree Commerce Affirm and Spree integration"
description: "Affirm is a financial services company that offers installment loans to consumers at the point of sale. Its aim is to improve the banking industry to be more accountable and accessible to consumers. Founded in 2012, Affirm lets shoppers pay for purchases across multiple months with transparent, fairly-priced fees built into…"
url: https://spreecommerce.org/integrations/affirm-and-spree-integration/
---

[Integrations](https://spreecommerce.org/integrations.md)

[Payment](https://spreecommerce.org/integrations-cat/payment.md)

August 20, 2024

# Affirm and Spree integration

[Affirm](https://www.affirm.com/) is a financial services company that offers installment loans to consumers at the point of sale. Its aim is to improve the banking industry to be more accountable and accessible to consumers.

Founded in 2012, Affirm lets shoppers pay for purchases across multiple months with transparent, fairly-priced fees built into every payment, and increases conversion and basket size for e-tailers at less than the cost of credit cards.

The integration of Affirm with your Spree Commerce store can be done quickly and easily following the guidelines mentioned below.

## The benefits of using Affirm for your eCommerce business

### Large customer network

When you partner with Affirm, you’ll reach the company’s rapidly growing network of millions of customers.

### Zero risk to you

Affirm settles within one business day and takes on risk, from costly chargebacks to fraud.

### Flexibility to fit your business

With Affirm, you have the power to tailor your shopping experience to any customer, channel, or price point.

## How to integrate Affirm with Spree

### Before you begin

Before beginning integration, you should review:

- [The transaction flow when buying with Affirm](https://docs.affirm.com/Integrate_Affirm/Transaction_flow)
- Your current checkout process to understand how Affirm will affect operations and customer experience
- [Settlement reports to know how to reconcile transactions with the deposits into your bank account](https://docs.affirm.com/Merchant_Resources/Merchant_Daily_Operations/Settlement_Reports?origin=deflection)

### Sandbox development

You should have received an email inviting you to create an Affirm account. [Click here for information about accessing your account](https://docs.affirm.com/Merchant_Resources/Merchant_Daily_Operations/Accessing_the_Dashboard?origin=deflection).

Develop and test the Affirm integration in your development environment connected to our sandbox. To use our sandbox, retrieve your sandbox API keys at [https://sandbox.affirm.com/dashboard/#/apikeys](https://sandbox.affirm.com/dashboard/#/apikeys) for use during integration.

After development and testing, you’ll need to update your integration to use your live API keys, which you can find at [https://affirm.com/dashboard/#/apikeys](https://affirm.com/dashboard/#/apikeys).

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">1</td><td class="p-3 align-top"></td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">1</td><td class="p-3 align-top"></td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">2</td><td class="p-3 align-top"></td></tr></tbody></table>

1. Restart your Spree server

## 2\. Configure Affirm as a payment method

1. Sign in to the Spree admin page
2. Go to **Configurations** > **Payment Methods**
3. Click **New Payment Method**
4. Set **PROVIDER** to **Spree::Gateway::Affirm**
5. Enter **Affirm Monthly Payments** for **NAME**
6. Click **Create**
7. Keep **SERVER** set to **sandbox.affirm.com** for testing
8. Check the **TEST MODE** box for testing
9. Enter the **API Key** (public key) and **Secret Key** (private key) you retrieved from the Affirm sandbox merchant dashboard
10. If your checkout process automatically captures the charge, set **AUTO CAPTURE** to **Yes**
11. Set **ACTIVE** to **Yes** to enable Affirm as a payment method.
12. Click **Update**

## 3\. Add Affirm promotional messaging

Affirm promotional messaging components, monthly payment messaging and educational modals, show customers how they can use Affirm to finance their purchases. Properly placed promotional messaging helps drive increased AOV and conversion.

Adding Affirm promotional messaging is a required integration step, and you should complete it before testing your integration. [Click here for information about adding Affirm promotional messaging](https://docs.affirm.com/Integrate_Affirm/Promotional_Messaging).

## 4\. Review your order management functions

Processing orders (authorize, void, refund, and partial refund) in Spree updates the order status in the Affirm dashboard. While you can process orders in the dashboard, we strongly recommend using Spree to keep order status synced with Affirm. For more information on processing orders in Spree, refer to their documentation.

## 5\. Add the Confirmation Page function

When a customer completes their purchase, you can send their order and product information to Affirm for A/B testing, which will help you optimize your site. Send this information by adding the Confirmation Page function to your payment confirmation page. We only require **orderId**, **total**, **productId**, and **quantity** for A/B testing.

[Click here for all the Confirmation Page function parameters](https://docs.affirm.com/Integrate_Affirm/Promotional_Messaging/2018_Summer_Upgrade/Confirmation_Page_function).

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">01</td><td class="p-3 align-top">affirm.analytics.trackOrderConfirmed({</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">02</td><td class="p-3 align-top">"orderId": "T12345",</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">03</td><td class="p-3 align-top">"total": 3739</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">04</td><td class="p-3 align-top">}, [{</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">05</td><td class="p-3 align-top">"productId": "SKU-1234",</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">06</td><td class="p-3 align-top">"quantity": 1</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">07</td><td class="p-3 align-top">}, {</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">08</td><td class="p-3 align-top">"productId": "SKU-5678",</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">09</td><td class="p-3 align-top">"quantity": 1</td></tr></tbody></table>

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">10</td><td class="p-3 align-top">}]);</td></tr></tbody></table>

### Required function parameters

**Order object**

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">orderId</td><td class="p-3 align-top">string</td><td class="p-3 align-top">Your internal unique identifier representing the order. Maximum 500 characters.</td></tr><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">total</td><td class="p-3 align-top">integer</td><td class="p-3 align-top">The total amount of the transaction, including tax and shipping, stated in USD cents (e.g., $100 = 10000).</td></tr></tbody></table>

**Product object**

<table class="w-full border-collapse text-sm"><tbody><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">productId</td><td class="p-3 align-top">string</td><td class="p-3 align-top">Your internal unique identifier representing the product, such as the SKU or an internal database identifier. Maximum 500 characters.</td></tr><tr class="border-b border-(--color-border) last:border-0"><td class="p-3 align-top">quantity</td><td class="p-3 align-top">integer</td><td class="p-3 align-top">The quantity of the purchased product.</td></tr></tbody></table>

## 6\. Test your integration

After completing your integration, do a thorough testing of both your front-end and order management functions in our sandbox to ensure that everything works as expected. [Click here for our recommended test plan](https://docs.affirm.com/Integrate_Affirm/Platform_Integration/Platform_Acceptance_Testing_Guidelines?origin=deflection). However, you’ll need to tailor your testing plan to your specific systems, processes, and integration.

## 7\. Deploy to production

### Coordinate testing with Affirm

Before deploying the Affirm integration to your production site, Affirm will need to test it in your development or staging environment connected to our live environment. Contact your Client Success Manager to coordinate this test.

### Connect to the live Affirm environment

1. Retrieve your live API keys at [https://affirm.com/dashboard/#/apikeys](https://affirm.com/dashboard/#/apikeys)
2. In the Spree admin panel, go to **Configurations** > **Payment Methods**
3. Select **Affirm Monthly Payments**
4. Set **SERVER** set **api.affirm.com**
5. Enter the **API Key** (public key) and **Secret Key** (secret key) you just retrieved from the Affirm merchant dashboard
6. Uncheck the **TEST MODE** box
7. Click **Update**

### Launch to production

After you’ve connected to our live environment and we’ve tested your integration, you’re ready to deploy to your production environment and offer Affirm as a payment option to your customers.

## Example of Affirm and Spree integration

FORM is a beauty brand belonging to Walker and Company, a firm that is reinventing the way consumers of color learn about, purchase and enjoy health and beauty products. The company uses Spree for their beautiful website with some really cool features like customized Gift Cards, product reviews and featured testimonials from Twitter. The integration with Affirm allows FORM’s customers to pay with 3 interest-free payments.

Read more: [FORM Success Story](https://spreecommerce.org/success-stories/form-uses-spree-commerce-for-its-prestige-hair-care-brand-designed-for-all-hair-types.md)
