Stripe Module Provider
In this document, you’ll learn about the Stripe Module Provider and how to configure it in the Payment Module.
Your AI agent can perform the steps in this guide. Run the following prompt in your agent from your Medusa application's directory:
Register the Stripe Module Provider#
The Stripe Module Provider is installed by default in your application. To use it, add it to the array of providers passed to the Payment Module in medusa-config.ts:
module.exports = defineConfig({
// ...
modules: [
{
resolve: "@medusajs/medusa/payment",
options: {
providers: [
{
resolve: "@medusajs/medusa/payment-stripe",
id: "stripe",
options: {
apiKey: process.env.STRIPE_API_KEY,
webhookSecret:
process.env.STRIPE_WEBHOOK_SECRET,
},
},
],
},
},
],
})
Environment Variables#
Set the STRIPE_API_KEY and STRIPE_WEBHOOK_SECRET environment variables:
- In Cloud, add the variables in your environment's Environment variables settings. Mark both variables as Sensitive, and enable the Build toggle for all variables, since
medusa-config.tsreads them during the build. - For local development, add the variables to your
.envfile:
You receive the webhook secret after you set up webhooks in Stripe for your deployed environment. You can leave STRIPE_WEBHOOK_SECRET empty in .env, since Stripe can't send webhooks to your local application.
Deploy to Cloud#
Commit the changes to medusa-config.ts and push them to the branch that your Cloud environment tracks. Cloud then creates a deployment that registers the Stripe Module Provider. Add the environment variables in Cloud before you push, so the deployment uses them.
Then, enable the provider in a region and set up webhooks for the deployed environment.
Module Options#
Option | Description | Required | Default |
|---|---|---|---|
| A string indicating the Stripe Secret API key. | Yes | - |
| A string indicating the Stripe webhook secret. This is only useful for deployed Medusa applications. | Yes | - |
| Whether to automatically capture payment after authorization. | No |
|
| 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 |
|
| A string used as the default description of a payment if none is available in | No | - |
| The number of days before an OXXO payment expires. Only applicable if you plan to use OXXO as a payment method. | No |
|
| A string indicating the ID of a Stripe Payment Method Configuration (PMC) to apply a Dashboard-managed set of payment methods to the intent. This option is only used when | No | - |
| A string indicating the Stripe API version to send requests with. For example, | No |
|
Enable Stripe Providers in a Region#
Before customers can use Stripe to complete their purchases, you must enable the Stripe payment provider(s) in the region where you want to offer this payment method.
Refer to the Merchant Guide to learn how to edit a region and enable the Stripe payment provider.
Stripe Payment Provider IDs#
When you register the Stripe Module Provider, it registers different providers, such as basic Stripe payment, Bancontact, and more.
Each provider is registered and referenced by a unique ID made up of the format pp_{identifier}_{id}, where:
{identifier}is the ID of the payment provider as defined in the Stripe Module Provider.{id}is the ID of the Stripe Module Provider as set in themedusa-config.tsfile. For example,stripe.
Assuming you set the ID of the Stripe Module Provider to stripe in medusa-config.ts, the Medusa application will register the following payment providers:
Provider Name | Provider ID |
|---|---|
Basic Stripe Payment |
|
Bancontact Payments |
|
BLIK Payments |
|
giropay Payments |
|
iDEAL Payments |
|
Przelewy24 Payments |
|
PromptPay Payments |
|
OXXO Payments (Available since Medusa v2.12.0) |
|
Setup Stripe Webhooks#
For production applications, you must set up webhooks in Stripe that inform Medusa of changes and updates to payments. Refer to Stripe's documentation on how to setup webhooks.
Webhook URL#
Medusa has a {server_url}/hooks/payment/{provider_id} API route that you can use to register webhooks in Stripe, where:
{server_url}is the URL to your deployed Medusa application in server mode. On Cloud, it's the environment's Medusa Backend URL, which you can find below the environment's name in its dashboard.{provider_id}is the ID of the provider as explained in the Stripe Payment Provider IDs section, without thepp_prefix.
The Stripe Module Provider supports the following payment types, and the webhook endpoint URL is different for each:
Stripe Payment Type | Webhook Endpoint URL |
|---|---|
Basic Stripe Payment |
|
Bancontact Payments |
|
BLIK Payments |
|
giropay Payments |
|
iDEAL Payments |
|
Przelewy24 Payments |
|
PromptPay Payments |
|
OXXO Payments (Available since Medusa v2.12.0) |
|
Webhook Events#
When you set up the webhook in Stripe, choose the following events to listen to:
payment_intent.amount_capturable_updatedpayment_intent.succeededpayment_intent.payment_failedpayment_intent.partially_funded(Since v2.8.5)
Useful Guides#
- Storefront guide: Add Stripe payment method during checkout.
- Integrate in Next.js Starter.
- Customize Stripe Integration in Next.js Starter.
- Add Saved Payment Methods with Stripe.