1
Run the workflow
Pass the ids of the orders to The workflow returns the lines it wrote for all the orders. It throws if any id doesn’t belong to an order.
refreshOrderCommissionLinesWorkflow. This route refreshes one order.src/api/admin/orders/[id]/recompute-commission/route.ts
2
Check the result
Read the lines back through Item lines carry
query.graph, filtering by the order’s item ids.item_id. Shipping lines carry shipping_method_id and the description Shipping Commission.Backfill existing orders
The workflow takes any number of order ids and resolves them in one batch, so the rates load once per run. For a backfill, page through orders and refresh each page.src/scripts/backfill-commission.ts
Pass extra data with setCommissionContext
ThesetCommissionContext hook receives the calculation contexts before they reach the provider. Return a StepResponse with new contexts to fill additional_context for a custom provider, or return nothing to keep them.
src/workflows/hooks/commission-context.ts
order_id, seller_id, currency_code, items, and shipping_methods. Items carry the product’s tags and attribute_value_ids, which the system provider ignores but your own provider can use.
React with commissionLinesUpserted
ThecommissionLinesUpserted hook runs after the lines are written, as part of the same workflow run. If your handler throws, the run fails, and at checkout that fails the cart completion too.
src/workflows/hooks/commission-written.ts