Skip to content
This repository has been archived by the owner on Nov 9, 2021. It is now read-only.

Cashierstream is a simple Spark alternative written for Laravel Jetstream, with the super-power of tracking plan quotas, like seats or projects number on a per-plan basis

License

Notifications You must be signed in to change notification settings

renoki-co/jetstream-cashier-billing-portal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

99 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Jetstream Cashier Billing Portal

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Jetstream Cashier Billing Portal is a simple scaffolding billing portal to manage subscriptions, invoices and payment methods, built on top of Jetstream & Cashier Register.

Currently, only Inertia with Stripe are supported. For Paddle and/or Livewire, any PR is welcomed!

example

🀝 Supporting

Renoki Co. on GitHub aims on bringing a lot of open source projects and helpful projects to the world. Developing and maintaining projects everyday is a harsh work and tho, we love it.

If you are using your application in your day-to-day job, on presentation demos, hobby projects or even school projects, spread some kind words about our work or sponsor our work. Kind words will touch our chakras and vibe, while the sponsorships will keep the open source projects alive.

ko-fi

πŸš€ Installation

This package assumes you have installed Jetstream in your project. If not, head over to Jetstream website for installation steps.

Cashier

Make sure to have installed Cashier as explained in the Cashier documentation, including the billable traits and tables, because Jetstream Cashier Billing Portal WILL NOT install them for you.

Scaffolding

You can install the package via composer:

composer require renoki-co/jetstream-cashier-billing-portal

You shall install the Cashier Billing Portal in one command, just like Jetstream. This will install Cashier, Cashier Register and Billing Portal.

$ php artisan billing-portal:install inertia stripe

Stripe Checkout

Starting with Laravel Cashier v12.7.0, you can now use Stripe Checkout for easier implementation. Jetstream Cashier Billing Portal supports this and will send the user directly to the Checkout portal for new subscriptions.

Starting with package version 2.x, you will also need to set up Stripe Webhooks in your own project to benefit from Stripe Checkout, that is used by default. If not, check the 1.x branch or 1.x releases that do not use Stripe Checkout.

The only thing you should do is to add the Stripe Javascript SDK code before the app.js import in your app.blade.php file:

<script src="https://js.stripe.com/v3/"></script>
<script src="{{ mix('js/app.js') }}" defer></script>

Defining Plans

You will also have to prepare the plans in CashierRegisterServiceProvider.

Manual import of the app/Providers/CashierRegisterServiceProvider class is no longe required. The install commandd did that for you.

Below you will find plenty of examples.

πŸ™Œ Usage

In BillingPortalServiceProvider's boot method you may define the plans you need:

use RenokiCo\CashierRegister\BillingPortalServiceProvider as BaseServiceProvider;
use RenokiCo\CashierRegister\Saas;

class BillingPortalServiceProvider extends BaseServiceProvider
{
    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        // Define plans here.
    }
}

By default, the subscriptions are accessible under /billing, but you can change the /billing prefix easily in config/billing-portal.php.

For more information about defining plans and quotas, check Cashier Register documentation and check Laravel Cashier for Stripe documentation on handling the billing.

Custom Billables

By default, the billing is made directly on the currently authenticated model. In some cases like using billable trait on the Team model, you may change the model that will be retrieved from the current request. You may define it in the boot() method of BillingPortalServiceProvider:

use Illuminate\Http\Request;
use RenokiCo\BillingPortal\BillingPortal;

class BillingPortalServiceProvider extends BaseServiceProvider
{
    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        BillingPortal::resolveBillable(function (Request $request) {
            return $request->user()->currentTeam;
        });
    }
}

Modifying the actions

Even if the scaffolding comes with basic controller logic to handle new subscriptions or manage existing ones, you are free to change the Billing Portal's actions in app/Actions/BillingPortal.

You just have to re-write your logic in the action classes.

Proration Between Swaps

By default, Billing Portal prorates the swap between plans. If you wish to not prorate the subscription between swaps, you can specify this in your service provider:

use RenokiCo\BillingPortal\BillingPortal;

class BillingPortalServiceProvider extends BaseServiceProvider
{
    /**
     * Boot the service provider.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        BillingPortal::dontProrateOnSwap();
    }
}

Further reading

Because Jetstream Cashier Billing Portal is written on top of Cashier Register, a complete subscription manager for your Laravel application, you are free to follow the Cashier Register examples in the repository.

You are free to leverage the power of subscriptions in your app. Billing Portal just makes it easier for your app to handle subscriptions.

πŸ› Testing

vendor/bin/phpunit

🀝 Contributing

Please see CONTRIBUTING for details.

πŸ”’ Security

If you discover any security related issues, please email alex@renoki.org instead of using the issue tracker.

πŸŽ‰ Credits