• This repository has been archived on 30/Apr/2023
  • Stars
    star
    726
  • Rank 62,418 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

⚠️ [ABANDONED] Rinvex Subscribable is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.

Rinvex Subscriptions

⚠️ This package is abandoned and no longer maintained. No replacement package was suggested. ⚠️

👉 If you are interested to step on as the main maintainer of this package, please reach out to me!


Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.

Packagist Scrutinizer Code Quality Travis StyleCI License

Considerations

  • Payments are out of scope for this package.
  • You may want to extend some of the core models, in case you need to override the logic behind some helper methods like renew(), cancel() etc. E.g.: when cancelling a subscription you may want to also cancel the recurring payment attached.

Installation

  1. Install the package via composer:

    composer require rinvex/laravel-subscriptions
  2. Publish resources (migrations and config files):

    php artisan rinvex:publish:subscriptions
  3. Execute migrations via the following command:

    php artisan rinvex:migrate:subscriptions
  4. Done!

Usage

Add Subscriptions to User model

Rinvex Subscriptions has been specially made for Eloquent and simplicity has been taken very serious as in any other Laravel related aspect. To add Subscription functionality to your User model just use the \Rinvex\Subscriptions\Traits\HasPlanSubscriptions trait like this:

namespace App\Models;

use Rinvex\Subscriptions\Traits\HasPlanSubscriptions;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasPlanSubscriptions;
}

That's it, we only have to use that trait in our User model! Now your users may subscribe to plans.

Note: you can use HasPlanSubscriptions trait on any subscriber model, it doesn't have to be the user model, in fact any model will do.

Create a Plan

$plan = app('rinvex.subscriptions.plan')->create([
    'name' => 'Pro',
    'description' => 'Pro plan',
    'price' => 9.99,
    'signup_fee' => 1.99,
    'invoice_period' => 1,
    'invoice_interval' => 'month',
    'trial_period' => 15,
    'trial_interval' => 'day',
    'sort_order' => 1,
    'currency' => 'USD',
]);

// Create multiple plan features at once
$plan->features()->saveMany([
    new PlanFeature(['name' => 'listings', 'value' => 50, 'sort_order' => 1]),
    new PlanFeature(['name' => 'pictures_per_listing', 'value' => 10, 'sort_order' => 5]),
    new PlanFeature(['name' => 'listing_duration_days', 'value' => 30, 'sort_order' => 10, 'resettable_period' => 1, 'resettable_interval' => 'month']),
    new PlanFeature(['name' => 'listing_title_bold', 'value' => 'Y', 'sort_order' => 15])
]);

Get Plan Details

You can query the plan for further details, using the intuitive API as follows:

$plan = app('rinvex.subscriptions.plan')->find(1);

// Get all plan features                
$plan->features;

// Get all plan subscriptions
$plan->planSubscriptions;

// Check if the plan is free
$plan->isFree();

// Check if the plan has trial period
$plan->hasTrial();

// Check if the plan has grace period
$plan->hasGrace();

Both $plan->features and $plan->planSubscriptions are collections, driven from relationships, and thus you can query these relations as any normal Eloquent relationship. E.g. $plan->features()->where('name', 'listing_title_bold')->first().

Get Feature Value

Say you want to show the value of the feature pictures_per_listing from above. You can do so in many ways:

// Use the plan instance to get feature's value
$amountOfPictures = $plan->getFeatureBySlug('pictures_per_listing')->value;

// Query the feature itself directly
$amountOfPictures = app('rinvex.subscriptions.plan_feature')->where('slug', 'pictures_per_listing')->first()->value;

// Get feature value through the subscription instance
$amountOfPictures = app('rinvex.subscriptions.plan_subscription')->find(1)->getFeatureValue('pictures_per_listing');

Create a Subscription

You can subscribe a user to a plan by using the newSubscription() function available in the HasPlanSubscriptions trait. First, retrieve an instance of your subscriber model, which typically will be your user model and an instance of the plan your user is subscribing to. Once you have retrieved the model instance, you may use the newSubscription method to create the model's subscription.

$user = User::find(1);
$plan = app('rinvex.subscriptions.plan')->find(1);

$user->newPlanSubscription('main', $plan);

The first argument passed to newSubscription method should be the title of the subscription. If your application offer a single subscription, you might call this main or primary, while the second argument is the plan instance your user is subscribing to, and there's an optional third parameter to specify custom start date as an instance of Carbon\Carbon (by default if not provided, it will start now).

Change the Plan

You can change subscription plan easily as follows:

$plan = app('rinvex.subscriptions.plan')->find(2);
$subscription = app('rinvex.subscriptions.plan_subscription')->find(1);

// Change subscription plan
$subscription->changePlan($plan);

