Payment Module Provider

In this guide, you’ll learn about the Payment Module Provider and how it's used.

Looking for no-code docs? Refer to this Medusa Admin User Guide to learn how to manage the payment providers available in a region using the dashboard.

What is a Payment Module Provider?#

The Payment Module Provider handles payment processing in the Medusa application. It integrates third-party payment services, such as Stripe.

To authorize a payment amount with a payment provider, a payment session is created and associated with that payment provider. The payment provider is then used to handle the authorization.

After the payment session is authorized, the payment provider is associated with the resulting payment and handles its payment processing, such as to capture or refund payment.

Diagram showcasing the communication between Medusa, the Payment Module Provider, and the third-party payment provider.

List of Payment Module Providers#

Stripe

Default Payment Provider#

The Payment Module provides a system payment provider that acts as a placeholder payment provider.

It doesn’t handle payment processing and delegates that to the merchant. It acts similarly to a cash-on-delivery (COD) payment method.

Tip: The identifier of the system payment provider is pp_system.

How to Create a Custom Payment Provider?#

A payment provider is a module whose main service extends the AbstractPaymentProvider imported from @medusajs/framework/utils.

The module can have multiple payment provider services, where each is registered as a separate payment provider.

Refer to this guide on how to create a payment provider for the Payment Module.

After you create a payment provider, you can enable it as a payment provider in a region using the Medusa Admin dashboard.


How are Payment Providers Registered?#

Configure Payment Module's Providers#

The Payment Module accepts a providers option that allows you to configure the providers registered in your application.

Learn more about this option in the Module Options guide.

Registration on Application Start#

When the Medusa application starts, it registers the Payment Module Providers defined in the providers option of the Payment Module.

For each Payment Module Provider, the Medusa application finds all payment provider services defined in them to register.

PaymentProvider Data Model#

A registered payment provider is represented by the PaymentProvider data model in the Medusa application.

Diagram showcasing the PaymentProvider data model

This data model is used to reference a service in the Payment Module Provider and determine whether it's installed in the application.

The PaymentProvider data model has the following properties:

  • id: The unique identifier of the Payment Module Provider. The ID's format is pp_{identifier}_{id}, where:
    • identifier is the value of the identifier property in the Payment Module Provider's service.
    • id is the value of the id property of the Payment Module Provider in medusa-config.ts.
  • is_enabled: A boolean indicating whether the payment provider is enabled.

How to Remove a Payment Provider?#

If you remove a payment provider from the providers option, the Medusa application will not remove the associated PaymentProvider data model record.

Instead, the Medusa application will set the is_enabled property of the PaymentProvider's record to false. This allows you to re-enable the payment provider later if needed by adding it back to the providers option.

Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break