Learning Resources

Stripe Module Provider

In this document, you’ll learn about the Stripe Module Provider and how to install and use it in the Payment Module.

Features#

Stripe is a battle-tested and unified platform for transaction handling. Stripe supplies you with the technical components needed to handle transactions safely and all the analytical features necessary to gain insight into your sales.

These features are also available in a safe test environment, allowing for a concern-free development process.


Install the Stripe Module Provider#

To install the Stripe Module Provider, run the following command in the directory of your Medusa application:

NoteMake sure that the version added in package.json is preview to avoid errors with installation and updates in the future.

Next, add the module to the array of providers passed to the Payment Module:

medusa-config.js
1const { Modules } = require("@medusajs/utils")2
3// ...4
5module.exports = defineConfig({6  // ...7  modules: {8    [Modules.PAYMENT]: {9      resolve: "@medusajs/payment",10      options: {11        providers: [12          {13            resolve: "@medusajs/payment-stripe",14            id: "stripe",15            options: {16              apiKey: process.env.STRIPE_API_KEY,17            },18          },19        ],20      },21    },22  },23})

Environment Variables#

Make sure to add the necessary environment variables for the above options in .env:

Terminal
STRIPE_API_KEY=<YOUR_STRIPE_API_KEY>

Module Options#

OptionDescriptionRequiredDefault

apiKey

A string indicating the Stripe Secret API key.

Yes

webhookSecret

A string indicating the Stripe webhook secret. This is only useful for deployed Medusa applications.

Yes

capture

Whether to automatically capture payment after authorization.

No

false

automatic_payment_methods

A boolean value indicating whether to enable Stripe's automatic payment methods. This is useful if you integrate services like Apple pay or Google pay.

No

false

payment_description

A string used as the default description of a payment if none is available in cart.context.payment_description.

No

-

Use Provider#

To use the Stripe provider, create a payment session for the provider:

Code
1const paymentSession =2  await paymentModuleService.createPaymentSession(3    "pay_col_123",4    {5      provider_id: "stripe-usd",6      amount: 5000,7      currency_code: "usd",8      data: {9        // any necessary data10        // to pass to stripe11      },12    }13  )
Was this page helpful?
Edit this page