Sanka

Rule builder for subscription invoice generation

Learn how to use the rule builder when generating invoices from subscriptions, including family keys and formula patterns.

Last updated: May 29, 2026

Guide overview

This guide explains the core concepts behind the rule builder used when generating invoices from subscriptions. You can define meter classifications, unit price calculations, minimum charges, and fixed fees in one setup flow.

Before you start

  • The subscription has item lines.
  • The target meter is linked to the subscription.
  • If needed, the item or item line has fields for unit price, minimum charge, fixed fee, or similar pricing inputs.

Step 1: Open the rule builder

  1. Open Commerce > Subscriptions.
  2. Select the subscription, then open Generate Invoice from Subscription from the actions menu.
  3. Turn on Add meter billing.
  4. Select Rule builder.
Notes:
  • Simple builder works well when one formula is enough for the condition.
  • Rule builder is better when you want to separate classification rules, pricing rules, and adjustment rules.

Step 2: Configure classification rules

Classification rules decide which meter rows should be calculated by which pricing group.Examples:
  • Charge ID = 6303, 6304, 6305 for calls
  • Charge ID = 6302 for SMS
This is where you use a family key. A family key is the shared key that connects a classification rule to a pricing rule.Examples:
  • Family key for calls: isdn_usd
  • Family key for SMS: sms_usd
Key points:
  • Use the same family key in the related pricing rule.
  • The family key is an internal decision key. It identifies which calculation rule should be used.
  • The output label is the name shown on the invoice line.
  • The component target controls which item line the formula references.

Step 3: Configure pricing rules

Pricing rules define the calculation method for each family key.One family can have multiple patterns. Patterns are evaluated from top to bottom, and the first matching pattern is used.Example:
  • Family key isdn_usd
    • Pattern 1: usage >= 2
    • Pattern 2: otherwise
Formula types:
  • Quantity formula: Calculates the invoice quantity.
  • Unit price formula: Calculates the amount per unit.
  • Amount formula: Calculates the amount directly instead of using quantity and unit price.
Common formula examples:
Text
meter_field("usage")
item_field("unit_price_field_id")
line_field("line_total")
sum_lines("line_total")
Meanings:
  • meter_field(...): References a meter value.
  • item_field(...): References an item or item line value.
  • line_field(...): References a value on the invoice line being generated.
  • sum_lines(...): References the total of multiple generated lines.

Step 4: Review adjustment rules and preview

Adjustment rules are used when you need to add charges separately from meter lines.Examples:
  • Add one line for a monthly fixed fee.
  • Add only the difference when usage does not meet the minimum charge.
  • Reflect free allowance or discount amounts as an adjustment.
After setup, review the result in Preview. The preview uses the selected subscription and shows which classification rule, family key, and pattern were used before you generate the invoice.

Operating tips

  • Always use the same family key in the classification rule and pricing rule.
  • Patterns are evaluated from top to bottom, so put the strictest conditions first.
  • Manage the invoice line name with the output label, not the family key.
  • Start with a small number of rules, then add more after confirming the preview.
  • If you only need simple conditions, the simple builder may be easier to maintain.