Migrate to Netlify Today

Netlify announces the next evolution of Gatsby Cloud. Learn more

ContactSign Up
Community Plugin
View plugin on GitHub

gatsby-plugin-affirm-js

A plugin for integrating Affirm JS payment options with Gatsby.

Installation

npm install gatsby-plugin-affirm-js

# or

yarn add gatsby-plugin-affirm-js

Configuration and usage

.env.*

In the root of your Gatsby project, create 2 environment variables files (.env.development and .env.production) if you don’t have them already, then ddd this key and value.

AFFIRM_API_KEY=YOUR_AFFIRM_API_KEY

gatsby-config.js

Add the pulugin and its options to gatsby-config.js in your project.

// 1. Import your .env files
require("dotenv").config({
  path: `.env.${process.env.NODE_ENV}`,
});

module.exports = {
  plugins: [
    // 2. add the plugin
    {
      resolve: "gatsby-plugin-affirm-js",
      options: {
        // 3. pass in the API key in the options
        AFFIRM_API_KEY: `${process.env.AFFIRM_API_KEY}`,
      },
    },
  ],
};

You can now access the Affirm object in your React code using window.affirm. For example

window.affirm.checkout({});
© 2023 Gatsby, Inc.