Download the PHP package creatydev/plans without Composer

On this page you can find all versions of the php package creatydev/plans. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package plans

Build Status codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

PayPal

Laravel Plans

Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.

Laravel Cashier

While Laravel Cashier does this job really well, there are some features that can be useful for SaaS apps:

Installation

Install the package:

If your Laravel version does not support package discovery, add this line in the providers array in your config/app.php file:

Publish the config file & migration files:

Migrate the database:

Add the HasPlans trait to your Eloquent model:

Creating plans

The basic unit of the subscription-like system is a plan. You can create it using Creatydev\Plans\Models\PlanModel or your model, if you have implemented your own.

Features

Each plan has features. They can be either countable, and those are limited or unlimited, or there just to store the information, such a specific permission.

Marking a feature type can be done using:

Note: For unlimited feature, the limit field will be set to any negative value.

To attach features to your plan, you can use the relationship features() and pass as many Creatydev\Plans\Models\PlanFeatureModelinstances as you need:

Later, you can retrieve the permissions directly from the subscription:

Subscribing to plans

Your users can be subscribed to plans for a certain amount of days or until a certain date.

By default, the plan is marked as recurring, so it's eligible to be extended after it expires, if you plan to do so like it's explained in the Recurrency section below.

If you don't want a recurrent subscription, you can pass false as a third argument:

If you plan to subscribe your users until a certain date, you can pass strngs containing a date, a datetime or a Carbon instance.

If your subscription is recurrent, the amount of days for a recurrency cycle is the difference between the expiring date and the current date.

Note: If the user is already subscribed, the subscribeTo() will return false. To avoid this, upgrade or extend the subscription.

Upgrading subscription

Upgrading the current subscription's plan can be done in two ways: it either extends the current subscription with the amount of days passed or creates another one, in extension to this current one.

Either way, you have to pass a boolean as the third parameter. By default, it extends the current subscription.

Just like the subscribe methods, upgrading also support dates as a third parameter if you plan to create a new subscription at the end of the current one.

Passing a fourth parameter is available, if your third parameter is false, and you should pass it if you'd like to mark the new subscription as recurring.

Extending current subscription

Upgrading uses the extension methods, so it uses the same arguments, but you do not pass as the first argument a Plan model:

Extending also works with dates:

Cancelling subscriptions

You can cancel subscriptions. If a subscription is not finished yet (it is not expired), it will be marked as pending cancellation. It will be fully cancelled when the expiration dates passes the current time and is still cancelled.

Consuming countable features

To consume the limit type feature, you have to call the consumeFeature() method within a subscription instance.

To retrieve a subscription instance, you can call activeSubscription() method within the user that implements the trait. As a pre-check, don't forget to call hasActiveSubscription() from the user instance to make sure it is subscribed to it.

The consumeFeature() method will return:

If consumeFeature() meets an unlimited feature, it will consume it and it will also track usage just like a normal record in the database, but will never return false. The remaining will always be -1 for unlimited features.

The revering method for consumeFeature() method is unconsumeFeature(). This works just the same, but in the reverse:

Using the unconsumeFeature() method on unlimited features will also reduce usage, but it will never reach negative values.

Payments

This package works well even without explicitly using payments integrated. This is good, because the features explained before in this documentation works without having to use the integrated payment system. If you have your own payment system, you can use it as you like. Make sure you check the Recurrency section below to see how you can charge your users based on their last subscription and how to handle recurrency, in general.

Configuring Stripe

This package comes with a Stripe Charge feature that helps you charge subscribers at subscribing or on-demand, when handling the Recurrency (explained below).

To keep it as classy as Laravel Cashier, you have to configure your config/services.php file by adding Stripe:

Using Stripe

If you are now pretty familiar with subscribing, extending, upgrading or cancelling subscriptions without actively passing a payment method, there are some additional features that gives you control over payments:

Subscribing with Stripe Charge

To subscribe your users with a Stripe Token, you have to explicitly pass a Stripe Token:

By default, the charging amount are retrieved from the plans table. However, you can change the price mid-process, at your discretion:

The charging price will be $10, no matter what the plan's price is, since we overrode the charging price.

Since charging doesn't work with extendCurrentSubscriptionWith(), extendCurrentSubscriptionUntil(), upgradeupgradeCurrentPlanTo(), and upgradeCurrentPlanToUntil(), using withStripe() will have no effect, unless you tell them to create a new plan, in extension to the current one:

Keep in mind, even like this, the method won't charge your user because the new subscription did not start. Since this new subscription will start after the current subscription ends, you will have to charge it manually as explained below.

Recurrency

This package doesn't support what Cashier supports: Stripe Plans & Stripe Coupons. This package is able to make you the master, without using a third party to handle subscriptions and recurrency. The main advantage is that you can define your own recurrency amount of days, while Stripe is limited to daily, weekly, monthly and yearly.

To handle recurrency, there is a method called renewSubscription that does the job for you. You will have to loop through all your subscribers. Preferably, you should run a cron command that will call the method on each subscriber.

This method will renew (if needed) the subscription for the user.

If you use the integrated Stripe Charge feature, you will have to pass a Stripe Token to charge from that user. Since Stripe Tokens are disposable (one-time use), you will have to manage getting a token from your users.

As always, if the payment was processed, it will fire the Creatydev\Plans\Stripe\ChargeSuccessful event, or if the payment failed, it will fire Creatydev\Plans\Stripe\ChargeFailed event.

Due subscriptions

Subscriptions that are not using the local Stripe Charge feature will never be marked as Due since all of them are paid, by default.

If your app uses your own payment method, you can pass a closure for the following chargeForLastDueSubscription() method that will help you get control over the due subscription:

On failed payment, they are marked as Due. They need to be paid, and each action like subscribing, upgrading or extending will always try to re-pay the subscription by deleting the last one, creating the one intended in one of the actions mentioned and trying to pay it.

To do so, chargeForLastDueSubscription() will help you charge the user for the last, unpaid subscription. You will have to explicitly pass a Stripe Token for this:

For this method, \Creatydev\Plans\Events\Stripe\DueSubscriptionChargeSuccess and \Creatydev\Plans\Events\Stripe\DueSubscriptionChargeFailed are thrown on succesful charge or failed charge.

Model Extends

You can extend Plan models as well

note $table, $fillable, $cast, Relationships will be inherit

PlanModel

PlanFeatureModel

PlanSubscriptionModel

PlanSubscriptionUsageModel

StripteCustomerModel

Events

When using subscription plans, you want to listen for events to automatically run code that might do changes for your app.

Events are easy to use. If you are not familiar, you can check Laravel's Official Documentation on Events.

All you have to do is to implement the following Events in your EventServiceProvider.php file. Each event will have it's own members than can be accessed through the $event variable within the handle() method in your listener.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details


All versions of plans with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version ~5.8.0|~6.0|~6.2.0|^8.22.2|^9.19|^10.0
stripe/stripe-php Version >=12.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package creatydev/plans contains the following files

Loading the files please wait ....