Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7859afc
feat: establish standalone subscription package and fail-closed Gate …
mstfkhazaal Oct 29, 2026
ecc74e0
test: avoid mass assigning Illuminate base User fixture
mstfkhazaal Oct 29, 2026
9e14702
ci: scope initial style check to new files and track upstream style debt
mstfkhazaal Oct 29, 2026
740e914
style: conform new permission tests to Laravel Pint constructor syntax
mstfkhazaal Oct 29, 2026
3e1c109
docs: codify universal subscriptions product spec and safe continuati…
mstfkhazaal Oct 29, 2026
a790550
docs: mark fork distribution status, verified CI and draft PR
mstfkhazaal Oct 29, 2026
33f25be
docs: track complete subscription platform backlog and contributor co…
mstfkhazaal Oct 29, 2026
3c8e93b
feat: exact decimal money arithmetic with ISO currency scales and reg…
mstfkhazaal Oct 29, 2026
9a31709
feat: add exact subscription pricing quote API beside legacy display …
mstfkhazaal Oct 29, 2026
9336a92
fix: accept internal high-precision BCMath fractional values before r…
mstfkhazaal Oct 29, 2026
09abd3e
feat: preserve canonical decimal plan/discount prices and add forward…
mstfkhazaal Oct 29, 2026
a6caa46
chore: publish widening monetary migration in Subbase installer
mstfkhazaal Oct 29, 2026
b32b1fc
feat: add optional fail-closed tenant isolation contract for subscrip…
mstfkhazaal Oct 29, 2026
d6eb275
feat: tenant-scope Filament plan, discount and subscription resource …
mstfkhazaal Oct 29, 2026
76361fd
fix: correct tenant-aware resource permission method arguments
mstfkhazaal Oct 29, 2026
55215b9
style: align new billing security and integration test code with Pint
mstfkhazaal Oct 29, 2026
f9f8017
test: verify forward decimal precision migration retains historical p…
mstfkhazaal Oct 29, 2026
26538fb
ci: include precise price migration integration test in formatting gate
mstfkhazaal Oct 29, 2026
1fc3258
test: verify exact percent discounts across currency-specific plan pr…
mstfkhazaal Oct 29, 2026
e191a50
ci: lint exact multi-currency pricing regression tests
mstfkhazaal Oct 29, 2026
22a91ad
chore: adopt FNX Software Composer identity while keeping legacy PHP …
mstfkhazaal Oct 29, 2026
ed02d3e
docs: record exact monetary pricing, tenant scope, package usage and …
mstfkhazaal Oct 29, 2026
05736bf
feat: authorize subscription cancellation per billable tenant and tes…
mstfkhazaal Oct 29, 2026
e51cae5
style: normalize new subscription lifecycle service and access tests
mstfkhazaal Oct 29, 2026
789c284
docs: record tested subscription cancellation and current CI status
mstfkhazaal Oct 29, 2026
c66a4a2
feat(licenses): add app SKU offers, reseller accounts, wholesale orde…
mstfkhazaal Oct 29, 2026
dd67229
feat(licenses): authorize provider onboarding, snapshot wholesale ord…
mstfkhazaal Oct 29, 2026
94ae5a7
test(licenses): verify wholesale pricing, safe fulfillment, reseller …
mstfkhazaal Oct 29, 2026
1c97a91
ci: inspect exact Pint fixes for new licensing files
mstfkhazaal Oct 29, 2026
61e6ede
fix(licensing): allow confirmed gateway orders awaiting payment to is…
mstfkhazaal Oct 29, 2026
ab62319
style(licensing): apply Pint exact formatting and restore normal CI
mstfkhazaal Oct 29, 2026
848603b
feat(filament): add license products, pricing, reseller approval, ord…
mstfkhazaal Oct 29, 2026
d5c1b19
fix(filament5): match Resource navigation group property UnitEnum typing
mstfkhazaal Oct 29, 2026
4703f78
feat(licensing): snapshot plan SKU and duration at purchase so later …
mstfkhazaal Oct 29, 2026
e853250
fix(licenses): validate admin-defined prices and prove purchased key …
mstfkhazaal Oct 29, 2026
0a0a204
test(filament): load licensing resources and deny anonymous catalog/p…
mstfkhazaal Oct 29, 2026
132263c
ci(filament): enforce formatting and PHPUnit class load for all resel…
mstfkhazaal Oct 29, 2026
99c424a
feat(resellers): add private provider dashboard with per-currency inv…
mstfkhazaal Oct 29, 2026
eb553cf
ci: capture exact Pint diff for newly generated Filament resource UI
mstfkhazaal Oct 29, 2026
62cabc5
style(licenses): normalize Gate and reseller dashboard imports
mstfkhazaal Oct 29, 2026
91b8085
style(filament): apply exact Pint-normalized licensing resources and …
mstfkhazaal Oct 29, 2026
1e0d815
security: enforce host tenant access on provider approval, purchase, …
mstfkhazaal Oct 29, 2026
ede24c3
test: deny cross-tenant reseller bulk purchase and inventory export w…
mstfkhazaal Oct 29, 2026
4a87faa
docs(resellers): define wholesale license business model, entitlement…
mstfkhazaal Oct 29, 2026
e84754d
docs: record verified licensing test counts and Draft release gates
mstfkhazaal Oct 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Package Tests
on:
push:
branches: [main, 'feat/**', 'fix/**']
pull_request:
permissions:
contents: read
jobs:
unit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
extensions: mbstring, dom, sqlite3, pdo_sqlite, bcmath
coverage: none
tools: composer:v2
- run: composer validate --no-check-publish --strict
- run: composer update --no-interaction --prefer-dist
- name: Syntax check all licensing admin resources
run: |
find src/Filament/Resources/LicenseProducts src/Filament/Resources/LicenseOffers src/Filament/Resources/LicenseProviders src/Filament/Resources/LicenseOrders src/Filament/Resources/LicenseKeys -name '*.php' -exec php -l {} \;
- run: vendor/bin/phpunit
# The upstream fork has pre-existing style drift. Format existing files in a separate PR.
- run: vendor/bin/pint --test src/Support/SubbasePermission.php tests/TestCase.php tests/Authorization/SubbasePermissionTest.php src/Support/Money.php tests/Money/MoneyTest.php src/Support/SubbaseTenancy.php src/Contracts/TenantAccess.php tests/Tenancy/SubbaseTenancyTest.php tests/Money/PrecisionMigrationTest.php tests/Money/ExactPricingTest.php src/Services/SubscriptionAdministration.php tests/Subscriptions/SubscriptionAdministrationTest.php src/Models/LicenseProduct.php src/Models/LicenseOffer.php src/Models/LicenseProvider.php src/Models/LicenseOrder.php src/Models/LicenseKey.php src/Models/LicenseSale.php src/Services/LicenseProviderService.php src/Services/LicenseOrderService.php src/Services/LicenseFulfillmentService.php src/Services/LicenseInventoryService.php src/Services/LicenseRedemptionService.php src/Services/LicenseResaleService.php src/Services/LicenseProviderDashboard.php tests/Licensing/LicenseTestCase.php tests/Licensing/LicenseWholesaleTest.php tests/Licensing/LicenseRedemptionTest.php tests/Licensing/LicenseAdminResourcesTest.php
- name: Pint licensing Filament 5 resources
run: vendor/bin/pint --test src/Filament/Resources/LicenseProducts src/Filament/Resources/LicenseOffers src/Filament/Resources/LicenseProviders src/Filament/Resources/LicenseOrders src/Filament/Resources/LicenseKeys
- run: composer audit --no-dev
16 changes: 16 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Subbase package contribution rules

