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.

Looking for no-code docs?Refer to the Medusa Admin User Guide to learn how to manage order payments using the dashboard.

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.

NoteLearn more about why modules are isolated in this documentation.

Payment Features#


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:

src/workflows/create-payment-collection.ts
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      currency_code: "usd",16      amount: 5000,17    })18
19    return new StepResponse({ paymentCollection }, paymentCollection.id)20  },21  async (paymentCollectionId, { container }) => {22    if (!paymentCollectionId) {23      return24    }25    const paymentModuleService = container.resolve(Modules.PAYMENT)26
27    await paymentModuleService.deletePaymentCollections([paymentCollectionId])28  }29)30
31export const createPaymentCollectionWorkflow = createWorkflow(32  "create-payment-collection",33  () => {34    const { paymentCollection } = createPaymentCollectionStep()35
36    return new WorkflowResponse({37      paymentCollection,38    })39  }40)

You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:

src/api/workflow/route.ts
5import { createPaymentCollectionWorkflow } from "../../workflows/create-payment-collection"6
7export async function GET(8  req: MedusaRequest,9  res: MedusaResponse10) {11  const { result } = await createPaymentCollectionWorkflow(req.scope)12    .run()13
14  res.send(result)15}

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.

Stripe

Server Guides#

Learn how to use the Payment Module in your customizations on the Medusa application server.

Accept Payment Flow
Create Payment Provider

Storefront Guides#

Learn how to integrate the Payment Module's features into your storefront.

Customize the Stripe Integration in the Next.js Starter
Checkout Step 5: Complete Cart
Checkout Step 4: Choose Payment Provider
Payment with Stripe in React Storefront

References#

Find references for tools and resources related to the Payment Module, such as data models, methods, and more. These are useful for your customizations.

Workflows
JS SDK
Events Reference
Main Service Reference
Data Models Reference
Was this page helpful?
Edited Feb 26·Edit this page
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