Skip to main content
The Commission module service reads and writes commission records without a workflow. Use it in steps, subscribers, and scheduled jobs, and use the workflows when you need rollback or the global-rate delete guard.

Resolve the service

Resolve the service from the container with MercurModules.COMMISSION.
The call returns enabled rates with their rules and per-currency values, plus the total count.

Generated methods

The service extends MedusaService, so every model gets the standard methods. For CommissionRate they are: The same set exists for CommissionRule, CommissionRateValue, and CommissionLine, for example listCommissionRules, createCommissionRateValues, and retrieveCommissionLine.
deleteCommissionRates doesn’t check for the global rate. Use deleteCommissionRatesWorkflow to keep the is_default rate safe.

Custom methods

The service overrides or adds these methods: getCommissionLines and getCommissionLinesBatch stamp the default provider’s id on any line without a provider_id. getCommissionLinesBatch falls back to one getCommissionLines call per context when the provider has no batch method.

Filter rates by scope type

scope_type filters rates by the dimensions their rules use, computed in the database. Pass one value, an array, or a comma-separated string. Several values are combined with OR, and an unknown value matches nothing.

Commission providers

A provider computes the lines from a calculation context. The module always registers the built-in system provider, which implements the rule matching algorithm, and uses it unless you configure another one.
src/modules/tiered-commission/service.ts
A provider class needs a static identifier and getCommissionLines. It can add getCommissionLinesBatch(contexts) to load its data once per batch. The module doesn’t cap amount, so keep it within the item’s total yourself. Export the class as a module provider so the commission module can register it.
src/modules/tiered-commission/index.ts
The module takes these options, typed as CommissionModuleOptions: A single configured provider becomes the default without is_default.