https://github.com/netcore/module-subscription
Subscription plans
https://github.com/netcore/module-subscription
Last synced: 10 days ago
JSON representation
Subscription plans
- Host: GitHub
- URL: https://github.com/netcore/module-subscription
- Owner: netcore
- License: mit
- Created: 2017-11-24T15:18:58.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-07T20:44:09.000Z (about 8 years ago)
- Last Synced: 2025-08-04T05:17:50.388Z (10 months ago)
- Language: PHP
- Size: 67.4 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Description
This module allows you to manage subscription plans and let users to subscribe to plans.
## Pre-installation
**Only use this module if you are using a fully custom payment method. If you use Laravel Cashier, there's support coming for that!**
This package is part of Netcore CMS ecosystem and is only functional in a project that has the following packages
installed:
1. https://github.com/netcore/netcore
2. https://github.com/netcore/module-admin
3. https://github.com/netcore/module-translate
### Installation
* Require this package using composer
```
composer require netcore/module-subscription
```
* Publish configuration/migrations
```
php artisan module:publish-config Subscription
php artisan module:publish-migration Subscription
php artisan migrate
```
* Configure plans and billing periods in `config/netcore/module-subscription.php` file.
* Seed the configuration to database
```
php artisan module:seed Subscription
```
* Add `Modules\Subscription\Traits\Subscribable` trait to your `User` model
### Usage
* Subscribe to a plan with price specification
```
$plan = Modules\Subscription\Models\Plan::where('key', 'premium')->first();
$planPrice = $plan->prices()->inPeriod('monthly')->first();
$user = App\User::first();
$user->subscribe($planPrice, true);
/*
The boolean stands for whether the user has already paid for the subscription or not.
If a boolean is not provided, it'll be automatically set to false.
*/
```
* Get user plan
```
$plan = $user->plan;
```
* Get user subscription
```
$subscription = $user->subscription;
$expirationDate = $subscription->expires_at;
$userHasPaid = $subscription->is_paid;
```
* Cancel subscription
```
$user->cancelSubscription();
```
* Renew subscription
```
$user->renewSubscription(true);
// The boolean stands for whether the user has already paid for the subscription or not
```