ntech-services / subscription-system
A subscription management system for Laravel applications.
Installs: 40
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ntech-services/subscription-system
Requires
- php: ^8.1
- laravel/framework: ^8.0 || ^9.0 || ^10.0 || ^11.0 || ^12.0
README
A powerful and flexible subscription management system for Laravel applications, designed to handle subscription plans, payments, and user management.
Table of Contents
Requirements
- PHP 8.0 or higher
- Laravel 8.0 or higher
- Composer
Installation
To install the ntech-services/subscription-system package, follow these steps:
-
Install the package via Composer:
Run the following command in your terminal:
composer require ntech-services/subscription-system
- Register Service Provider
After installing the package, you should register the service provider in the bootstrap/providers.php file. Open bootstrap/providers.php and add the following line to the array:
[
App\Providers\AppServiceProvider::class,
NtechServices\SubscriptionSystem\SubscriptionServiceProvider::class, // add this line to providers array
];
-
Publish the package configuration:
Publish the configuration file to customize the package settings.
php artisan vendor:publish --provider="NtechServices\SubscriptionSystem\SubscriptionSystemServiceProvider"
-
Run the migrations:
Migrate the subscription system tables to your database by executing:
php artisan migrate:subscription-system
-
Configure your models:
Add the
HasSubscriptionstrait to your user or model class that will handle subscriptions:
use NtechServices\SubscriptionSystem\Traits\HasSubscriptions;
class User extends Authenticatable
{
use HasSubscriptions;
}
-
Set up your environment variables:
Update your
.envfile with necessary configurations for the subscription system (if applicable).
Configuration
After publishing the configuration file, you can find it at Config/subscription.php. Customize the settings according to your application's requirements.
Usage
Subscribing to a Plan
To subscribe a user to a plan, you can use the subscribeToPlan method provided by the HasSubscriptions trait:
$user = User::find(1);
$planPrice = PlanPrice::find(1); // Retrieve the desired plan
$user->subscribeToPlan($planPrice, $couponCode = null);
Managing Subscriptions
You can manage subscriptions using the available methods in the HasSubscriptions trait:
- Check active subscriptions:
$user->activeSubscriptions() - Cancel subscription:
$subscription->cancelSubscription($softCancel = true) - Update subscription plan:
$subscription->updateSubscription($newPlanPrice)
Subscription History
Subscription status changes are automatically recorded in the subscription history for tracking purposes.
Commands
Migrate Subscription System Tables
To migrate the subscription system tables, you can run the following command:
php artisan migrate:subscription-system
License
This package is licensed under the MIT License. See the LICENSE file for details.