Commerce Modules

Payment Module

The Payment Module is the @medusajs/payment NPM package that provides payment-related features in your Medusa and Node.js applications.

How to Use Payment Module's Service#

You can use the Payment Module's main service by resolving from the Medusa container the resource Modules.PAYMENT imported from @medusajs/utils.

For example:


Features#

Add Payment Functionalities to Any Resource#

The Payment Module provides payment functionalities that allow you to process payment of any resource, such as a cart.

All payment processing starts with creating a payment collection.

Code
1const paymentCollection = await paymentModuleService.createPaymentCollections({2  region_id: "reg_123",3  currency_code: "usd",4  amount: 5000,5})

Authorize, Capture, and Refund Payment#

The Payment Module provides essential features to receive and handle payments, including authorizing, capturing, and refunding payment.

Code
1await paymentModuleService.capturePayment({2  payment_id: "pay_1",3})

Integrate Third-Party Payment Providers#

Use payment providers like Stripe to handle and process payments.

Code
1const payment = await paymentModuleService.createPaymentSession("pay_col_1", {2  provider_id: "stripe",3  amount: 1000,4  currency_code: "usd",5  data: {6    // necessary data for the payment provider7  },8})

Handle Webhook Events#

The Payment Module allows you to handle webhook events from third-party providers and process the associated payment.

Code
1await paymentModuleService.processEvent({2  provider: "stripe",3  payload: {4    // webhook payload5  },6})

Configure Payment Module#

Refer to this documentation for details on the module's options.

Was this page helpful?
Edit this page