Goal: one reusable subscription engine for standalone Laravel and all organization/tenant SaaS apps, **without mandatory Fenix Accounts dependencies**.

- Read `docs/PRODUCT-SPEC.md`, `docs/PROGRESS.md`, `docs/UNIVERSAL-BILLING.md`, `docs/SECURITY-MIGRATION.md` before modifying business rules.
- Detect actual PHP, Laravel, Filament and laravelcm/laravel-subscriptions versions before using version-specific APIs.
- Keep existing Composer and PHP namespaces stable until a coordinated versioned migration; no silent renames or destructive data conversion.
- Keep subscription business operations in tested actions/services; UI and API delegate. Prefer Eloquent relations, explicit indexes, transactions and locking.
- Never conflate authorization with authentication. Explicitly scope both the selected billable and all record/read-model queries to the permitted tenant.
- Use exact decimal / integer-scaled monetary computations and currency scales, never float for financial truth.
- Keep any model-translations package choice an internal implementation detail; do not make all host apps use Spatie or Astrotomic.
- No dependencies on Fenix, ZITADEL, a particular tenancy package or a fixed `User` model.
- Every important change needs tests: unauthenticated, unauthorized, cross-tenant, concurrency, invoice/payment consistency and migration compatibility.
- PHP: strict types for new files, Laravel Pint, PSR-12 where compatible. Legacy file formatting is a separate mechanical PR.
- Preserve MIT license and original upstream authorship. Maintain `docs/PROGRESS.md` and `Changelog.md` per PR.
- No release or main-branch merge without a green CI, a compatibility demo and clearly identified breaking changes.
41 changes: 41 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Changelog

