Overview
This reference documents every object and method available in Affirm's browser-side JavaScript library, Affirm.js.
Including and initializing Affirm.js
Include the affirm.js
script to the head of your global page template.
In order to create an instance of Affirm, you will need to pass your public API key and the environment you are pointing too. The Affirm object is your entry point to the rest of the Affirm.js SDK.
Your Affirm public API key is required when calling this function, as it identifies your website to Affirm.
When you’re ready to accept live transactions, replace the sandbox key with your live key in production as well as the environment URL.
Learn more about how API keys work in sandbox mode and production mode.
<script>
const _affirm_config = {
public_api_key: "YOUR_PUBLIC_API_KEY", /* replace with public api key */
script: "https://cdn1-sandbox.affirm.com/js/v2/affirm.js",
locale: "en_US",
country_code: "USA",
};
(function(m,g,n,d,a,e,h,c){var b=m[n]||{},k=document.createElement(e),p=document.getElementsByTagName(e)[0],l=function(a,b,c){return function(){a[b]._.push([c,arguments])}};b[d]=l(b,d,"set");var f=b[d];b[a]={};b[a]._=[];f._=[];b._=[];b[a][h]=l(b,a,h);b[c]=function(){b._.push([h,arguments])};a=0;for(c="set add save post open empty reset on off trigger ready setProduct".split(" ");a<c.length;a++)f[c[a]]=l(b,d,c[a]);a=0;for(c=["get","token","url","items"];a<c.length;a++)f[c[a]]=function(){};k.async=
!0;k.src=g[e];p.parentNode.insertBefore(k,p);delete g[e];f(g);m[n]=b})(window,_affirm_config,"affirm","checkout","ui","script","ready","jsReady");
</script>
Method arguments
public_api_key required | string | Your public API key. |
script required | string | Sandbox: https://cdn1-sandbox.affirm.com/js/v2/affirm.js Production: https://cdn1.affirm.com/js/v2/affirm.js |
Ready
A callback can be passed to affirm.ui.ready()
that will be called when affirm.js
is finished loading.
affirm.ui.ready(function() {
console.log('Affirm JS ready!');
});
Updated 7 days ago