You can find the entire documentation for this package on our documentation site. Including several usecases with detailed explanation.
- Manage all Plans and Addons of your SaaS where users can subscribe to.
- Subscribe to one or more plans with different billing intervals.
- Manage optional features, if you need it. You can also stick with plans and just check for a subscribed plan.
- Offer countable and uncountable features. Use uncountable features to just enable/disable a functionality. Use countable features, for things like tokens, credits, and others. Attach different values of the feature to different plans, including "unlimited". Auto reset the values after given intervals.
- Consume Features as long as some amount is available. Split up usage on different plans, depending on the order of the plans.
- Translate your plans and features. Identify both by slug in your app, but offer it to your users localized, powered by spatie/laravel-translatable
- Order your plans, features (for visualisation to your users) and subscriptions (to keep control over usage order)
- Allow meta data in plans and subscriptions. The usage of meta data is up to you. In some usecase we take meta data to save currency or additional price information. This information can be used by a subsequent billing system.
- Billing. We don't create invoices or keep track on bills. Use the invoice service of your choice, doesn't matter which. Stripe, PayPal, your own software and any other. You just get events from this package, when subscriptions are created or renewed, and this can be used to trigger invoices. You are also free to wait for payment before you create the subscription or the other way round.
- Pricing. Yes there is a price column in the plan model, that can be used for visualisation. You also can use meta data for additional price information like we do it in some examples. But you don't need to use it. You can keep your prices in your billing system or save it separate from the plans. But indeed, if you use the price-column you can also get calculated prices for partial subscription intervals.
composer require lacodix/laravel-plans
To get familiar with all settings and possibilities, please see the more detailed examples. This is only a very quick overview how the package can work.
Add our HasSubscription Trait to any model.
use Lacodix\LaravelPlans\Models\Traits\HasSubscriptions;
class User extends Authenticatable {
use HasSubscriptions;
...
}
Create a Plan with Features (the latter is optional, if you don't need feature functionality).
use Lacodix\LaravelPlans\Enums\Interval;
use Lacodix\LaravelPlans\Models\Feature;
use Lacodix\LaravelPlans\Models\Plan;
$myPlan = Plan::create([
'slug' => 'my-plan',
'name' => 'My Plan', // can also be locale-array - see Feature below
'price' => 50.0,
'active' => true,
'billing_interval' => Interval::MONTH,
'billing_period' => 1,
'meta' => [
'price_per_token' => 0.05,
],
]);
$myFeature = Feature::create([
'slug' => 'tokens',
'name' => [
'de' => 'Zusätzliche Tokens',
'en' => 'Additional Tokens',
],
]);
$myPlan->features()->attach($myFeature, [
'value' => 1000,
'resettable_period' => 1,
'resettable_interval' => Interval::MONTH,
]);
// Subscribe to multiple plans
$user->subscribe($myPlan1, 'main');
$user->subscribe($myPlan2, 'addon');
// Change Subscription
$user->subscribe($myPlan3, 'main'); // will replace myPlan1 subscription
// Renew
$user->subscriptions()->first()->renew();
// Cancel
$user->subscriptions()->first()->cancel();
composer test
Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.
composer rector:test
composer insights
composer csfixer:test
composer phpstan:test
Please see CHANGELOG for more information on what has changed recently.
This package is inspired by Laravel Subscriptions created by Laravel Cameroon and was initially started as a fork of it. After several decisions to go different ways for subscription calculation, it was rewritten from scratch, but still contains several simple methods and other code parts of the original. So if this package doesn't fit your needs, try a look into Laravel Cameroons subscription package.
The MIT License (MIT). Please see License File for more information.