Overview
The Payment Module manages all payment-related operations including payment collection creation, payment session handling, payment capture, and refunds. It provides a provider-agnostic interface that works with various payment providers like Stripe, PayPal, and others. Key Features:- Payment collection management
- Payment session handling (authorize, capture)
- Multi-provider support (Stripe, PayPal, etc.)
- Payment capture and refund processing
- Webhook handling for async payments
- Account holder management
- Payment method tracking
When to Use
Use the Payment Module when you need to:- Process customer payments during checkout
- Authorize payments before capturing
- Capture authorized payments
- Process full or partial refunds
- Handle payment provider webhooks
- Store customer payment methods
- Track payment transactions
- Support multiple payment providers
Data Models
PaymentCollection
Groups payment sessions for a cart or order.Unique payment collection identifier
Three-letter ISO currency code
Total amount to be paid
Amount currently authorized
Amount successfully captured
Amount refunded to customer
Status:
not_paid, awaiting, authorized, partially_authorized, canceledPayment sessions in this collection
Completed payments
Associated region ID
PaymentSession
Represents an active payment attempt.Unique payment session identifier
ID of the parent payment collection
Payment provider identifier (e.g., “stripe”, “paypal”)
Three-letter ISO currency code
Payment amount
Status:
pending, authorized, error, canceledWhen payment was authorized
Provider-specific data (e.g., Stripe payment intent)
Additional context data
Payment
Represents a completed payment.Unique payment identifier
ID of the payment collection
ID of the originating payment session
Payment provider identifier
Three-letter ISO currency code
Payment amount
When payment was captured
Payment captures
Payment refunds
Capture
Represents a payment capture (full or partial).Unique capture identifier
ID of the payment being captured
Captured amount
User ID who initiated the capture
Refund
Represents a payment refund.Unique refund identifier
ID of the payment being refunded
Refund amount
ID of the refund reason
Refund note or explanation
User ID who initiated the refund
AccountHolder
Stores customer payment account information.Unique account holder identifier
Account holder email
Associated customer ID
Payment provider identifier
Provider-specific account ID
Service Interface
The Payment Module service is available at@medusajs/medusa/payment.
Create Payment Collection
Create a payment collection for a cart or order.The created payment collection
Create Payment Session
Initiate a payment session with a provider.ID of the payment collection
The created payment session
Authorize Payment Session
Authorize a payment (reserve funds).ID of the payment session to authorize
Provider-specific authorization context
The authorized payment
Capture Payment
Capture an authorized payment.The created capture
Refund Payment
Refund a captured payment.The created refund
Handle Provider Webhook
Process payment provider webhooks.Webhook processing result with action type
Create Account Holder
Store customer payment account information.List Payment Providers
Retrieve available payment providers.Integration Examples
With Cart Module
Create payment collection for cart checkout.With Order Module
Track order payments.With Region Module
Region-based payment provider availability.Payment Providers
Medusa supports multiple payment providers through a provider pattern:Stripe
PayPal
Best Practices
- Authorization vs Capture: Use two-step authorization and capture for orders that require fulfillment before charging. Authorize during checkout, capture upon shipment.
-
Currency Precision: The module automatically rounds amounts to currency-specific precision using
Intl.NumberFormat. - Partial Operations: Support partial captures and refunds by specifying amounts less than the total payment amount.
- Webhook Security: Always verify webhook signatures using the raw request body. Providers include signature verification in their SDKs.
-
Error Handling: Payment sessions can fail due to insufficient funds, declined cards, etc. Handle
PaymentSessionStatus.ERRORappropriately. - Idempotency: Payment operations should be idempotent to prevent duplicate charges during retries.
Related Modules
- Cart Module - Create payment collections for carts
- Order Module - Link payments to orders
- Region Module - Configure region payment providers
- Customer Module - Store customer payment methods