Community Plugin
View plugin on GitHubgatsby-plugin-affirm
Adds the (Affirm JavaScript SDK)[https://docs.affirm.com/developers/docs/afjs-reference] to your Gatsby project.
Installation
- Install gatsby-plugin-affirm.
npm install gatsby-plugin-affirm
# or
yarn add gatsby-plugin-affirm- Add the plugins to your gatsby-config.js:
gatsby-config.js
module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-affirm`,
      options: {
        // REQUIRED VALUES
        //
        // Affirm API write key for the running environment
        publicAPIKey: YOUR_AFFIRM_KEY,
        // Affirm SDK url for the running environment (i.e. https://cdn1.affirm.com/js/v2/affirm.js)
        environmentScript: AFFIRM_SDK_URL
        // OPTIONAL VALUES
        //
        // Loads the Affirm script after the document has been parsed
        experimental_shouldDeferAffirmScript: false,
        // Loads the initial script asynchronously
        isAsync: true,
      },
    },
  ],
};How to use
In the client, the Affirm SDK will now be available in the window / global context.
if (affirm && affirm.ui.ready()) {
  affirm.checkout(affirmCheckoutPayload);
  affirm.checkout.open();
}
// or
window.affirm;