This episode is for members only

Sign up to access "Laravel Subscriptions" right now.

Get started
Already a member? Sign in to continue
Playing
04. Creating and storing plans

Transcript

00:00
So we've spent some time getting everything set up and now we're going to dive straight into creating subscription products on Stripe and going ahead and adding them to some sort of config without application, where we can easily extract information from them, use them to display plans, validate plans, all that good stuff.
00:18
So because we're using Cashier, which works with Stripe, we need a Stripe account. I've gone ahead and created one of them already. I haven't done anything here at all. I'm going to fairly quickly show you around in case you are new, and then we're going to get started with creating plans.
00:36
Okay. So the majority of the time we're going to spend over in this developer section here, make sure that test mode is on. You can't change it unless you complete your business profile. So likely, if you just created one, you're not going to be able to turn this off anyway.
00:52
Let's head over to the developer section where, like I said, we're going to spend most of our time. Okay. So over here, the API keys will show you the keys that you're going to need to interact with Stripe and you'll have a publishable and a secret key. We also have the ability to create webhooks as well, which we're going to do a little bit later.
01:11
What we're interested in right now, though, is just creating a few products and adding them to our backend so we can access them. So we do this over in the product catalog section. Let's go ahead and open that up. And of course I have no products at the moment.
01:26
Let's go ahead and click add product. And we're going to give this an overall name for the thing that we are creating. So we're not going to call this product monthly. We're going to call this product premium or subscription, whatever your offering is called.
01:40
Okay. So we don't really need to fill out a description or upload an image, but we do want to make sure that recurring here is checked. We'll also need to come down and choose an amount which is required. So I'm going to go ahead and choose USD here.
01:54
I'm going to set this to $15 monthly. This is going to be the first price of our product. Okay. Let's go ahead and hit add product and create that out.
02:03
And under premium now we have this price, but we can also add another price to this. So this is where we're going to go ahead and create the yearly or biweekly, whatever pricing strategy you want to use. So let's go ahead and add a new price to this. Again, it's going to be recurring with a flat rate.
02:22
And we're going to change the currency over to USD and we're going to set this at $120. But of course we're going to change this to yearly. Okay. So now that we've done that, we can create this other price and we're done.
02:34
We've got both of our prices under this product. Now, what we're going to need to do here is access the price ID for each of these. This is what we need to pass over to the Stripe API through Laravel Cashier to choose which product the user wants to sign up to. So we're going to go ahead and click on any of these prices and you'll see just up here, this is the price ID.
02:58
And that's going to be exactly the same for the yearly offering as well. Okay. Let's go ahead and figure out now that we've created two prices under a single product, how we're going to store these in our backend. So there's a couple of ways that we can do this.
03:12
We can either do this in the database, or we can do this just within a very simple config file. I found it a lot easier to add these just to a simple config file rather than add them to the database. So we don't need to query for things. We just need to fetch them out of a file, essentially.
03:29
So let's go ahead and create out a new PHP file in here and let's call this subscriptions.php. Okay. Now that we've got this, we can return some config within Laravel and we can add our plans to an overall array. So in here, we're going to choose as the key, the thing that we want this to be called.
03:46
This doesn't matter what we give this name. Okay. So in here, we're going to have several things about this plan over on Stripe or for our own use. So for the name, we are going to call this monthly.
03:59
That's how we want this to be displayed. And then we're going to add the price ID directly from Stripe here. So we're going to do that for both monthly and yearly, or any other plans that you've created. So let's swap this one over to yearly.
04:11
And we'll change this one to yearly as well. And let's go ahead and just grab the price IDs. So if we come back over, let's grab the price ID for monthly and go ahead and add that in. And we'll do the same thing for the yearly plan as well.
04:25
So let's grab this, grab the price ID and go ahead and paste it in there. Okay. So we've gone ahead and created two prices for a product on Stripe. In the next episode, we're going to go ahead and look at creating a pricing page to display these and output some of the details about them.
26 episodes2 hrs 38 mins

Overview

Learn to start accepting subscriptions with Laravel and build a solid foundation for your next application. In fact, it’s exactly how we do things here on Codecourse!

Even if you’re completely new to Laravel, by the end of this course you’ll have a platform where customers can purchase subscriptions and gain access to restricted areas of your application.

We’ll also cover managing subscriptions, cancellations, invoices, giving customers trial periods — and more.

Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!