Subscription Manager can now bill usage-based (metered) charges alongside a flat recurring fee (#3615735: Add a rating step for usage-based charges, delivered per connector scheduling mode). The module implements no measurement or aggregation itself; it provides a rating seam that sites and contrib modules plug into.
Implementing a rater
Implement \Drupal\subscription_manager\UsageRaterInterface and register it as a service tagged subscription_manager.usage_rater:
mymodule.storage_rater:
class: Drupal\mymodule\StorageUsageRater
arguments: ['@mymodule.metrics']
tags:
- { name: subscription_manager.usage_rater, priority: 10 }
priority is optional (default 0) and only matters when several raters are registered: higher priority is consulted first, which sets the order of the lines on the charge — every registered rater's lines are billed regardless.
rate($subscription, $period_start, $period_end) returns zero or more RatedLine objects — label, a free-form display quantity (e.g. "312 GB"), unitAmount, and an authoritative total, the amounts as decimal strings in major currency units (the subscription's currency). Return an empty array when there is nothing to bill. Implementations must be side-effect free and idempotent for a given period: the engine may rate the same period again when a failed charge is retried. Multiple registered raters compose — all their lines are billed.
What the engine does with it
For charge-based connectors (#3618739: Add a charge-based connector mode with a local billing cycle engine), each cycle anchor bills the base fee in advance plus the rated usage of the period that just ended (in arrears). The rated lines and their usage window are recorded in the charge record's data map under rated_lines. A zero-amount base with rated usage charges normally, so a free plan with metered overage works. Sites with no raters registered are unaffected.
Self-scheduling connectors
Pushing usage to services that own their own billing cycle (e.g. Stripe Billing) is not part of this change; it follows with the Stripe metering work in #3615738: Support metered (usage-based) prices alongside licensed subscription items.