PHPackages                             mahmoud-elboshy/laravel-hierarchical-billing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. mahmoud-elboshy/laravel-hierarchical-billing

ActiveLibrary[Payment Processing](/categories/payments)

mahmoud-elboshy/laravel-hierarchical-billing
============================================

A Laravel package for managing hierarchical account billing — supporting subscription, per-event, and sub-account billing models within a single tenant.

v1.0.0(2mo ago)00MITPHPPHP ^8.1

Since May 16Pushed 2mo agoCompare

[ Source](https://github.com/Mahmoud-ElBoshy/laravel-hierarchical-billing)[ Packagist](https://packagist.org/packages/mahmoud-elboshy/laravel-hierarchical-billing)[ RSS](/packages/mahmoud-elboshy-laravel-hierarchical-billing/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Laravel Hierarchical Billing
============================

[](#laravel-hierarchical-billing)

[![Latest Version on Packagist](https://camo.githubusercontent.com/07c7882a684529d194f0535ba5ccd71eeed72373b0b76747260e1bcf698c20e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61686d6f75642d656c626f7368792f6c61726176656c2d68696572617263686963616c2d62696c6c696e672e737667)](https://packagist.org/packages/mahmoud-elboshy/laravel-hierarchical-billing)[![License](https://camo.githubusercontent.com/3e1bc91aec45978b6fcf4cf4c2f44a63e998b680e73deac4a4952ee2350046f4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4d61686d6f75642d456c426f7368792f6c61726176656c2d68696572617263686963616c2d62696c6c696e67)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/83dd395020c37276225039739320f6c8e7e99963ab21ee3d09282cb48dad2a60/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c7565)](https://php.net)[![Laravel Version](https://camo.githubusercontent.com/b1048e429ceb7ebeecc65ce60d1cd51cea1d263e105c8b54dc0c69606266bb76/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31302532422532303131253242253230313225324225323031332532422d726564)](https://laravel.com)

A Laravel package for managing **hierarchical account billing** — supporting subscription, per-event, and sub-account billing models within a single tenant.

Built from real-world experience running a production SaaS platform.

---

The Problem
-----------

[](#the-problem)

Most billing packages handle simple user → subscription flows. But what if your SaaS has:

- A **main organization** paying a monthly subscription
- **Sub-accounts** (departments/branches) each with their own billing
- **Per-event charges** on top of the subscription

No existing package handles this out of the box. This one does.

---

Features
--------

[](#features)

- ✅ **3 billing models** in one package: Subscription, Per-Event, Sub-Account
- ✅ **Hierarchical accounts** — main accounts with unlimited sub-accounts
- ✅ **Polymorphic** — attach billing to any model (User, Organization, Team, etc.)
- ✅ **Transaction tracking** — full audit trail for every charge
- ✅ **Trial &amp; Grace periods** — configurable out of the box
- ✅ **Gateway agnostic** — works with any payment gateway
- ✅ **Laravel 10, 11, 12 &amp; 13** support

---

Installation
------------

[](#installation)

```
composer require mahmoud-elboshy/laravel-hierarchical-billing
```

Publish and run migrations:

```
php artisan vendor:publish --tag="hierarchical-billing-migrations"
php artisan migrate
```

Publish config (optional):

```
php artisan vendor:publish --tag="hierarchical-billing-config"
```

---

Usage
-----

[](#usage)

### 1. Add the trait to your model

[](#1-add-the-trait-to-your-model)

```
use MahmoudElBoshy\HierarchicalBilling\Traits\HasBilling;
use MahmoudElBoshy\HierarchicalBilling\Traits\HasSubAccounts;

class Organization extends Model
{
    use HasBilling, HasSubAccounts;
}
```

---

### 2. Subscription Billing

[](#2-subscription-billing)

```
// Subscribe an organization to a plan
$organization->subscribe('plan_pro', [
    'ends_at' => now()->addMonth(),
]);

// Check subscription status
$organization->isSubscribed(); // true

// Cancel subscription
$organization->cancelSubscription();
```

---

### 3. Per-Event Billing

[](#3-per-event-billing)

```
// Charge for a specific event
$billingAccount = $organization->billingAccount;

$billingAccount->billedEvents()->create([
    'event_reference' => 'EVENT-001',
    'event_type'      => 'conference',
    'amount'          => 500.00,
    'currency'        => 'SAR',
    'billed_at'       => now(),
]);
```

---

### 4. Sub-Account Billing

[](#4-sub-account-billing)

```
// Create a sub-account under the main organization
$subAccount = $organization->createSubAccount([
    'metadata' => ['department' => 'Marketing'],
]);

// Check sub-account count
$organization->activeSubAccountsCount(); // 1

// Check if limit reached
$organization->hasReachedSubAccountLimit(); // false
```

---

### 5. Billing Status Checks

[](#5-billing-status-checks)

```
$organization->isSubscribed();             // true/false
$organization->billingAccount->isActive(); // true/false
$organization->billingAccount->onTrial();  // true/false
$organization->billingAccount->hasExpired(); // true/false
$organization->billingAccount->isSubAccount(); // true/false
```

---

Configuration
-------------

[](#configuration)

```
// config/hierarchical-billing.php

return [
    'default_model'      => 'subscription', // subscription | per_event | sub_account
    'currency'           => 'SAR',
    'sub_account_limit'  => null,           // null = unlimited
    'trial_days'         => 14,
    'grace_period_days'  => 3,
];
```

---

Database Schema
---------------

[](#database-schema)

TablePurpose`billing_accounts`Main &amp; sub-accounts with hierarchy via `parent_id``billing_transactions`Full transaction history`billed_events`Per-event billing records---

Roadmap
-------

[](#roadmap)

- Artisan commands for billing management
- Webhook handling helpers
- Invoice generation
- Usage-based billing model
- Proration support

---

Contributing
------------

[](#contributing)

Contributions are welcome! Please open an issue first to discuss what you'd like to change.

---

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE.md) for details.

---

Author
------

[](#author)

**Mahmoud El Boshy** — Senior Backend Engineer
[GitHub](https://github.com/Mahmoud-ElBoshy) · [LinkedIn](https://www.linkedin.com/in/mahmoudelboshy/)

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance86

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

70d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11808812?v=4)[Mahmoud El Boshy](/maintainers/Mahmoud-ElBoshy)[@Mahmoud-ElBoshy](https://github.com/Mahmoud-ElBoshy)

---

Top Contributors

[![Mahmoud-ElBoshy](https://avatars.githubusercontent.com/u/11808812?v=4)](https://github.com/Mahmoud-ElBoshy "Mahmoud-ElBoshy (2 commits)")

---

Tags

laravelbillingsubscriptionsaasmulti-tenanthierarchicalsub-account

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/mahmoud-elboshy-laravel-hierarchical-billing/health.svg)

```
[![Health](https://phpackages.com/badges/mahmoud-elboshy-laravel-hierarchical-billing/health.svg)](https://phpackages.com/packages/mahmoud-elboshy-laravel-hierarchical-billing)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.3M347](/packages/psalm-plugin-laravel)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[api-platform/laravel

API Platform support for Laravel

58174.6k17](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