If both plans (current and new plan) have the same billing frequency (e.g., invoice_period and invoice_interval) the subscription will retain the same billing dates. If the plans don't have the same billing frequency, the subscription will have the new plan billing frequency, starting on the day of the change and the subscription usage data will be cleared. Also if the new plan has a trial period and it's a new subscription, the trial period will be applied.

Feature Options

Plan features are great for fine-tuning subscriptions, you can top-up certain feature for X times of usage, so users may then use it only for that amount. Features also have the ability to be resettable and then it's usage could be expired too. See the following examples:

// Find plan feature
$feature = app('rinvex.subscriptions.plan_feature')->where('name', 'listing_duration_days')->first();

// Get feature reset date
$feature->getResetDate(new \Carbon\Carbon());

Subscription Feature Usage

There's multiple ways to determine the usage and ability of a particular feature in the user subscription, the most common one is canUseFeature:

The canUseFeature method returns true or false depending on multiple factors:

  • Feature is enabled.
  • Feature value isn't 0/false/NULL.
  • Or feature has remaining uses available.
$user->planSubscription('main')->canUseFeature('listings');

Other feature methods on the user subscription instance are:

  • getFeatureUsage: returns how many times the user has used a particular feature.
  • getFeatureRemainings: returns available uses for a particular feature.
  • getFeatureValue: returns the feature value.

All methods share the same signature: e.g. $user->planSubscription('main')->getFeatureUsage('listings');.

Record Feature Usage

In order to effectively use the ability methods you will need to keep track of every usage of each feature (or at least those that require it). You may use the recordFeatureUsage method available through the user subscription() method:

$user->planSubscription('main')->recordFeatureUsage('listings');

The recordFeatureUsage method accept 3 parameters: the first one is the feature's name, the second one is the quantity of uses to add (default is 1), and the third one indicates if the addition should be incremental (default behavior), when disabled the usage will be override by the quantity provided. E.g.:

// Increment by 2
$user->planSubscription('main')->recordFeatureUsage('listings', 2);

// Override with 9
$user->planSubscription('main')->recordFeatureUsage('listings', 9, false);

Reduce Feature Usage

Reducing the feature usage is almost the same as incrementing it. Here we only substract a given quantity (default is 1) to the actual usage:

$user->planSubscription('main')->reduceFeatureUsage('listings', 2);

Clear The Subscription Usage Data

$user->planSubscription('main')->usage()->delete();

Check Subscription Status

For a subscription to be considered active one of the following must be true:

  • Subscription has an active trial.
  • Subscription ends_at is in the future.
$user->subscribedTo($planId);

Alternatively you can use the following methods available in the subscription model:

$user->planSubscription('main')->active();
$user->planSubscription('main')->canceled();
$user->planSubscription('main')->ended();
$user->planSubscription('main')->onTrial();

Canceled subscriptions with an active trial or ends_at in the future are considered active.

Renew a Subscription

To renew a subscription you may use the renew method available in the subscription model. This will set a new ends_at date based on the selected plan and will clear the usage data of the subscription.

$user->planSubscription('main')->renew();

Canceled subscriptions with an ended period can't be renewed.

Cancel a Subscription

To cancel a subscription, simply use the cancel method on the user's subscription:

$user->planSubscription('main')->cancel();

By default the subscription will remain active until the end of the period, you may pass true to end the subscription immediately:

$user->planSubscription('main')->cancel(true);

Scopes

Subscription Model

// Get subscriptions by plan
$subscriptions = app('rinvex.subscriptions.plan_subscription')->byPlanId($plan_id)->get();

// Get bookings of the given user
$user = \App\Models\User::find(1);
$bookingsOfSubscriber = app('rinvex.subscriptions.plan_subscription')->ofSubscriber($user)->get(); 

// Get subscriptions with trial ending in 3 days
$subscriptions = app('rinvex.subscriptions.plan_subscription')->findEndingTrial(3)->get();

// Get subscriptions with ended trial
$subscriptions = app('rinvex.subscriptions.plan_subscription')->findEndedTrial()->get();

// Get subscriptions with period ending in 3 days
$subscriptions = app('rinvex.subscriptions.plan_subscription')->findEndingPeriod(3)->get();

// Get subscriptions with ended period
$subscriptions = app('rinvex.subscriptions.plan_subscription')->findEndedPeriod()->get();

Models

Rinvex Subscriptions uses 4 models:

Rinvex\Subscriptions\Models\Plan;
Rinvex\Subscriptions\Models\PlanFeature;
Rinvex\Subscriptions\Models\PlanSubscription;
Rinvex\Subscriptions\Models\PlanSubscriptionUsage;

Roadmap

Looking for contributors!

