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 line items and shipping methods based on configurable conditions.

Commission rates

A CommissionRate defines how much commission the marketplace takes. Each rate has a type, a target, and an optional set of rules that determine when it applies.
FieldDescription
nameHuman-readable name (e.g. “Default Product Commission”)
codeUnique system identifier
typeFIXED (flat amount) or PERCENTAGE
targetITEM (applies to line items) or SHIPPING (applies to shipping methods)
valueThe rate value — either a fixed amount or a percentage
min_amountOptional minimum commission (floor)
include_taxWhether to include tax in the base amount for calculation
priorityHigher priority rates are evaluated first
currency_codeOptional — restricts the rate to a specific currency

Commission rules

Rules determine when a rate applies. A rate without rules acts as a default — it applies to all items or shipping methods of its target type. Rules narrow the scope. Each rule has a reference (the type of condition) and a reference_id (the value to match):
ReferenceMatches against
productA specific product ID
product_typeProducts of a given type
product_collectionProducts in a collection
product_categoryProducts in a category
sellerProducts owned by a specific seller
shipping_option_typeShipping options of a given type
A single rate can have multiple rules. The rate applies if any of its rules match.

Priority and matching

Rates are evaluated in descending priority order. The first matching rate wins — subsequent rates are not applied. This lets you set up specific overrides with high priority and catch-all defaults with low priority. Example configuration:
RatePriorityRulesTypeValue
Electronics Commission10product_category: "electronics"Percentage12%
Premium Seller Rate5seller: "slr_abc123"Percentage8%
Default Commission0(none — matches all)Percentage15%
An electronics product from the premium seller would match the Electronics Commission rate (priority 10), not the seller-specific rate (priority 5).

The calculation pipeline

The getCommissionLines method calculates commissions for a given cart or order context: 1. Load rates
  • All enabled commission rates are loaded with their rules, ordered by priority (highest first)
  • Rates are separated into ITEM and SHIPPING targets
2. Match items
  • For each line item, the system iterates through item-target rates in priority order
  • It checks each rate’s rules against the item’s product, type, collection, category, and seller
  • Rates with no rules match everything (defaults)
  • First match wins
3. Calculate amount
  • Base amount is the item subtotal (optionally including tax if include_tax is true)
  • For PERCENTAGE rates: commission = (base_amount × value) / 100
  • For FIXED rates: commission = value
  • If the result is below min_amount, the minimum is used instead
4. Match and calculate shipping
  • Same process repeats for shipping methods using shipping-target rates
  • Matches against shipping_option_type rules
5. Output
  • Returns an array of CommissionLine records, one per 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

Create a commission rate (Admin API)

curl -X POST http://localhost:9000/admin/commission-rates \
  -H "Authorization: Bearer <admin-token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Default Product Commission",
    "code": "default-product",
    "type": "percentage",
    "target": "item",
    "value": 15,
    "priority": 0
  }'

Create a 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",
    "target": "item",
    "value": 12,
    "priority": 10,
    "rules": [
      {
        "reference": "product_category",
        "reference_id": "pcat_electronics"
      }
    ]
  }'

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. It stores:
FieldDescription
item_idReferences the order line item or shipping method
commission_rate_idThe rate that was applied
codeCode of the applied rate
rateThe actual rate value used
amountThe calculated commission amount
Commission lines are linked to order line items via a read-only link. This means you can query an order’s line items and include 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.