## Overview

This page describes changes that should be made to the site for SFRA storefronts. All of the modifications are stored in the mirrored cartridge structure in `int_affirm_sfra/_cartridge` for default Storefront Reference Architecture so you can find the exact code there.

Custom modifications to your core cartridge outlined in this guide can be separated into three parts:

  • Templates

  • Controllers

  • Client-side JavaScript.




## Templates (SFRA)

### Step 1: cartridge/templates/default/common/htmlHead.isml

Include the Affirm header script tag after Google Verification tag (or after any other relevant tags and before the `htmlHead` hook). This tag will populate the configuration object and methods to be placed in the html head.








### Step 2: cartridge/templates/default/common/scripts.isml

Include `vcn.js` as static file at the bottom of the file.








### Step 3: cartridge/templates/default/components/modules.isml

Include the `affirmModule` template after the last line.








### Step 4: cartridge/templates/default/cart/cart.isml

Place promo message below where the cart total is being displayed.








### Step 5: cartridge/templates/default/product/

There is a set of recurring snippets that need to be placed in order for the Affirm promo message to be shown on the various product related pages. The list of templates that correspond to the pages include:

  • `setDetails`

  • `productDetails`

  • `bundleDetails`

  • `quickView`

  • `setQuickView` in the product folder.

Place promo messages in relevant locations where price is displayed.

#### setDetails.isml





#### bundleDetails.isml





#### productDetails.isml





#### quickView.isml & setQuickView.isml








### Step 6: product/productTile.isml

Paste the following code where the Affirm promo message should be shown on the product listing page.








### Step 7: cartridge/forms/default/billing.xml

In Storefront Reference Architecture where the credit card form is hardcoded into the templates, you need to manually modify these templates to enable the Affirm payment. Make sure email field is included in the billing form.





Important

  • Make sure the corresponding email field is included in `default/checkout/billing/billing.isml`

  • Older versions of SFRA may include an email field in `forms/default/creditCard.xml` as well as in the template `checkout/billing/creditCardForm.isml` in which case the redundant email field in `creditCard.xml` as well as `creditCardForm.isml` should be removed.




### Step 8: cartridge/templates/default/checkout

Edit the following templates to integrate Affirm payment into the checkout flow.

#### cartridge/templates/default/checkout/billing/billingSummary.isml

Include a `div` tag with vcn data.





#### cartridge/templates/default/checkout/billing/paymentOptions.isml

Add a condition attribute within the `payment-information` div for switching payment methods whether Affirm is applicable.





#### cartridge/templates/default/checkout/billing/paymentOptionsTabs.isml

Include the `affirmpaymethodli` template.





#### cartridge/templates/default/checkout/billing/paymentOptionsContent.isml

Include the payment method input template within the payment options `isloop`.





#### cartridge/templates/default/checkout/billing/paymentOptionsSummary.isml

Include Affirm payment option in the summary.





#### cartridge/templates/default/checkout/confirmation/confirmation.isml

Place affirm tracking script at the bottom of the order confirmation page before the closing </isdecoratre> tag.








## Controllers (SFRA)

CheckoutServices Controllers

Checkout endpoints in `CheckoutServices.js` were replaced to handle Affirm and credit card payments, which can be found in `int_affirm_sfra/cartridge/controllers/`.

No custom code is required in controllers apart from the `CheckoutServices.js` which is included in `int_affirm_sfra`.




## Client-side JavaScript (SFRA)

Running build scripts

Client-side JavaScript and CSS will need to be compiled before deployment. Update `package.json` at the root to make sure the value of paths property is referencing the base cartridge. In addition, please make sure the [SGMF Scripts](🔗) package is installed and run the following command after making changes:

`sgmf-scripts --compile js`

More information on the build commands can be found [here](🔗).

### Step 1: cartridge/client/default/js/checkout/billing.js

Replace the if statement inside the `updatePaymentInformation` function with the following:





Important

Make sure the `billing.js` includes force clearing security code and credit card number inside the `updateBillingAddressFormValues` function, which SFRA should include by default.






### Step 2: cartridge/client/default/js/checkout/checkout.js

Add an if statement based on checkout stage inside the `updateUrl` function.





Modify the block executed when stage is ‘placeOrder’ as shown below:








### Step 3: js/cart/cart.js

Add recalculation for the Affirm Modal Promo price on re-rendering of order totals.








### Step 4: js/search/search.js

Update `showMore` method to include `affirm.ui.refresh` as a success callback, shown below.





Make sure to rebuild client JS after making modifications.