Charge filters, pricing_group_keys and prorated sum/unique_count were stored
but never billed: every billing path priced a charge over all of the
subscription's events with the charge's base properties. A filtered plan
billed every event at the default price, grouped pricing was one summed line,
and a prorated seat charge billed full seats.
- rago-billing charge_fees: Lago Fees::ChargeService#init_fees. One fee per
filter (MatchingAndIgnoredService scoping, oldest of identical filters wins)
plus the default bucket, one per pricing group, prorated aggregations with
the persisted value carried in on recurring metrics, should_persist_fee?.
- The invoice builder, period billing, invoice preview, progressive billing,
pay-in-advance (the event's own line), real-time wallet pricing and current
usage (REST, GraphQL, portal) all load through rago-db LoadedCharge, so they
see the same filters. A minimum true-up now covers all of a charge's lines.
- REST POST /events and /events/batch apply the billable metric expression
(Events::CalculateExpressionService); only Kafka did. Metric create/update
refuse an invalid expression or one without a field_name.
- charge_filters created_at is decoded as a timestamp (the live test caught it).
Tests: rago-billing charge_fees (11) and expression units (5); live Postgres
rago-jobs charge_filters_billing (3) and rago-api usage_lines (2). Full
workspace with pg-tests: 565 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>