DEV Community

Laravel Jetstream Subscription Billing With Stripe Checkout and Customer Portal

Chris Earls on December 01, 2020

Update 2/16/21 - This tutorial has been updated to include the recent Stripe Checkout support added to Laravel Cashier. Laravel Jetstream is a gre...
Collapse
 
foxrocks76 profile image
FoxRocks76

Thanks Chris, this was super helpful! The only problem I ran into is that when I changed those migrations, I got an error because the customers table was being created before the teams table, but I was able to fix that by just renaming the migration files so they went in the correct order. Full disclosure: I was doing this on an existing (new) project I started, so I expect I just didn't install Jetstream and Cashier in the same order you did.
Cheers!

Collapse
 
ostap profile image
Ostap Brehin • Edited

In Laravel 11, I believe the middleware config would be in bootstrap/app.php

    ->withMiddleware(function (Middleware $middleware) {
        $middleware->validateCsrfTokens(except: [
            'stripe/webhook',
        ]);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ibourgeois profile image
Derek Bourgeois

You are not importing the Stripe JS library, so this tutorial will result in:

Uncaught ReferenceError: Stripe is not defined
    at billing:408
Enter fullscreen mode Exit fullscreen mode

You can add the following to resources/views/billing.blade.php, above the <script> tag:

<script src="https://js.stripe.com/v3/"></script>
Enter fullscreen mode Exit fullscreen mode
Collapse
 
cearls profile image
Chris Earls • Edited

Good catch! I've added this.

Collapse
 
alexweissman profile image
Alex Weissman

Thanks, this was very helpful! A few notes:

  • When you try to run the Cashier migrations, you will get an error because Cashier tries to create the same sessions table as Jetstream
  • The Stripe event is actually checkout.session.completed
  • I believe the callback at the end of your JS should be handleFetchResult, not handleResult?
Collapse
 
cearls profile image
Chris Earls

Thanks for your feedback, Alex! I have made updates to address the last two notes, but I'm not able to reproduce the sessions table error. 🤔

Collapse
 
websilvercraft profile image
websilvercraft

Nice integration, for added flexibility, I added a way to select between multiple payment providers using service container and contextual binding. However I didn't know about jetstream, seems a nice solution to prevent inventing the wheel.

Collapse
 
grsherwin profile image
grsherwin

Chris, This is a very good article, but I must be missing something. I followed each of your steps and get the page below, but when I click on a button nothing happens. I would have expected it to go to stripe. Do I need to set something else up?

Collapse
 
jamestechdude profile image
James Erikson • Edited

I wanted to add... At least nowadays, when you publish the migrations to switch to team_id for stripe, you will have to also rename your team migrations for jetstream to run first before the stripe migrations do

Also, I wish there was a tutorial for the inertia version of Jetstream as it seems like I can't get this setup completely. I get up to the part and then I'm stuck since the view and navigation dropdown files aren't the same, but I'll format them to what I have

Thank you!

Collapse
 
mckltech profile image
MCKLtech

Is it possible to start a subscription from the billing portal? In other words, the checkout is entirely handled by Stripe in their portal?

Collapse
 
cearls profile image
Chris Earls

No, you can only manage existing subscriptions with the billing portal.

Collapse
 
mckltech profile image
MCKLtech

Interesting! Would be a nice feature for Stripe to add as it would remove the requirement for checkout and decouple billing entirely.

Thank you for the tutorial, very insightful.

Collapse
 
rabol profile image
Steen Rabol

For the installation I think this would work as well:

laravel new cool-project --jet --teams

Collapse
 
cearls profile image
Chris Earls • Edited

Thanks! I've updated the tutorial to use the installer.

Collapse
 
esbenc_volsgaard_4b9903 profile image
Esben C. Volsgaard

Great article! I’m having an issue with the model though… when I define it as the Team model in my .env, it still tries to user the User model and as a result it fails - any tips?

Collapse
 
fabiofolino profile image
fabiofolino

Is it possible to style the buttons? I'm not clear where that code is located.

Collapse
 
draidel profile image
Ariel

Can we handle single parents with this as well? (Not subscriptions)