Skip to main content
Skip to main content

Stripe Provider Module

In this document, you’ll learn about the Stripe provider module 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 Provider Module

Prerequisites
  • Stripe account.
  • Stripe API Key
  • For deployed Medusa applications, a Stripe webhook secret. When creating the Webhook, set the endpoint URL to {medusa_url}/hooks/payment/stripe, where {medusa_url} with the URL to your deployed Medusa application.

To install the Stripe provider module, run the following command in the directory of your Medusa application:

npm install @medusajs/payment-stripe

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

medusa-config.js
const modules = {
// ...
payment: {
resolve: "@medusajs/payment",
options: {
providers: [
{
resolve: "@medusajs/payment-stripe",
options: {
credentials: {
usd: {
apiKey: process.env.STRIPE_USD_API_KEY,
},
},
},
},
],
},
},
}

Module Options

OptionDescriptionRequiredDefault

credentials

An object where each entry is a stripe provider installation. The object’s keys are the name suffix of the provider, where the provider name will be formatted as stripe-{key}. For example, stripe-usd.

Each value is an object that accepts the following properties:

  • apiKey: A string indicating the Stripe API key.
  • webhookSecret: (optional in development) 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

-

Environment Variables

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

STRIPE_USD_API_KEY=<YOUR_STRIPE_API_KEY>

Use Provider

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

const paymentSession =
await paymentModuleService.createPaymentSession(
"pay_col_123",
{
provider_id: "stripe-usd",
amount: 5000,
currency_code: "usd",
data: {
// any necessary data
// to pass to stripe
},
}
)
Was this section helpful?