Split Order Payment Module
In this section of the documentation, you will find resources to learn more about the Split Order Payment Module and how to use it in your application. Mercur has payment splitting features available out-of-the-box through the Split Order Payment Module. A module is a standalone package that provides features for a single domain. Each of Mercur’s marketplace features are placed in custom modules, such as this Split Order Payment Module. Learn more about why modules are isolated in this documentation.Split Order Payment Features
- Payment Tracking per Seller: Track payment amounts (authorized, captured, refunded) separately for each seller’s portion of a multi-vendor order.
- Payment Collection Association: Link split payments to the main payment collection for the entire cart.
- Automatic Status Updates: Automatically update split payment status when the main payment is captured.
- Refund Management: Handle partial refunds specific to each seller’s order.
- Financial Reconciliation: Maintain accurate payment records for commission calculation and payout processing.
How to Use the Split Order 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. Mercur provides pre-built workflows for split payment operations in the@mercurjs/b2c-core package.
For example, the markSplitOrderPaymentsAsCapturedWorkflow:
src/workflows/split-order-payment/mark-split-order-payments-as-captured.ts
Subscriber
src/subscribers/split-payment-payment-captured.ts
Concepts
In this document, you’ll learn about the main concepts related to split order payments in Mercur.Split Order Payment
A split order payment tracks the payment amounts specific to an individual seller’s order within a multi-vendor purchase. It is represented by the SplitOrderPayment data model. A split order payment holds information about:- Payment status (authorized, captured, refunded)
- Authorized amount for this seller’s portion
- Captured amount (funds actually received)
- Refunded amount (funds returned to customer)
- Currency code
- Associated payment collection ID
Why Split Order Payments?
In a multi-vendor marketplace, when a customer checks out with products from multiple sellers: Payment Flow:- Customer authorizes payment for the total cart amount ($100)
- Cart splits into 3 orders: Seller A (35), Seller C ($25)
- Three
SplitOrderPaymentrecords are created, tracking each seller’s portion - Payment is captured ($100 total)
- Each split payment updates to “captured” with their respective amounts
- Commission is calculated per split payment
- Payouts are processed to each seller (minus commission)
- No way to track which seller’s portion was captured/refunded
- Commission calculation would be difficult
- Payout processing would require complex lookups
- Refund handling would be ambiguous
- Clear payment tracking per seller
- Simple commission calculation
- Straightforward payout processing
- Accurate refund attribution
Payment Lifecycle
1. Authorization
When a cart is completed:- Main payment collection is created for the total amount
- Individual orders are created per seller
SplitOrderPaymentrecords are created with statusauthorizedauthorized_amountis set to each seller’s order total
2. Capture
When payment is captured (either immediately or later):- Main payment’s
payment.capturedevent is emitted - Subscriber triggers
markSplitOrderPaymentsAsCapturedWorkflow - All split payments for the payment collection are updated:
status→capturedcaptured_amount→authorized_amount
3. Refund
When a refund is processed:- Refund workflow identifies the specific seller’s order
SplitOrderPaymentis updated:refunded_amountis incremented- If fully refunded and
refunded_amountequalscaptured_amount
Integration with Payment Module
Split order payments are tightly integrated with Medusa’s Payment Module:- PaymentCollection: The parent payment collection for the entire cart
- Link: One-to-one link between Order and SplitOrderPayment
- Event-Driven: Listens to
PaymentEvents.CAPTUREDto update split payment status - Automatic Sync: Split payments stay synchronized with main payment lifecycle
- Payment Module: Handles actual payment processing with providers
- Split Order Payment Module: Tracks seller-specific payment amounts
- Payout Module: Uses split payment data for seller payouts
Status Values
Split order payments use string-based status tracking:authorized: Payment has been authorized but not yet capturedcaptured: Payment has been captured and funds are securedrefunded: Payment has been fully refunded to the customerpartially_refunded: Some but not all funds have been refunded
Use Cases
1. Multi-Vendor Checkout Customer purchases from 3 sellers; system creates 3 split payments tracking each seller’s payment portion. 2. Delayed Capture Marketplace authorizes payment on checkout but captures later (e.g., after shipping). Split payments track both authorization and capture timing. 3. Partial Refunds Customer returns items from one seller; that seller’s split payment tracks the refunded amount separately. 4. Commission Calculation Commission module usescaptured_amount from split payments to calculate marketplace fees per seller.
5. Payout Processing
Payout job queries orders with captured split payments to determine which sellers should receive funds.
6. Financial Reporting
Generate reports on authorized vs captured amounts per seller for cash flow analysis.