PHPackages                             whilesmart/paywall - 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. whilesmart/paywall

ActiveLibrary

whilesmart/paywall
==================

Feature gates, quota checks, and usage tracking for Laravel applications

00PHPCI failing

Since Mar 24Pushed todayCompare

[ Source](https://github.com/whilesmartphp/paywall)[ Packagist](https://packagist.org/packages/whilesmart/paywall)[ RSS](/packages/whilesmart-paywall/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Whilesmart Paywall
==================

[](#whilesmart-paywall)

Feature gates, quota checks, and usage tracking for Laravel applications via the subscriptions microservice.

[![Latest Version on Packagist](https://camo.githubusercontent.com/9870c76fcc593642e61e2477f28de1dea499be24b3d664c082b332eaacc69e8f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7768696c65736d6172742f70617977616c6c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/whilesmart/paywall)

Features
--------

[](#features)

- **Feature Gates**: Gate routes and actions behind subscription features
- **Quota Enforcement**: Check usage limits before allowing access, return quota details on denial
- **Usage Tracking**: Buffer usage locally, flush to the microservice in batches
- **Stripe Billing Proxy**: Get checkout and portal URLs from the microservice without needing `stripe/stripe-php`
- **Multiple Providers**: External (microservice API) or local (database) subscription providers
- **Grace Periods**: Configurable grace period for expired subscriptions
- **Role Bypass**: Admin roles can bypass feature gates
- **Laravel Auto-Discovery**: Automatically registers service provider

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

[](#installation)

```
composer require whilesmart/paywall
```

Publish the config and migrations:

```
php artisan vendor:publish --tag=paywall-config
php artisan vendor:publish --tag=paywall-migrations
php artisan migrate
```

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

[](#configuration)

Set your environment variables:

```
PAYWALL_PROVIDER=external
PAYWALL_EXTERNAL_URL=http://localhost:3000
PAYWALL_EXTERNAL_API_KEY=sk_your_api_key
PAYWALL_SUBSCRIBER_TYPE=user
```

Define features in `config/paywall.php`:

```
'features' => [
    'project_creation' => [
        'name' => 'Project Creation',
        'description' => 'Create and manage projects',
        'default_access' => false,
        'bypass_roles' => ['admin'],
    ],
],
```

Usage
-----

[](#usage)

### Middleware

[](#middleware)

```
// Boolean feature gate — returns 402 if denied
Route::middleware('paywall:project_creation')->group(function () {
    Route::post('/projects', [ProjectController::class, 'store']);
});

// Quota check — returns 402 with quota details if exhausted
Route::middleware('paywall.quota:projects')->group(function () {
    Route::post('/projects', [ProjectController::class, 'store']);
});

// Usage tracking — records usage after response is sent
Route::middleware('paywall.usage:api_calls')->group(function () {
    Route::get('/api/data', [DataController::class, 'index']);
});
```

### Facade

[](#facade)

```
use Whilesmart\Paywall\Facades\Paywall;

// Boolean check
if (Paywall::hasAccess($user, 'project_creation')) {
    // allowed
}

// Detailed check with limits and subscription info
$result = Paywall::checkAccess($user, 'projects');
$result->allowed;              // bool
$result->reason;               // "Quota exceeded" etc.
$result->limit->remaining;     // 3
$result->subscription->status; // "active"

// Record usage
Paywall::recordUsage($user, 'api_calls', 1, ['endpoint' => '/api/users']);

// Stripe checkout (proxied via microservice)
$url = Paywall::getCheckoutUrl($user, 'pro', $successUrl, $cancelUrl);
return redirect($url);

// Stripe billing portal
$url = Paywall::getPortalUrl($user, $returnUrl);
return redirect($url);
```

### HasSubscription Trait

[](#hassubscription-trait)

```
use Whilesmart\Paywall\Traits\HasSubscription;

class User extends Model
{
    use HasSubscription;
}
```

```
$user->subscribed();           // bool
$user->onTrial();              // bool
$user->canAccess('projects');  // bool
$user->checkAccess('projects'); // AccessResult
$user->featureUsage('projects'); // FeatureLimit
$user->subscription();         // array|null
```

### Usage Buffer

[](#usage-buffer)

Usage is buffered locally to avoid HTTP calls during requests. Flush via cron:

```
php artisan paywall:flush-usage
```

Add to your scheduler:

```
$schedule->command('paywall:flush-usage')->everyMinute();
```

Requirements
------------

[](#requirements)

- PHP ^8.2
- Laravel ^11.0|^12.0

License
-------

[](#license)

The MIT License (MIT).

###  Health Score

20

↑

LowBetter than 16% of packages

Maintenance65

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity11

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.

### Community

Maintainers

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

---

Top Contributors

[![nfebe](https://avatars.githubusercontent.com/u/14317775?v=4)](https://github.com/nfebe "nfebe (3 commits)")

### Embed Badge

![Health badge](/badges/whilesmart-paywall/health.svg)

```
[![Health](https://phpackages.com/badges/whilesmart-paywall/health.svg)](https://phpackages.com/packages/whilesmart-paywall)
```

PHPackages © 2026

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