## Unreleased (2026-10-29) — Universal billing foundation

- Kept Subbase independent of Fenix Accounts for all Laravel applications.
- Hardened SubbasePermission: no implicit allow when Spatie is absent; native Laravel Gate is always checked.
- Passed the requesting authorization actor into Plan, Subscription and Discount policies (no Auth global mismatch).
- Added Testbench/PHPUnit authorization regression tests (5 passing on PHP 8.4 / Laravel 13).
- Added initial CI with Composer validation, scoped Pint and dependency audit.
- Documented broad product requirements, independent subscriber models, upgrade strategy and roadmap.

### Breaking behavior and outstanding work

Existing apps that relied on permissive missing-Spatie access will be denied until they grant explicit Laravel Gate abilities. No existing app has been upgraded. Tenant record scoping and financial decimal precision are **not yet implemented**. A stable release and new Composer name are pending.

## 2026-10-29 — Exact money, tenancy and package ownership

- Added high-precision BCMath `Money` and currency scale policy; implemented exact checkout pricing alongside legacy presentation methods.
- Widened Plan/Discount columns and pivot to decimal(20,4) using a forward-only upgrade migration; tested migrations/pricing on isolated SQLite.
- Introduced optional fail-closed host-defined `TenantAccess`, scoped Filament resources and record-aware policies.
- Changed feature-branch Composer identity to `fnx-software/subbase` while preserving existing PHP namespace.
- Expanded Testbench suite to 19 tests/38 assertions (CI run 40838411564), with follow-up installation/upgrade tests still required.
- Added `docs/INSTALLATION.md` for safe path-repo sandbox integration.

**Not yet released.** Multi-tenant end-to-end coverage, recurring billing, version tags, CRM/Zeno migration, and complete formatting/DB matrix are outstanding.

### Subscription administration

