Function: calculatePrices()
function calculatePrices<TContext extends EvaluatePricingContext>(partitioned: PricingEvaluationResult<TContext>, options?: CalculatePricesOptions<TContext>): PricingCalculation<TContext["line_items"][number]>;Defined in: shared/pricing/calculator.ts:146
Turn a partitioned PricingEvaluationResult into per-line and
per-order subtotals with a traceable, ordered breakdown. Pure — no
IO, no globals, deterministic given inputs.
Pipeline per line item (in order):
- Base subtotal. Find the single
base-phase rule on this line and sum everyBASE_PRICEaction'samount_cents. If more than one base-phase rule matched, throwMultipleBasePriceRulesError. If zero matched, fall back toline_item.base_price_cents, then to0. Multiply byquantity— the line's own unit axis, times the base rule's optionalper(duration) axis when it declares one (seeresolveDurationAxis). non_compoundingpass. Each matched rule's actions apply independently againstbase_cents— deltas are computed off the base, not the running subtotal, and summed in. Multiple non_compounding rules therefore do not stack with each other.compoundingpass. Sequential application against the running subtotal inpriorityascending order (matchingloadRules).postpass. Same mechanics as compounding.
Then each line's subtotal_cents is summed into lines_total_cents,
and the same four-phase pipeline runs against the order-level rules
to produce total_cents.
Subtotals are clamped at zero: a discount that would drive the
running subtotal negative records delta_cents = -before_cents
instead of the action's full negative value.
Rounding: half-away-from-zero, applied at each multiplication step
(percentage applications and per_unit scaling). Sub-cent values are
never surfaced.
Type Parameters
| Type Parameter |
|---|
TContext extends EvaluatePricingContext |
Parameters
| Parameter | Type |
|---|---|
partitioned | PricingEvaluationResult<TContext> |
options | CalculatePricesOptions<TContext> |
Returns
PricingCalculation<TContext["line_items"][number]>