- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Payment Module
In this section of the documentation, you will find resources to learn more about the Payment Module and how to use it in your application.
Medusa has payment related features available out-of-the-box through the Payment Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Payment Module.
Payment Features#
- Authorize, Capture, and Refund Payments: Authorize, capture, and refund payments for a single resource.
- Payment Collection Management: Store and manage all payments of a single resources, such as a cart, in payment collections.
- Integrate Third-Party Payment Providers: Use payment providers like Stripe to handle and process payments, or integrate custom payment providers.
- Handle Webhook Events: Handle webhook events from third-party providers and process the associated payment.
How to Use the Payment Module#
In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows
package.
For example:
1import { 2 createWorkflow, 3 WorkflowResponse,4 createStep,5 StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8 9const createPaymentCollectionStep = createStep(10 "create-payment-collection",11 async ({}, { container }) => {12 const paymentModuleService = container.resolve(Modules.PAYMENT)13 14 const paymentCollection = await paymentModuleService.createPaymentCollections({15 region_id: "reg_123",16 currency_code: "usd",17 amount: 5000,18 })19 20 return new StepResponse({ paymentCollection }, paymentCollection.id)21 },22 async (paymentCollectionId, { container }) => {23 if (!paymentCollectionId) {24 return25 }26 const paymentModuleService = container.resolve(Modules.PAYMENT)27 28 await paymentModuleService.deletePaymentCollections([paymentCollectionId])29 }30)31 32export const createPaymentCollectionWorkflow = createWorkflow(33 "create-payment-collection",34 () => {35 const { paymentCollection } = createPaymentCollectionStep()36 37 return new WorkflowResponse({38 paymentCollection,39 })40 }41)
You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
Learn more about workflows in this documentation.
Configure Payment Module#
The Payment Module accepts options for further configurations. Refer to this documentation for details on the module's options.
Providers#
Medusa provides the following payment providers out-of-the-box. You can use them to process payments for orders, returns, and other resources.