Skip to main content

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.
string
required
Unique payment collection identifier
string
required
Three-letter ISO currency code
BigNumber
required
Total amount to be paid
BigNumber
Amount currently authorized
BigNumber
Amount successfully captured
BigNumber
Amount refunded to customer
PaymentCollectionStatus
required
Status: not_paid, awaiting, authorized, partially_authorized, canceled
PaymentSession[]
Payment sessions in this collection
Payment[]
Completed payments
string
Associated region ID

PaymentSession

Represents an active payment attempt.
string
required
Unique payment session identifier
string
required
ID of the parent payment collection
string
required
Payment provider identifier (e.g., “stripe”, “paypal”)
string
required
Three-letter ISO currency code
BigNumber
required
Payment amount
PaymentSessionStatus
required
Status: pending, authorized, error, canceled
DateTime
When payment was authorized
object
Provider-specific data (e.g., Stripe payment intent)
object
Additional context data

Payment

Represents a completed payment.
string
required
Unique payment identifier
string
required
ID of the payment collection
string
ID of the originating payment session
string
required
Payment provider identifier
string
required
Three-letter ISO currency code
BigNumber
required
Payment amount
DateTime
When payment was captured
Capture[]
Payment captures
Refund[]
Payment refunds

Capture

Represents a payment capture (full or partial).
string
required
Unique capture identifier
string
required
ID of the payment being captured
BigNumber
required
Captured amount
string
User ID who initiated the capture

Refund

Represents a payment refund.
string
required
Unique refund identifier
string
required
ID of the payment being refunded
BigNumber
required
Refund amount
string
ID of the refund reason
string
Refund note or explanation
string
User ID who initiated the refund

AccountHolder

Stores customer payment account information.
string
required
Unique account holder identifier
string
Account holder email
string
Associated customer ID
string
required
Payment provider identifier
string
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.
CreatePaymentCollectionDTO
required
Payment collection data
string
required
Three-letter ISO currency code
number
required
Total amount to collect
string
ID of the associated region
PaymentCollectionDTO
The created payment collection

Create Payment Session

Initiate a payment session with a provider.
string
required
ID of the payment collection
CreatePaymentSessionDTO
required
Payment session data
string
required
Payment provider ID (e.g., “stripe”, “paypal”)
string
required
Currency code
number
required
Payment amount
object
Provider-specific initialization data
object
Additional context (customer info, etc.)
PaymentSessionDTO
The created payment session

Authorize Payment Session

Authorize a payment (reserve funds).
string
required
ID of the payment session to authorize
object
Provider-specific authorization context
PaymentDTO
The authorized payment

Capture Payment

Capture an authorized payment.
CreateCaptureDTO
required
Capture data
string
required
ID of the payment to capture
number
Amount to capture (defaults to full payment amount)
string
User ID initiating the capture
CaptureDTO
The created capture

Refund Payment

Refund a captured payment.
CreateRefundDTO
required
Refund data
string
required
ID of the payment to refund
number
Amount to refund (defaults to full payment amount)
string
ID of the refund reason
string
Refund note or explanation
string
User ID initiating the refund
RefundDTO
The created refund

Handle Provider Webhook

Process payment provider webhooks.
ProviderWebhookPayload
required
Webhook data
string
required
Payment provider ID
object
required
Webhook payload from provider
string | Buffer
Raw webhook body (for signature verification)
object
Webhook request headers
WebhookActionResult
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

  1. Authorization vs Capture: Use two-step authorization and capture for orders that require fulfillment before charging. Authorize during checkout, capture upon shipment.
  2. Currency Precision: The module automatically rounds amounts to currency-specific precision using Intl.NumberFormat.
  3. Partial Operations: Support partial captures and refunds by specifying amounts less than the total payment amount.
  4. Webhook Security: Always verify webhook signatures using the raw request body. Providers include signature verification in their SDKs.
  5. Error Handling: Payment sessions can fail due to insufficient funds, declined cards, etc. Handle PaymentSessionStatus.ERROR appropriately.
  6. Idempotency: Payment operations should be idempotent to prevent duplicate charges during retries.