Download the PHP package smartech/subscriptions without Composer
On this page you can find all versions of the php package smartech/subscriptions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smartech/subscriptions
More information about smartech/subscriptions
Files in smartech/subscriptions
Package subscriptions
Short Description Manage users subscriptions for Laravel/Lumen apps
License MIT
Homepage https://smartech.online/
Informations about the package subscriptions
Smartech Subscriptions
Manage user subscriptions for Laravel/Lumen apps
Requirements
php
>= 5.6.6laravel/laravel
>= 5. orlaravel/lumen
>= 5.
Installation
Laravel Installation
1) Install package using composer.
2) Add package service provider (< laravel 5.5).
3) Publishing the configuration file (Optional).
4) Migrate tables.
Lumen Installation
1) Install package using composer.
2) Add package service provider in bootstrap/app.php
.
3) Publishing the configuration file (Optional)
-
Copy the config file:
vendor/smartech/subscriptions/config/subscriptions.php
to the application config directory. - Setting Lumen to parse the configuration file.
4) Migrate tables.
Configuration
use the HasSubscription
trait with the User
model.
Usage
Subscribe to a plan
- To subscribe to a plan, you must either specify the pricing or request a trial period (if the plan supports requesting a trial period)
- Setting the pricing by defining the period and its price for each plan, and each plan can have multiple pricings (monthly, yearly or others).
Subscribe to a a plan with trial period
- If the requested plan supports requesting a trial period, the following code will subscribe the user to this plan with the period defined for each plan in the plans table.
setPricing
should not be called here as trial period is always free.
Change the subscription plan
- Changing the plan will set a new plan to the user and set a new period (
started_at
,ended_at
) based on the pricing ID.
Renew the subscription
- Renewing the subscription will only set a new period (
started_at
,ended_at
) based on the current pricing ID.
Cancel the subscription
- Canceling the subscription will set the
canceled_at
field -
By default, the subscription will still valid until the end of the current period.
- If we want to cancel the subscription immediately, just call
$user->subscription->cancel(true)
.
Activate/Deactivate the subscription
- Activating/Deactivating the subscription will set the
is_active
field.
Models
Subscription Model
Plan Modal
User Model
Get user subscription
check if user has specific plan
check if user has specific feature
Extending Models
All models are binded into IOC and listed in config/subscription.php
.
As example, we want to extend the Plan
model.
-
Edit
config/subscription.php
and set themodels.plan
to have the new plan model class\App\Models\Plan::class
. -
define the new class extends the parent plan class
- Now you can call it from
app("subscriptions.models.plan")
or from\App\Models\Plan
.