Skip to main content

Flat-Rate Billing

Flat-rate billing charges a fixed price every billing period regardless of usage. It is the most straightforward subscription model and works well for SaaS products with tiered feature access.

Plan configuration

// config/subscribd.php
'plans' => [
    'starter' => [
        'name'           => 'Starter',
        'description'    => 'Full product access for individuals.',
        'rule'           => 'flat',
        'amount'         => 1900,       // $19.00/month in cents
        'currency'       => 'USD',
        'interval'       => 'month',
        'interval_count' => 1,
        'trial_days'     => 14,
        'features'       => [
            'projects'   => 5,
            'api'        => true,
            'support'    => 'email',
        ],
    ],
    'pro' => [
        'name'           => 'Pro',
        'description'    => 'Everything in Starter, plus priority support.',
        'rule'           => 'flat',
        'amount'         => 4900,       // $49.00/month in cents
        'currency'       => 'USD',
        'interval'       => 'month',
        'interval_count' => 1,
        'trial_days'     => 14,
        'features'       => [
            'projects'   => null,       // unlimited
            'api'        => true,
            'support'    => 'priority',
        ],
    ],
    'pro_annual' => [
        'name'           => 'Pro (Annual)',
        'rule'           => 'flat',
        'amount'         => 47040,      // $470.40/year (~20% discount)
        'currency'       => 'USD',
        'interval'       => 'year',
        'interval_count' => 1,
        'features'       => [
            'projects'   => null,
            'api'        => true,
            'support'    => 'priority',
        ],
    ],
],

Creating a subscription

use Pixelworxio\Subscribd\Actions\CreateSubscription;
use Pixelworxio\Subscribd\Models\Plan;

$plan = Plan::query()->where('key', 'starter')->firstOrFail();

app(CreateSubscription::class)->execute($user, $plan);

Upgrading mid-cycle

use Pixelworxio\Subscribd\Actions\SwapPlan;

$pro = Plan::query()->where('key', 'pro')->firstOrFail();

// Immediate charge/credit (default)
app(SwapPlan::class)->execute($user->subscription(), $pro);

// Apply at next renewal instead
app(SwapPlan::class)->execute($user->subscription(), $pro, ['prorate' => 'renewal']);

Checking plan access

use Pixelworxio\Subscribd\Facades\Entitlements;

// Gate a controller action on feature access
abort_unless(Entitlements::for($user)->allows('api'), 403);

// Check project limit
$limit = Entitlements::for($user)->limit('projects');
abort_if($user->projects()->count() >= $limit, 403, 'Project limit reached.');

Free plan

A plan with amount: 0 is automatically routed to the null gateway — no payment method is required and no charge is ever made:
'free' => [
    'name'     => 'Free',
    'rule'     => 'flat',
    'amount'   => 0,
    'currency' => 'USD',
    'interval' => 'month',
    'features' => [
        'projects' => 1,
        'api'      => false,
        'support'  => 'community',
    ],
],

Next steps