Payment Module Provider
In this guide, you’ll learn about the Payment Module Provider and how it's used.
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.
List of Payment Module Providers#
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.
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.
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 ispp_{identifier}_{id}
, where:identifier
is the value of theidentifier
property in the Payment Module Provider's service.id
is the value of theid
property of the Payment Module Provider inmedusa-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.