PHP Billing Library

June 12, 2026 · View on GitHub

Latest Stable Version Total Downloads codecov phpunit-tests behat-tests psalm phpcs

A pure domain library for billing and invoicing. No framework dependency — drop it into any PHP 8.3+ project.

It models the full billing pipeline: customers subscribe to resources under pricing plans, metered activities are recorded as actions, the calculator matches actions to prices to produce charges, and the aggregator groups charges into bills.

Supports one-time, metered, and recurring charging with multiple pricing strategies (fixed per-unit, percentage-based, tiered/progressive, discrete lookup), a formula DSL for smart discounts and installments, and a reseller hierarchy.

Installation

composer require hiqdev/php-billing

How It Works

Customer → Plan → Price

Sale → Action → Calculator → Charge → Aggregator → Bill
  1. A Customer subscribes to a Target (resource) under a Plan via a Sale
  2. Metered activity is recorded as an Action (type, target, quantity, time)
  3. Calculator matches each Action against Prices in the Plan → produces Charges
  4. Aggregator groups Charges into Bills (invoice line items)
  5. Billing orchestrates steps 3–4 and optionally persists the result

Core Entities

EntityRole
ActionA customer's metered activity of a certain Type at a certain Target
SaleSubscription binding a Customer to a Target under a Plan
PlanA tariff containing a set of Prices
PriceA billing rule — SinglePrice, EnumPrice, RatePrice, or ProgressivePrice
ChargeResult of matching an Action to a Price
BillAggregation of Charges into an invoice line item
CalculatorOrchestrates the billing pipeline
AggregatorGroups Charges into Bills by unique key
BillingTop-level entry point: calculate + aggregate + persist

Model UML

Documentation

Integration Points

This library is the billing core — a foundation that needs surrounding infrastructure to become a complete billing system. Typical layers built on top:

  • Storage — implement PlanRepositoryInterface, SaleRepositoryInterface, BillRepositoryInterface, etc. to connect to your database
  • Action producers — translate business events (purchases, resource measurements) into Action objects
  • Scheduler — periodic jobs that fetch usage metrics, create Actions, run Billing::perform(), and update Bills
  • Plan management UI — lets managers create Plans, configure Prices, and assign Plans to Customers
  • Read API — query layer for Bills, Charges, Actions with filtering, ordering, and access control

Many of these layers are use-case specific. This package provides the calculation engine; persistence, scheduling, and UI are your responsibility.

License

This project is released under the terms of the BSD-3-Clause license. Read more here.

Copyright © 2017-2026, HiQDev (http://hiqdev.com/)