The Commission module owns four data models:
CommissionRate (comrate), CommissionRule (comrule), CommissionRateValue (comval), and CommissionLine (comline). Resolve its service with MercurModules.COMMISSION from @mercurjs/types.Key features
The Commission module covers configuration, resolution, and the per-order record:- Percentage or fixed rates: a percent of the line subtotal, or a flat amount per line
- Per-currency amounts: a fixed rate holds one amount per currency and falls back to its
value - Five scoping dimensions: rules match on
product,product_type,product_collection,product_category, andseller - Most specific wins: the matching rate scoped on the most dimensions wins, and ties go to the oldest rate
- Global commission: a seeded
is_defaultrate that can’t be deleted and is the only rate that commissions shipping - Lines that follow the order: lines are written at checkout and recomputed on order edits, returns, claims, and exchanges
- Exact arithmetic: amounts are computed with Medusa’s
MathBNand stored as big numbers - Pluggable calculation: swap the built-in
systemprovider for your ownICommissionProvider
How it works
Commission runs as part of checkout and again whenever the order changes:completeCartWithSplitOrdersWorkflowsplits the cart into one order per seller.- It runs
refreshOrderCommissionLinesWorkflowfor the new orders as a nested step. - The workflow builds one calculation context per order and passes them to the active provider in one batch.
- The
systemprovider loads the enabled rates once and picks the winning rate for each item. - The module replaces the order’s commission lines with the new set.
- When a payout is created, Mercur subtracts the sum of the order’s commission lines from the order total.
Get started
Learn how rates, rules, and commission lines fit together.Rules & rates
Percentage and fixed rates, per-currency amounts, and the global commission.
Rule matching
How Mercur picks one rate for each line, and how shipping is handled.
Order commission lines
What a commission line records and when it’s recomputed.
Examples
Build against commission in your own server code.Create a rate
Create percentage and fixed rates with
createCommissionRatesWorkflow.Batch-update rules
Add, change, and remove a rate’s rules in one workflow run.
Refresh order lines
Recompute commission for orders and extend the calculation context.
Resources
The data models, links, workflows, service methods, and events behind commission.Data models
Every field of the four commission models.
Links
How commission records point at the catalog, sellers, and orders.
Workflows
Rate, rule, and order-line workflows with their inputs and hooks.
Service
Generated and custom service methods, and commission providers.
Events
The order events that trigger a recompute.