Looking to hire Laravel developers? Try LaraJobs

laravel-commission-plans maintained by amjadiqbal

Description
Open, tested commission-plan engine for legitimate direct-selling companies on Laravel: unilevel, binary and hybrid rank-bonus plans driven only by retail sales volume, genealogy, monthly payout runs with dry-run report, CSV export and a small distributor back office.
Author
Last update
2026/12/03 23:05 (dev-main)
License
Downloads
0

Comments
comments powered by Disqus

Laravel Commission Plans

An open, tested commission-plan engine for legitimate direct-selling companies on Laravel. Unilevel, binary and a hybrid rank-bonus plan, a genealogy, a monthly payout run with a dry-run report, CSV export, and a small distributor back office. You own the code; there are no per-distributor fees.

What it will and will not do

Commissions are driven only by retail sales volume. Every commissionable amount traces to a real sale with an order reference and a positive volume.

The engine refuses, by design and by test, any plan that pays on enrolment, recruitment or sign-up, and any investment-return or daily-yield feature. A plan config containing such a key is rejected before anything is calculated (GUARD-001, GUARD-002). Plans with unknown keys are rejected too (GUARD-004). This package is not for pyramid schemes, ROI-promise or crypto "investment" programmes.

Install

composer require amjadiqbal/laravel-commission-plans
php artisan migrate
php artisan vendor:publish --tag=commission-plans-config

Requires PHP 8.3+ and Laravel 12 or 13.

Data you provide

  • Distributor (cp_distributors): name, email, sponsor_id (sponsor tree), optional binary_parent_id + binary_leg (left/right).
  • Sale (cp_sales): distributor_id, unique reference, volume_cents, sold_at, optional refunded_at. Money is always integer cents.
use AmjadIqbal\CommissionPlans\Models\{Distributor, Sale};

$a = Distributor::create(['name' => 'Alice', 'email' => 'alice@example.com']);
$b = Distributor::create(['name' => 'Bob', 'email' => 'bob@example.com', 'sponsor_id' => $a->id]);
Sale::create(['distributor_id' => $b->id, 'reference' => 'ORD-1001', 'volume_cents' => 20000, 'sold_at' => now()]);

Plans

Configure in config/commission-plans.php. Rates are basis points (100 = 1%).

Plan Pays
unilevel A percentage of downline retail volume per level (levels_bps), if the sponsor reached min_personal_volume_cents. No compression.
binary rate_bps of the matched volume of the weaker leg, optional period_cap_cents, unmatched volume carried over (or discarded).
hybrid Unilevel plus a rank bonus: the highest rank whose personal and group volume thresholds are met pays bonus_bps of group volume.

Amounts are floored to whole cents once per payee and level. Sales refunded inside the period are excluded; the period is a calendar month in the configured timezone.

Monthly payout run

php artisan commissions:run 2026-11 unilevel                 # dry run, saves nothing
php artisan commissions:run 2026-11 unilevel --csv=out.csv   # dry run + CSV
php artisan commissions:run 2026-11 unilevel --finalize      # stores the run, once per period and plan

Periods must be finalized in order. A finalized run keeps a snapshot of the plan config it used. CSV cells that could run as spreadsheet formulas are neutralised.

$engine = app(\AmjadIqbal\CommissionPlans\Engine\PayoutEngine::class);
$report = $engine->dryRun('2026-11', 'binary');
$report->totalCents(); $report->byDistributor(); $report->toCsv();

Demo back office

A small server-rendered Blade UI (no build step): each distributor sees their downline and finalized commissions; admins calculate a dry run, finalize, and download CSV. Off by default.

// config/commission-plans.php
'back_office' => ['enabled' => true, 'prefix' => 'commission-plans', 'middleware' => ['web', 'auth']],

// AppServiceProvider::boot(): admin pages are denied unless this gate is defined
Gate::define('manage-commission-plans', fn ($user) => $user->is_admin);

By default a user maps to the distributor with the same email; set distributor_resolver to change that. It is a demo, not a finished portal.

Tested rule by rule

Every rule in Support\RuleCatalog has a test, and a meta-test fails if one does not. Plan rules are fixture-driven: tests/fixtures/*.json hold a small genealogy, sales and the exact expected lines. See docs/design-notes.md.

composer install && vendor/bin/phpunit

Not in v0.1

Dynamic compression, clawback of refunds after finalization, multi-currency, tax and KYC, payment execution. This package calculates and exports; paying people is yours.

License

MIT.

Custom Development

Hire me on Upwork for:

  • Package integration
  • Custom feature development
  • Technical consultation
  • Project implementation

Community Support

For priority support and enterprise solutions, please reach out via Upwork for direct assistance.