This guide describes how to integrate Affirm into the AmeriCommerce eCommerce platform so that you can provide Affirm as a payment option to your customers. After integrating Affirm, your AmeriCommerce site will:

  • Offer Affirm as payment option on the checkout page
  • Process Affirm charges in your order management system
  • Display Affirm promotional messaging

Before you begin 

Before beginning integration, you should review:

Sandbox development

You should have received an email inviting you to create an Affirm account. Click here for information about accessing your account.

Develop and test the Affirm integration in your development environment connected to our sandbox. To use our sandbox, retrieve your sandbox API keys at 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

Install and configure Affirm

Visit AmeriCommerce for instructions on how to install and configure Affirm. Check Use Sandbox for development and testing. Return here after configuring Affirm to complete the integration.

Add Affirm promotional messaging

Affirm promotional messaging configuration is now available in the AmeriCommerce online store Apps & Addons dashboard for Affirm (Tools > Apps & Addons).  To enable Affirm messaging, you can check the box next to Shopping Cart & Product Page - Enable Promotional Messaging settings. Visit AmeriCommerce for instructions on how to install and configure Affirm

If you have modified your product or cart page templates in the past, you may not be able to see Affirm messaging after enabling the above configurations. Your product and cart page templates may not have Affirm related merge codes and you would then need to use the following instructions to add custom code to get Affirm promotional messaging: 

Add Affirm.js to the global page template

1. Go to Themes > Edit Theme > Head Tags
2. Add the code below:

<!-- Affirm -->
 _affirm_config = {
   public_api_key:  "YOUR_PUBLIC_KEY",
   script:          ""
 (function(l,g,m,e,a,f,b){var d,c=l[m]||{},h=document.createElement(f),n=document.getElementsByTagName(f)[0],k=function(a,b,c){return function(){a[b]._.push([c,arguments])}};c[e]=k(c,e,"set");d=c[e];c[a]={};c[a]._=[];d._=[];c[a][b]=k(c,a,b);a=0;for(b="set add save post open empty reset on off trigger ready setProduct".split(" ");a<b.length;a++)d[b[a]]=k(c,e,b[a]);a=0;for(b=["get","token","url","items"];a<b.length;a++)d[b[a]]=function(){};h.async=!0;h.src=g[f];n.parentNode.insertBefore(h,n);delete g[f];d(g);l[m]=c})(window,_affirm_config,"affirm","checkout","ui","script","ready");
// Use your live public API Key and script to point to Affirm production environment.

Be sure to use your public API key from the sandbox merchant dashboard for public_api_key.

Add an HTML element everywhere you want to display an Affirm promotional messaging component. The element attributes (see below) determine which component displays. We generally recommend adding promotional messaging to your category, product, cart, and payment pages.

In each HTML element, include the new data-page-type attribute corresponding to the page where that promotional messaging component is placed. The data-page-type attribute allows you to customize messaging in the future without development work. By default, promotional messaging on product pages have prequalification enabled, but you can work with your Client Success Manager to change this and configure additional customizations.

Add promotional messaging code

You'll need to edit the HTML on your pages by signing in to the AmeriCommerce admin page and navigating to Themes > Edit > Product Details > HTML Editor. When configuring your promotional messaging, you'll need to use AmeriCommerce's merge codes for the data-amount values. Possible merge codes include:

  • ##RAWPRICE## (product page)
  • ##CARTRAWTOTAL## (cart page)
  • $$PRICE$$

Add promotional messaging to product and cart pages:

     var refreshable = document.getElementById('as-low-as-refreshable');
     if (refreshable){
         var amount = "##RAWPRICE##".replace(/[^0-9]+/g,"");
         refreshable.setAttribute('data-amount', amount);
 <p class="affirm-as-low-as" data-amount="##RAWPRICE##" id="as-low-as-refreshable" data-page-type="product"> </p>

Here's a sample code for a variant product page:

  //Calculate price to update data-amount value
  function updateAffirmDataAmount (){
      var rawProductPrice = $('.ProductDetailsPricing .ProductDetailsPrice').html();
      rawProductPrice = Math.round(100 * parseFloat(rawProductPrice.replace(/[^0-9\.-]+/g, '')));      
      var refreshable = document.getElementById('as-low-as-refreshable');
      refreshable.setAttribute('data-amount', rawProductPrice);
 //Check if the product price changed
  $(document).on("DOMSubtreeModified", ".ProductDetailsPricing .ProductDetailsPrice", function () {
      updateAffirmDataAmount ();
<p class="affirm-as-low-as" data-amount="" id="as-low-as-refreshable" data-page-type="product"> </p>

Click here for more information on adding Affirm promotional messaging to your site

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. Click here for all the Confirmation Page function parameters.

To add the function, go to Settings > Orders > General and paste the script below in the Place Order Script box.

    var orderTotal = "##ORDERTOTAL##".replace(/[^0-9]+/g,""){
       "orderId": "##ORDERID##",
       "total": orderTotal,

Function parameters 

Order object

orderIdstring Your internal unique identifier representing the order. Maximum 500 characters.
totalinteger The total amount of the transaction, including tax and shipping, stated in USD cents (e.g., $100 = 10000).

Review your order management functions

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

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. However, you'll need to tailor your testing plan to your specific systems, processes, and integration.

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 Integration Consultant or [email protected] to coordinate this test.

Connect to the live Affirm environment 

Refer back to the AmeriCommerce instructions for connecting to the live Affirm environment.

1. Retrieve your live API keys at
2. Enter the Public API Key and Private API Key you just retrieved from the Affirm merchant dashboard
3. Uncheck the Use Sandbox box

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.

Updated 8 months ago


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.