The following are a set of limitations to be improved, or feature requests that's looking for contributors to implement, all PRs are welcome 🙂

  • Allow paying for multiple occurrences of the same plan (i.e. monthly plan, user can pay for 6 months of that plan) (#64)
  • Plan prorate fields in database isn't utilized, this should be implemented to consolidate extension dates, and prices (#68)
  • Change features to be in a many-to-many relationship with plans. Multiple plans can have the same feature, and many plans can have many features as well (#101)
  • Plan subscription timezone field in database isn't utilized, this should be implemented to respect timezone on date calculations (i.e. starts_at, ends_at, trial_ends_at) (#78)
  • Separate trial feature from the subscription periods and adjust subscriptions accordingly. Users should be able to have a trial period without having a subscription at all (#67)

Changelog

Refer to the Changelog for a full history of the project.

Support

The following support channels are available at your fingertips:

Contributing & Protocols

Thank you for considering contributing to this project! The contribution guide can be found in CONTRIBUTING.md.

Bug reports, feature requests, and pull requests are very welcome.

Security Vulnerabilities

If you discover a security vulnerability within this project, please send an e-mail to [email protected]. All security vulnerabilities will be promptly addressed.

About Rinvex

Rinvex is a software solutions startup, specialized in integrated enterprise solutions for SMEs established in Alexandria, Egypt since June 2016. We believe that our drive The Value, The Reach, and The Impact is what differentiates us and unleash the endless possibilities of our philosophy through the power of software. We like to call it Innovation At The Speed Of Life. That’s how we do our share of advancing humanity.

License

This software is released under The MIT License (MIT).

(c) 2016-2022 Rinvex LLC, Some rights reserved.

More Repositories

1

countries

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.
PHP
1,640
star
2

laravel-repositories

⚠️ [ABANDONED] Rinvex Repository is a simple, intuitive, and smart implementation of Active Repository with extremely flexible & granular caching system for Laravel, used to abstract the data layer, making applications more flexible to maintain.
PHP
667
star
3

laravel-bookings

⚠️ [ABANDONED] Rinvex Bookable is a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP
458
star
4

laravel-categories

Rinvex Categorizable is a polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.
PHP
454
star
5

laravel-attributes

⚠️ [ABANDONED] Rinvex Attributable is a robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
PHP
434
star
6

laravel-addresses

⚠️ [ABANDONED] Rinvex Addressable is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.
PHP
240
star
7

laravel-statistics

⚠️ [ABANDONED] Rinvex Statistics is a lightweight, yet detailed package for tracking and recording user visits across your Laravel application. With only one simple query per request, important data is being stored, and later a cronjob crush numbers to extract meaningful stories from within the haystack.
PHP
212
star
8

laravel-auth

A powerful authentication, authorization and verification package built on top of Laravel. It provides developers with Role Based Access Control, Two-Factor Authentication, Social Authentication, and much more, compatible Laravel’s standard API and fully featured out of the box.
PHP
132
star
9

laravel-cacheable

⚠️ [ABANDONED] Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
PHP
111
star
10

cortex-classic

Rinvex Cortex is a solid foundation for enterprise solutions, that provides a flexible and extensible architecture for building multi-lingual, multi-tenant applications with content management, themeable views, application modules and much more.
PHP
94
star
11

laravel-tenants-classic

Rinvex Tenantable is a contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others.
PHP
82
star
12

laravel-support

Rinvex common support helpers, contracts, and traits required by various Rinvex packages. Validator functionality, and basic controller included out-of-the-box.
PHP
73
star
13

universities

Rinvex University is a simple and lightweight package for retrieving university details with flexibility. A whole bunch of data including name, country, state, email, website, telephone, address, and much more attributes for the 17k+ known universities worldwide at your fingertips.
PHP
57
star
14

obsolete-larapulse

⚠️ [ABANDONED] This project is abandoned and no longer maintained. The author suggests following https://twitter.com/LaravelLog on twitter for @laravelphp framework specific changes instead.
PHP
41
star
15

laravel-widgets

⚠️ [ABANDONED] Rinvex Widgets is a powerful and easy to use widget system, that combines the both power of code logic and the flexibility of template views. You can create asynchronous widgets, reloadable widgets, and use the console generator to auto generate your widgets, all out of the box.
PHP
40
star
16

laravel-pages

Rinvex Pages is an integral part of your content management system (CMS), it affords an easy, yet powerful way to create and manage pages with full control over their URLs, active status, titles, content, and other attributes.
PHP
38
star
17

authy

Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
PHP
36
star
18

laravel-authy

Rinvex Authy is a simple wrapper for @Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.
PHP
35
star
19

laravel-contacts

⚠️ [ABANDONED] Rinvex Contacts is a polymorphic Laravel package, for contact management system. You can add contacts to any eloquent model with ease.
PHP
30
star
20

laravel-menus

Rinvex Menus is a simple menu builder package for Laravel, that supports hierarchical structure, ordering, and styling with full flexibility using presenters for easy styling and custom structure of menu rendering.
PHP
30
star
21

languages

Rinvex Language is a simple and lightweight package for retrieving language details with flexibility. A whole bunch of data including name, native, iso codes, language family, language script, language cultures, and other attributes for the 180+ known languages worldwide at your fingertips.
PHP
29
star
22

laravel-tags

Rinvex Taggable is a polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.
PHP
27
star
23

laravel-forms

⚠️ [ABANDONED] Rinvex Forms is a dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease.
PHP
15
star
24

punnet

Rinvex Punnet is opinionated, lightweight, yet powerful, and performant light speed docker environment for PHP applications.
Shell
14
star
25

laravel-testimonials

⚠️ [ABANDONED] Rinvex Testimonials is a Laravel package for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype!
PHP
13
star
26

cortex-auth-classic

Cortex Fort is a frontend layer for the powerful authentication, authorization and verification package rinvex/fort on top of Laravel. It has all required controllers, views, routes, and other required assets to run a fully functional user management system with complete dashboard out of the box.
PHP
12
star
27

cortex-tenants-classic

Cortex Tenantable is a frontend layer for the contextually intelligent polymorphic Laravel package, for single db multi-tenancy. You can completely isolate tenants data with ease using the same database, with full power and control over what data to be centrally shared, and what to be tenant related and therefore isolated from others
Blade
12
star
28

laravel-composer

Rinvex Composer is an intuitive package that utilizes Composer Plugin API to support additional actions during installation, such as installing packages outside of the default vendor library and running custom scripts during install, update, and uninstall processes.
PHP
11
star
29

cortex-attributes-classic

Cortex Attributable is a frontend layer for the robust, intelligent, and integrated Entity-Attribute-Value model (EAV) implementation for Laravel Eloquent, with powerful underlying for managing entity attributes implicitly as relations with ease. It utilizes the power of Laravel Eloquent, with smooth and seamless integration.
PHP
9
star
30

cortex-bookings-classic

Cortex Bookings is a front layer of a generic resource booking system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
PHP
8
star
31

cortex-categories-classic

Cortex Categorizable is a frontend layer for the polymorphic Laravel package, for category management. You can categorize any eloquent model with ease, and utilize the power of Nested Sets, and the awesomeness of Sluggable, and Translatable models out of the box.
PHP
8
star
32

cortex-foundation-classic

The core foundation of Rinvex Cortex modular application architecture.
PHP
7
star
33

cortex-tags-classic

Cortex Taggable is a frontend layer for the polymorphic Laravel package, for tag management. You can tag any eloquent model with ease, and utilize the awesomeness of Sluggable, and Translatable models out of the box.
PHP
6
star
34

cortex-statistics-classic

Cortex Statistics is a frontend layer for lightweight, yet detailed package for tracking and recording user visits across your Laravel application. With only one simple query per request, important data is being stored, and later a cronjob crush numbers to extract meaningful stories from within the haystack.
PHP
6
star
35

cloudinit

Shell
5
star
36

cortex-pages-classic

Cortex Pages is a frontend layer for an integral part of your Laravel content management system (CMS), it affords an easy, yet powerful way to create and manage pages with full control over their URLs, active status, titles, content, and other attributes.
PHP
5
star
37

laravel-oauth

Rinvex OAuth is an OAuth2 server and API authentication package that is simple and enjoyable to use.
PHP
4
star
38

cortex-oauth-classic

Cortex OAuth is a frontend layer for the OAuth server Laravel package, for API management.
PHP
2
star
39

cortex-contacts-classic

Cortex Contacts is a frontend layer for the polymorphic contact management system. You can add contacts to any eloquent model with ease.
PHP
2
star
40

renamed-country

⚠️ This package is renamed and now maintained at https://github.com/rinvex/countries, author suggests using the new package instead.
PHP
2
star
41

cortex-settings-tenantable-classic

Cortex Settings Tenantable is a new module for rinvex/cortex applications.
PHP
1
star
42

cortex-installer

⚠️ [ABANDONED] Rinvex Cortex Installer is a command line tool that depends on composer to install the Cortex projects seamlessly.
PHP
1
star
43

cortex-console-classic

Cortex Console is a set of powerful tools for administrators and system support staff, to maintain the project through a web console.
PHP
1
star
44

cortex-forms-classic

Cortex Forms is a frontend layer for dynamic form builder for Laravel, it's like the missing gem, the possibilities of using it are endless! With flexible API and powerful features you can build almost every kind of complex form with ease.
PHP
1
star
45

cortex-testimonials-classic

Cortex Testimonials is a frontend layer for managing testimonials. Customers can give you testimonials, and you can approve or disapprove each individually. Testimonials are good for showing the passion and love your service gets from customers, encouraging others to join the hype!
PHP
1
star