PHPackages                             bhhaskin/laravel-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. bhhaskin/laravel-billing

ActiveLibrary[Payment Processing](/categories/payments)

bhhaskin/laravel-billing
========================

Stripe billing and subscription management for Laravel applications.

0.3.1(6mo ago)14211MITPHPPHP ^8.1CI passing

Since Nov 4Pushed 6mo agoCompare

[ Source](https://github.com/bhhaskin/laravel-billing)[ Packagist](https://packagist.org/packages/bhhaskin/laravel-billing)[ RSS](/packages/bhhaskin-laravel-billing/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (8)Versions (5)Used By (1)

Laravel Billing
===============

[](#laravel-billing)

Stripe-based subscription and billing management for Laravel applications.

Features
--------

[](#features)

### Subscription Management

[](#subscription-management)

- **Multiple Plans &amp; Add-ons** - Support for base plans and both standalone and plan-dependent add-ons
- **Stripe Integration** - Full Stripe integration with webhook support
- **Proration** - Configurable proration for plan changes and cancellations
- **Plan Changes** - Immediate and scheduled plan changes with upgrade/downgrade detection
- **Trial Periods** - Optional trial periods per plan
- **Grace Periods** - Configurable grace periods for failed payments
- **Discount Codes** - Percentage and fixed discounts with flexible durations

### Financial Operations

[](#financial-operations)

- **Refund System** - Full and partial refunds with automatic credit creation
- **Customer Credits** - Complete credit/debit tracking with running balances and expiration support
- **Usage-Based Billing** - Track and bill for metered usage
- **Quota Tracking** - Track usage against limits with automatic warnings and exceeded events

### Developer Experience

[](#developer-experience)

- **Workspace Support** - Optional multi-tenancy with bhhaskin/laravel-workspaces
- **Audit Trail** - Optional audit logging with bhhaskin/laravel-audit
- **Fully Tested** - Comprehensive test suite with 90+ tests
- **UUIDs** - All models include UUIDs for secure API endpoints

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

[](#installation)

```
composer require bhhaskin/laravel-billing
```

### Publish Configuration

[](#publish-configuration)

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

### Publish and Run Migrations

[](#publish-and-run-migrations)

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

### Configuration

[](#configuration)

Add your Stripe credentials to `.env`:

```
STRIPE_KEY=your_stripe_key
STRIPE_SECRET=your_stripe_secret
STRIPE_WEBHOOK_SECRET=your_webhook_secret
```

Usage
-----

[](#usage)

### Add Billable Trait to User Model

[](#add-billable-trait-to-user-model)

```
use Bhhaskin\Billing\Concerns\Billable;

class User extends Authenticatable
{
    use Billable;
}
```

### Create Plans

[](#create-plans)

```
use Bhhaskin\Billing\Models\Plan;

$plan = Plan::create([
    'name' => 'Professional',
    'slug' => 'professional',
    'price' => 19.99,
    'interval' => 'monthly',
    'features' => ['feature1', 'feature2'],
    'limits' => ['websites' => 5, 'storage_gb' => 100],
]);
```

### Subscribe Users

[](#subscribe-users)

```
$user = User::find(1);
$plan = Plan::where('slug', 'professional')->first();

$subscription = $user->subscribe($plan);
```

### Check Subscriptions

[](#check-subscriptions)

```
// Check if user has any active subscription
if ($user->hasActiveSubscription()) {
    // ...
}

// Check if user is subscribed to specific plan
if ($user->subscribedToPlan($plan)) {
    // ...
}

// Get combined limits from all subscriptions
$limits = $user->getCombinedLimits();
$websiteLimit = $user->getLimit('websites');

// Check if user has specific feature
if ($user->hasFeature('ssl_certificate')) {
    // ...
}
```

### Plan Changes

[](#plan-changes)

Change subscription plans immediately or schedule for later:

```
$subscription = $user->subscriptions()->first();
$newPlan = Plan::where('slug', 'enterprise')->first();

// Immediate plan change with proration
$subscription->changePlan($newPlan, [
    'prorate' => true,
]);

// Schedule plan change for end of period
$subscription->changePlan($newPlan, [
    'schedule' => true,
    'schedule_for' => $subscription->current_period_end,
]);

// Preview plan change costs before applying
$preview = $subscription->previewPlanChange($newPlan);
// Returns: amount, proration_credit, upgrade_charge, is_upgrade, etc.

// Cancel scheduled plan change
$subscription->cancelScheduledPlanChange();
```

### Customer Credits

[](#customer-credits)

Manage customer credit balances for refunds, promotions, and adjustments:

```
// Add credit to customer balance
$user->customer->addCredit(
    amount: 25.00,
    type: 'promotional',
    description: 'Holiday promotion credit',
    options: ['expires_at' => now()->addMonths(3)]
);

// Get available credit balance
$balance = $user->customer->getAvailableCredit();

// Credits are automatically applied to invoices
// Or manually apply credits to an invoice
$amountApplied = $user->customer->applyCreditsToInvoice($invoice);

// View credit history
$credits = $user->customer->credits()
    ->where('type', 'refund')
    ->get();
```

### Refunds

[](#refunds)

Create full or partial refunds for paid invoices:

```
$invoice = $user->invoices()->where('status', 'paid')->first();

// Full refund
$refund = $invoice->refund();

// Partial refund
$refund = $invoice->refund(
    amount: 10.00,
    reason: 'requested_by_customer',
    description: 'Partial service credit'
);

// Check refund status
if ($refund->isSucceeded()) {
    // Refund completed - customer credit created
}

// Get refund information
$totalRefunded = $invoice->getTotalRefunded();
$remainingRefundable = $invoice->getRemainingRefundable();

if ($invoice->isFullyRefunded()) {
    // Invoice completely refunded
}
```

### Quota Tracking

[](#quota-tracking)

Track usage against plan limits and automatically fire events when quotas are reached:

```
// Record usage for a quota (e.g., disk space in MB)
$user->recordUsage('disk_space', 150.5);

// Get current usage
$currentUsage = $user->getUsage('disk_space');

// Set absolute usage (useful for syncing from external sources)
$user->setUsage('bandwidth', 5000);

// Decrement usage (e.g., when files are deleted)
$user->decrementUsage('disk_space', 50);

// Check if over quota
if ($user->isOverQuota('disk_space')) {
    // Prevent new uploads
}

// Get remaining quota
$remaining = $user->getRemainingQuota('websites'); // Returns remaining count

// Get percentage used
$percentage = $user->getQuotaPercentage('disk_space'); // Returns 0-100

// Reset usage to zero
$user->resetUsage('disk_space');
```

#### Quota Events

[](#quota-events)

The package fires events when quotas reach warning thresholds (default: 80%, 90%) or are exceeded:

```
// Listen to quota events in your EventServiceProvider
use Bhhaskin\Billing\Events\QuotaWarning;
use Bhhaskin\Billing\Events\QuotaExceeded;

protected $listen = [
    QuotaWarning::class => [
        SendQuotaWarningNotification::class,
    ],
    QuotaExceeded::class => [
        ArchiveUserFiles::class,
        SendQuotaExceededNotification::class,
    ],
];
```

Event properties:

- `$event->billable` - The billable model (User)
- `$event->quotaKey` - The quota identifier (e.g., 'disk\_space')
- `$event->currentUsage` - Current usage amount
- `$event->limit` - The quota limit from the plan
- `$event->thresholdPercentage` - Warning threshold (QuotaWarning only)
- `$event->overage` - Amount over limit (QuotaExceeded only)

Configure warning thresholds in `config/billing.php`:

```
'quota_warning_thresholds' => [80, 90, 95], // Fire warnings at these percentages
```

### API Routes

[](#api-routes)

Include the API routes in your `routes/api.php`:

```
Route::middleware('auth:sanctum')->group(function () {
    require __DIR__.'/../vendor/bhhaskin/laravel-billing/routes/api.php';
});
```

### Daily Billing Processing

[](#daily-billing-processing)

The package automatically schedules a daily billing command to process renewals, trial expirations, and grace periods. You can disable this in config and run it manually:

```
php artisan billing:process
```

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance68

Regular maintenance activity

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity37

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 ~1 days

Total

4

Last Release

187d ago

### Community

Maintainers

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

---

Top Contributors

[![bhhaskin](https://avatars.githubusercontent.com/u/4709778?v=4)](https://github.com/bhhaskin "bhhaskin (6 commits)")

---

Tags

laravelstripebillingpaymentssubscriptions

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/bhhaskin-laravel-billing/health.svg)

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

###  Alternatives

[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.5k25.9M107](/packages/laravel-cashier)[lanos/laravel-cashier-stripe-connect

Adds Stripe Connect functionality to Laravel's main billing package, Cashier.

84138.9k](/packages/lanos-laravel-cashier-stripe-connect)[mmanos/laravel-billing

A billing package for Laravel 4.

451.3k](/packages/mmanos-laravel-billing)[simonhamp/laravel-stripe-connect

1343.1k](/packages/simonhamp-laravel-stripe-connect)

PHPackages © 2026

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