WARNING!!! If you are already using v1.x version, please stay on it, v2.x may have some backward incompatibilities...
Billing package for Laravel 5.5+ supporting packages, plans, coupons, addons, payments and subscriptions with multi currencies
The structure is the following:
- Billable - Model that will pay for everything
- Hostable - Model for which can be purchased everything
- Package - Model that can be purchased
- Plan - Model that will sell the Package
- Reference - Can be any model, that will be purchased with Package
- Coupon - Discount, which can be applied on Plan purchase
The concept is the following:
To be able to use this package, firstly you need to add Billable
trait to your billable model and implement Billable
interface (usually it is User model).
Hostable models have to implement Hostable
interface and use Hostable
trait, which will add Purchases relation to model.
All packages have to be extended from PackageModel abstract class.
That's it!
P. S. Everything is overridable from configuration, provided by package
composer require ptuchik/billing
After composer installation, just run php artisan migrate
as usual, to have the additional tables added to your database and publish configurations by executing:
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider" --tag=config
php artisan vendor:publish --provider="Ptuchik\Billing\Providers\BillingServiceProvider" --tag=config
php artisan vendor:publish --provider="Ptuchik\CoreUtilities\Providers\CoreUtilitiesServiceProvider" --tag=config
IMPORTANT! Your billable model has to have the following attributes:
balance
- cast: numericpaymentGateway
- cast: stringpaymentProfiles
- cast: arraycurrency
- cast: stringparams
- cast: array
and isTester()
method, which will indicate if your billable model is tester or customer, to set the correct mode of payment gateway environment. If you don't need testers, you can just create the following method in your billable model:
public function isTester() {
return false;
}
To get the plan details, with trial days calculation and summary (all coupons and available balance discounts applied) for current user on current host, just call:
$plan->prepare($hostable); // Will return plan with all calculations applied for logged in user
To purchase the plan, just call:
$plan->purchase($hostable); // It will do the rest automagically
Coming soon...
- Taylor Otwell for the best framework - Laravel
- Daniel Stainback aka Torann for Currencies
- Spatie for Translatable package
- The League of Extraordinary Packages for Omnipay - multi-gateway payment processing library