PHPackages                             nandocdev/plinth-multitenant-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. nandocdev/plinth-multitenant-billing

ActivePackage[Payment Processing](/categories/payments)

nandocdev/plinth-multitenant-billing
====================================

Laravel package to automate payments and subscriptions via dLocal API

v0.3.0(2w ago)045↓45.8%MITPHPPHP ^8.2

Since May 16Pushed 2w agoCompare

[ Source](https://github.com/nandocdev/plinth-multitenant-billing)[ Packagist](https://packagist.org/packages/nandocdev/plinth-multitenant-billing)[ RSS](/packages/nandocdev-plinth-multitenant-billing/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (5)Used By (0)

Plinth: Multi-Tenant Billing &amp; Payment Orchestration
========================================================

[](#plinth-multi-tenant-billing--payment-orchestration)

[![Plinth Banner](docs/img/banner.png)](docs/img/banner.png)

[![Latest Version on Packagist](https://camo.githubusercontent.com/66f911f9ac52d69c3620ea07e137d703ee868b3d4956480c70d80b2bf9a5309a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706c696e74682f6c61726176656c2d6d756c746974656e616e742d62696c6c696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/plinth/laravel-multitenant-billing)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)

**Plinth** is a high-performance billing engine for Laravel SaaS applications. It provides a provider-agnostic abstraction layer that handles multi-tenant subscriptions, one-time payments, atomic usage metering, and financial integrity via an internal ledger.

🚀 Core Capabilities
-------------------

[](#-core-capabilities)

- **Dynamic Provider Switching**: Support Stripe and dLocal (extendable) out of the box. Each tenant can configure their own credentials.
- **Financial Integrity (Ledger)**: Append-only ledger for all transactions, preventing data corruption and enabling easy auditing.
- **Atomic Metering (Redis)**: High-performance usage tracking with atomic counters to prevent over-consumption in distributed systems.
- **SaaS First**: Built-in support for Plans, Subscriptions, Invoices, Quotas, and Entitlements (Feature Flags).
- **Store-First Webhooks**: Robust, multi-tenant webhook handling with cryptographic verification and queued processing.

---

📦 Installation
--------------

[](#-installation)

```
composer require nandocdev/plinth-multitenant-billing
```

### 1. Register Service Provider

[](#1-register-service-provider)

(Laravel auto-discovery usually handles this, but if not:) Add `Plinth\MultiTenantBilling\BillingServiceProvider::class` to your `config/app.php`.

### 2. Configuration &amp; Migrations

[](#2-configuration--migrations)

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

---

🛠 API Functionality
-------------------

[](#-api-functionality)

### 1. Dynamic Payment Resolution

[](#1-dynamic-payment-resolution)

Each tenant can have their own provider. You configure this in the `tenant_payment_providers` table.

```
use Plinth\MultiTenantBilling\Core\Models\TenantPaymentProvider;

TenantPaymentProvider::create([
    'tenant_id' => $tenant->id,
    'provider' => 'stripe', // or 'dlocal'
    'credentials' => [
        'secret_key' => 'sk_test_...',
        'webhook_secret' => 'whsec_...',
    ],
    'status' => 'active',
]);
```

### 2. Payment Processing

[](#2-payment-processing)

Use the `PaymentProcessor` to handle direct charges (B2C context).

```
use Plinth\MultiTenantBilling\Payments\Services\PaymentProcessor;

$processor = app(PaymentProcessor::class);

// Direct charge using tokenized payment method
$transaction = $processor->createPayin($order, [
    'payment_method' => 'pm_card_visa',
]);

echo $transaction->status; // PAID, PENDING, FAILED...
```

### 3. Hosted Checkout (Facade)

[](#3-hosted-checkout-facade)

For redirect-based flows (Checkout sessions).

```
use Plinth\MultiTenantBilling\Facades\Billing;

$session = Billing::checkout($tenant, [
    'amount' => 5000,
    'currency' => 'USD',
    'customer_id' => $customer->id,
    'success_url' => 'https://example.com/success',
    'cancel_url' => 'https://example.com/cancel',
]);

return redirect($session['url']);
```

### 4. Usage Metering &amp; Quotas

[](#4-usage-metering--quotas)

Manage resource consumption atomically using Redis.

```
use Plinth\MultiTenantBilling\Billing\Quotas\QuotaEnforcer;
use Plinth\MultiTenantBilling\Billing\Exceptions\QuotaExceededException;

$enforcer = app(QuotaEnforcer::class);

try {
    // Atomic check-and-consume (e.g., track 1 unit of 'api_calls')
    $enforcer->consume($tenant->id, 'api_calls', 1);

    // Logic here...
} catch (QuotaExceededException $e) {
    return response()->json(['error' => 'API limit reached'], 403);
}
```

### 5. Entitlements (Feature Flags)

[](#5-entitlements-feature-flags)

Check plan-based feature access with $O(1)$ complexity via Redis Sets.

```
use Plinth\MultiTenantBilling\Billing\Entitlements\EntitlementManager;

$manager = app(EntitlementManager::class);

if ($manager->hasFeature($tenant->id, 'premium_support')) {
    // Show premium features
}
```

---

⚓ Webhook Integration
---------------------

[](#-webhook-integration)

Plinth uses unique endpoints per tenant and provider to ensure maximum security and isolation.

### Routes Configuration

[](#routes-configuration)

Endpoints follow this pattern: `/api/{provider}/webhooks/{tenant_id}`.

**Example Webhook Setup:**

- **Stripe**: `https://your-api.com/api/stripe/webhooks/1`
- **dLocal**: `https://your-api.com/api/dlocal/webhooks/1`

The `WebhookController` handles:

1. **Signature Verification**: Validates the payload cryptographically using the specific tenant's secret.
2. **Store-First Persistence**: Saves the raw payload in `webhook_calls`.
3. **Async Processing**: Dispatches `ProcessWebhookJob` for status normalization and ledger recording.

---

📊 Domain Models Reference
-------------------------

[](#-domain-models-reference)

CategoryModels**Billing**`Plan`, `Subscription`, `SubscriptionItem`, `Invoice`, `InvoiceLine`, `BillingAttempt`**Payments**`Customer`, `Order`, `Transaction`, `PaymentMethod`, `Refund`, `Dispute`**Core**`LedgerEntry`, `TenantPaymentProvider`, `WebhookCall`, `UsageSnapshot`---

🧪 Testing
---------

[](#-testing)

The package includes a full suite of Pest tests.

```
vendor/bin/pest
```

For package development, Plinth utilizes `orchestra/testbench` to simulate the Laravel environment and provides a pre-configured `TestCase` with in-memory SQLite migrations.

---

📜 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

---

Developed with ❤️ by [Fernando Castillo (@nandocdev)](https://github.com/nandocdev)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance97

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 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

Every ~2 days

Total

4

Last Release

16d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a86ca08eb30b6efd48f67f12add60fc283d0b7521c98e1ecb65f06007cec9330?d=identicon)[nandocdev](/maintainers/nandocdev)

---

Top Contributors

[![nandocdev](https://avatars.githubusercontent.com/u/18200511?v=4)](https://github.com/nandocdev "nandocdev (46 commits)")

---

Tags

billingpayments

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/nandocdev-plinth-multitenant-billing/health.svg)

```
[![Health](https://phpackages.com/badges/nandocdev-plinth-multitenant-billing/health.svg)](https://phpackages.com/packages/nandocdev-plinth-multitenant-billing)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[asciisd/knet

Knet package is provides an expressive, fluent interface to KNet's payment services.

141.3k](/packages/asciisd-knet)

PHPackages © 2026

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