Skip to main content
Commissions are how the marketplace earns revenue. Rather than storing a single commission percentage, Mercur uses a rule-based system where commission rates are matched to order line items based on configurable conditions, with a global default as the fallback.

Commission rates

A CommissionRate defines how much commission the marketplace takes and when it applies.
FieldDescription
nameHuman-readable name (e.g. “Electronics Commission”)
codeUnique system identifier
typefixed (flat amount) or percentage
valueThe percentage, or the flat amount used when no per-currency value matches
valuesPer-currency amounts for fixed rates (currency_code + amount)
include_taxInclude tax in the base amount for calculation
include_shippingWhether shipping methods are also commissioned (global rate only)
is_defaultMarks the global commission — the fallback applied when no scoped rate matches
is_enabledDisabled rates are skipped entirely
percentage rates use the scalar value. fixed rates read the per-currency values list and fall back to value when the order’s currency has no entry.

Commission rules

Rules determine when a rate applies. Each rule has a reference (the dimension) and a reference_id (the value to match):
ReferenceMatches items whose product…
productis that specific product
product_typehas that product type
product_collectionbelongs to that collection
product_categorybelongs to that category
selleris sold by that seller
A rate with no rules matches everything — that’s what makes the default rate a catch-all.

The matching algorithm

For each line item:
  1. Group the rate’s rules by dimension (reference).
  2. A rate matches when every dimension group has at least one matching rule — AND across dimensions, OR within a dimension. Example: a rate with rules seller: A and product_category: electronics matches only electronics sold by seller A; a rate with two product_category rules matches either category.
  3. Among all matching rates, the most specific wins — the rate scoping on the largest number of distinct dimensions.
  4. Ties break deterministically to the oldest rate.
Example configuration:
RateRulesTypeValueMatches
Premium seller electronicsseller: slr_abc + product_category: electronicsPercentage8%Electronics from that seller (2 dimensions — most specific)
Electronics commissionproduct_category: electronicsPercentage12%Other sellers’ electronics (1 dimension)
Global commission(none, is_default)Percentage15%Everything else
An electronics item from seller slr_abc gets 8% — the two-dimension rate beats the one-dimension category rate, regardless of creation order.

The calculation pipeline

The getCommissionLines step calculates commissions when an order is placed:
  1. Load all enabled rates with their rules and per-currency values. Rates pinned to a currency_code apply only to orders in that currency.
  2. Match items — for each line item, find matching rates and pick the most specific (see above).
  3. Calculate — the base amount is the item subtotal, plus tax when include_tax is on. Percentage: (base × value) / 100. Fixed: the per-currency amount.
  4. Shipping — governed solely by the global commission: when its include_shipping flag is on, each shipping method gets a commission line calculated from the global rate.
  5. Output — one CommissionLine per commissioned item and shipping method.
All commission calculations use BigNumber arithmetic for precision. This is critical for financial accuracy — standard floating-point math can introduce rounding errors.

API examples

Set up the global commission (Admin API)

curl -X POST http://localhost:9000/admin/commission-rates \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Global Commission",
    "code": "global",
    "type": "percentage",
    "value": 15,
    "is_default": true,
    "include_shipping": true
  }'

Create a scoped rate with rules (Admin API)

curl -X POST http://localhost:9000/admin/commission-rates \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Electronics Commission",
    "code": "electronics",
    "type": "percentage",
    "value": 12,
    "rules": [
      { "reference": "product_category", "reference_id": "pcat_electronics" }
    ]
  }'

Create a fixed rate with per-currency amounts

curl -X POST http://localhost:9000/admin/commission-rates \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Flat Listing Fee",
    "code": "flat-fee",
    "type": "fixed",
    "value": 2,
    "values": [
      { "currency_code": "usd", "amount": 2 },
      { "currency_code": "eur", "amount": 1.8 }
    ],
    "rules": [
      { "reference": "seller", "reference_id": "slr_abc123" }
    ]
  }'

List commission rates

curl http://localhost:9000/admin/commission-rates \
  -H "Authorization: Bearer <admin-token>"

Commission lines

A CommissionLine is the calculated commission for a single line item or shipping method:
FieldDescription
item_idThe order line item (null for shipping lines)
shipping_method_idThe shipping method (null for item lines)
commission_rate_idThe rate that was applied
codeCode of the applied rate
rateThe rate value used
amountThe calculated commission amount
Commission lines are linked to order line items via a read-only link, so an order’s items can be queried together with their commission data in a single request.

How commission connects to payouts

Commission lines are the bridge between orders and seller earnings:
  1. An order is completed → commission lines are calculated for each item
  2. When the order is credited to the seller’s payout account, the total commission is subtracted:
    seller_earnings = order.total - sum(commission_line.amount)
    
  3. The marketplace retains the commission amount
This separation means commission rates can be changed at any time without affecting already-calculated orders — the CommissionLine records serve as a permanent audit trail.

Next steps

Payouts

How seller earnings settle after commission.

Order Groups

The per-seller orders commissions are calculated on.