- Added `SubscriptionAdministration::cancel($billable, $actor, $subscriptionName, $immediately)` to cancel a named subscription after Laravel Gate and tenant-policy validation, with DB transaction/lock and cross-organization isolation tests.
- Latest CI tested **23 PHPUnit tests / 44 assertions** and scoped Pint + Composer audit ([run 40839099089](https://github.com/fnx-software/subbase/actions/runs/40839099089)).
- Cancellation does not trigger a refund; payment provider refund workflows remain separate and unimplemented.

## 2026-10-29 — Wholesale license keys and provider reseller program

- Added app-SKU-based license catalog with retail/wholesale pricing, MOQ and immutable plan/SKU/term snapshots per order.
- Added Provider application, review/approval/suspension, server-priced orders, single-use encrypted random keys, redemption and subscription activation.
- Added independently declared reseller sales, per-currency gross margin dashboard, restricted key export and optional host tenant checks.
- Registered Filament 5 resources for catalog, offers, provider decisions, paid orders and masked inventory.
- Added 12-key CRM reseller, annual redemption, duplicate token, price change and tenant isolation test coverage.
- Payment gateway verification and protected routes are part of the coordinated `fnx-software/subbase-payment` PR #2.
- **No live merchant settlement certification; feature remains Draft.**
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> **FNX Software Subbase fork:** One reusable subscriptions engine for standalone and multi-tenant Laravel projects. Feature-branch Composer name: `fnx-software/subbase` (default branch not migrated); PHP namespace stays `Nafiswatsiq\\Subbase`. The [implementation guide](docs/INSTALLATION.md), [progress tracker](docs/PROGRESS.md), and [draft PR #2](https://github.com/fnx-software/subbase/pull/2) document the status. **Do not install in production yet.**

<img src="./.github/resources/banner-subbase.jpg" alt="header" class="filament-hidden" />

# Subbase - Filament Subscription Management Plugin
Expand Down Expand Up @@ -369,3 +371,8 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information.
- Built with [Filament](https://filamentphp.com)
- Powered by [laravelcm/laravel-subscriptions](https://github.com/laravelcm/laravel-subscriptions)
- Internationalization by [Spatie Laravel Translatable](https://github.com/spatie/laravel-translatable)


### License keys and reseller/provider channel

The FNX feature branch now contains [License Key & Provider documentation](docs/LICENSING-RESELLERS.md): sell app-specific plans with separate retail and wholesale prices, approve a business reseller, issue encrypted single-use keys only after cleared payment, and allow independent resale with gross-margin reporting. A customer activates their plan when a key is redeemed, not when the reseller bought it. See [development progress](docs/PROGRESS.md). **This is not a production-ready payment release.**
86 changes: 56 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,58 @@
{
"name": "nafiswatsiq/subbase",
"description": "Filament plugin for advanced subscriptions",
"type": "library",
"license": "MIT",
"keywords": ["filament", "subscription", "laravel", "saas", "billing", "multi-currency"],
"homepage": "https://github.com/nafiswatsiq/subbase",
"authors": [
{
"name": "Nafis Watsiq",
"email": "nafiswatsiq@gmail.com"
"name": "fnx-software/subbase",
"description": "FNX Software universal subscription management for Laravel and Filament",
"type": "library",
"license": "MIT",
"keywords": [
"filament",
"subscription",
"laravel",
"saas",
"billing",
"multi-currency"
],
"homepage": "https://github.com/fnx-software/subbase",
"authors": [
{
"name": "Nafis Watsiq",
"email": "nafiswatsiq@gmail.com"
}
],
"require": {
"php": "^8.2",
"filament/filament": "^5.0",
"laravelcm/laravel-subscriptions": "^1.8",
"spatie/laravel-package-tools": "^1.16",
"ext-bcmath": "*"
},
"autoload": {
"psr-4": {
"Nafiswatsiq\\Subbase\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Nafiswatsiq\\Subbase\\SubbaseServiceProvider"
]
}
},
"require-dev": {
"orchestra/testbench": "^11.3",
"phpunit/phpunit": "^12.5",
"laravel/pint": "^1.27"
},
"autoload-dev": {
"psr-4": {
"Nafiswatsiq\\Subbase\\Tests\\": "tests/"
}
},
"scripts": {
"test": "phpunit",
"lint": "pint --test"
},
"support": {
"source": "https://github.com/fnx-software/subbase",
"issues": "https://github.com/fnx-software/subbase/pulls"
}
],
"require": {
"php": "^8.2",
"filament/filament": "^5.0",
"laravelcm/laravel-subscriptions": "^1.8",
"spatie/laravel-package-tools": "^1.16"
},
"autoload": {
"psr-4": {
"Nafiswatsiq\\Subbase\\": "src/"
}
},
"extra": {
"laravel": {
"providers": [
"Nafiswatsiq\\Subbase\\SubbaseServiceProvider"
]
}
}
}
}
24 changes: 24 additions & 0 deletions config/subbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,30 @@

'default_currency' => 'USD',

// ISO 4217 minor unit scales; overrides for special pricing/accounting cases.
// Monetary posting requires canonical decimal strings, not PHP floats.
'currency_scales' => [],

// Opt-in: host application defines record- and query-level isolation.
// If enabled without a resolver, every tenant query and action is denied.
'tenancy' => ['enabled' => false, 'access' => null],

// License keys belong to a catalog SKU and a subscription Plan, not to Fenix.
// This allows one billing engine to sell CRM, POS, Clinic or independent apps.
'licensing' => [
'key_prefix' => env('SUBBASE_LICENSE_PREFIX', 'LIC'),
'max_order_quantity' => 500,
'reseller_max_retail_price' => true,
'tables' => [
'products' => 'subbase_license_products',
'offers' => 'subbase_license_offers',
'providers' => 'subbase_license_providers',
'orders' => 'subbase_license_orders',
'keys' => 'subbase_license_keys',
'sales' => 'subbase_license_sales',
],
],

'theme' => env('SUBBASE_THEME', 'default'),

'locale_currency_map' => [
Expand Down
51 changes: 51 additions & 0 deletions database/migrations/add_license_order_contract_snapshots_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
$tables = config('subbase.licensing.tables');
Schema::table($tables['orders'], static function (Blueprint $table): void {
$table->unsignedBigInteger('contract_plan_id')->nullable();
$table->string('contract_product_sku', 80)->nullable();
$table->unsignedSmallInteger('contract_term_count')->nullable();
$table->string('contract_term_unit', 10)->nullable();
});

// Earlier prototype orders never included a frozen license term.
// Backfill a best-effort snapshot from their CURRENT catalog values;
// immutable historical terms cannot be reconstructed after edits.
DB::table($tables['orders'])->orderBy('id')->chunkById(100, function ($orders) use ($tables): void {
foreach ($orders as $order) {
$offer = DB::table($tables['offers'])->where('id', $order->offer_id)->first();
$product = $offer
? DB::table($tables['products'])->where('id', $offer->product_id)->first()
: null;

if (! $offer || ! $product) {
continue;
}

DB::table($tables['orders'])->where('id', $order->id)->update([
'contract_plan_id' => $offer->plan_id,
'contract_product_sku' => $product->sku,
'contract_term_count' => $offer->term_count,
'contract_term_unit' => $offer->term_unit,
]);
}
});
}

public function down(): void
{
// Deleting purchased terms would destroy contractual entitlements.
// A production rollback requires a reviewed data-safe migration.
}
};
60 changes: 60 additions & 0 deletions database/migrations/create_license_catalog_and_providers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
$tables = config('subbase.licensing.tables');

Schema::create($tables['products'], function (Blueprint $table): void {
$table->id();
$table->string('sku', 80)->unique();
$table->string('name', 150);
$table->boolean('is_active')->default(true);
$table->timestamps();
});

Schema::create($tables['offers'], function (Blueprint $table) use ($tables): void {
$table->id();
$table->foreignId('product_id')->constrained($tables['products'])->restrictOnDelete();
$table->unsignedBigInteger('plan_id')->index();
$table->string('sku', 120)->unique();
$table->char('currency', 3);
$table->decimal('retail_price', 20, 4);
$table->decimal('wholesale_price', 20, 4);
$table->unsignedSmallInteger('wholesale_minimum')->default(12);
$table->unsignedSmallInteger('term_count')->default(1);
$table->string('term_unit', 10)->default('year');
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index(['product_id', 'currency', 'is_active'], 'sb_license_offer_lookup');
});

Schema::create($tables['providers'], function (Blueprint $table): void {
$table->id();
$table->string('owner_type');
$table->string('owner_id', 191);
$table->string('business_name', 150);
$table->string('status', 20)->default('pending');
$table->timestamp('approved_at')->nullable();
$table->timestamp('suspended_at')->nullable();
$table->timestamps();
$table->unique(['owner_type', 'owner_id'], 'sb_license_provider_owner_unique');
$table->index(['status', 'created_at']);
});
}

public function down(): void
{
$tables = config('subbase.licensing.tables');
Schema::dropIfExists($tables['providers']);
Schema::dropIfExists($tables['offers']);
Schema::dropIfExists($tables['products']);
}
};
Loading
Loading