Users want to be able to choose how often they pay. This video shows how to set up the page to let a user select monthly or yearly.
- [Instructor] It's time now to actually start - [Instructor] It's time now to actually start writing some code. writing some code. And let's start first with our join page. And let's start first with our join page. If we go back to our website If we go back to our website and we click on the premium tab, and we click on the premium tab, we have this awesome page where it says we have this awesome page where it says hey, you can either join monthly or yearly. hey, you can either join monthly or yearly. We have a nice little shout out showing We have a nice little shout out showing how you save $20 bucks a year by doing the yearly. how you save $20 bucks a year by doing the yearly. But both of these buttons right now are not going anywhere. But both of these buttons right now are not going anywhere. And we want to talk about the whole flow of our project And we want to talk about the whole flow of our project and where we want things to go. and where we want things to go. So let's go ahead and move over into our project. So let's go ahead and move over into our project. To get you a little bit familiar with what we have, To get you a little bit familiar with what we have, it's called Nick Fitness.
it's called Nick Fitness. And we have an app called Plans. And we have an app called Plans. So inside of the Plans app if we go to our models. So inside of the Plans app if we go to our models. You can see the big object that we have here You can see the big object that we have here is the fitness plan. is the fitness plan. So fitness plan has a title, it has text, So fitness plan has a title, it has text, and it has a premium Boolean, meaning does this require and it has a premium Boolean, meaning does this require a premium account to be able to access it, right? a premium account to be able to access it, right? That's what we're trying to sell people. That's what we're trying to sell people. So this is what sort of everything is based off of. So this is what sort of everything is based off of. If you go ahead and check out our views.py If you go ahead and check out our views.py you can see that we have a function for our plans you can see that we have a function for our plans that simply just say okay, if someone wants that simply just say okay, if someone wants the following plan, check and see if it's premium.
the following plan, check and see if it's premium. Currently we're just saying if it's premium Currently we're just saying if it's premium we're just going to redirect 'em to the join page. we're just going to redirect 'em to the join page. If not then we'll actually show them the plan, right. If not then we'll actually show them the plan, right. That first plan we were able to see that. That first plan we were able to see that. And then we have some other pages here And then we have some other pages here but right now they're just returning back templates but right now they're just returning back templates that already exist. that already exist. So let's go ahead and check out the join template. So let's go ahead and check out the join template. And move into templates, plans. And move into templates, plans. And we'll go to our join.html. And we'll go to our join.html. And currently our two buttons here, our HREFS are blank. And currently our two buttons here, our HREFS are blank. So we need to talk about where it is So we need to talk about where it is that we want to send our user.
that we want to send our user. Well we want to send them to the checkout page. Well we want to send them to the checkout page. So let's go ahead and add in the appropriate tag for that. So let's go ahead and add in the appropriate tag for that. We'll say we want the URL We'll say we want the URL that's called checkout and that's a URL that's called checkout and that's a URL if you go to our URLS.py you can go see that. if you go to our URLS.py you can go see that. But along with this not only do we want to send them But along with this not only do we want to send them to the checkout but we want to specify to the checkout but we want to specify did they select a monthly or a yearly plan? did they select a monthly or a yearly plan? So for this button up here, if we look at this So for this button up here, if we look at this this is our $10 monthly plan. this is our $10 monthly plan.
So we're going to add on to the end of this URL So we're going to add on to the end of this URL a question mark and then we're going to say plan a question mark and then we're going to say plan is equal to and we'll have that be monthly. is equal to and we'll have that be monthly. So we're going to copy the code that we have here So we're going to copy the code that we have here for this HREF, come down and paste it below for this HREF, come down and paste it below and change this from monthly to yearly. and change this from monthly to yearly. And with this in place, go ahead and save this. And with this in place, go ahead and save this. We'll come back to our join page here. We'll come back to our join page here. We'll reload, let's click on the Get Started button. We'll reload, let's click on the Get Started button. Look at that, it takes us our checkout with monthly. Look at that, it takes us our checkout with monthly.
And if we go back and hit the yearly And if we go back and hit the yearly it'll take us there with yearly in place. it'll take us there with yearly in place. Now with that underway, let's go ahead and start prepping Now with that underway, let's go ahead and start prepping for our next phase of the site here. for our next phase of the site here. And that's that whenever somebody wants to buy And that's that whenever somebody wants to buy a premium subscription, we have to make a customer a premium subscription, we have to make a customer account for them. account for them. And this is different from our user object. And this is different from our user object. So let's go ahead and go to our models.py So let's go ahead and go to our models.py and now create a new class. and now create a new class. So the class that we're going to be creating is customer. So the class that we're going to be creating is customer. And customer is going to come from models, capital Model.
And customer is going to come from models, capital Model. And the different properties here are first we should have And the different properties here are first we should have the user, this is what's going to connect them the user, this is what's going to connect them to the user object. to the user object. And we'll say models dot and we want capital One to One And we'll say models dot and we want capital One to One capital Field and inside of here we'll pass in capital Field and inside of here we'll pass in capital User comma and then our on delete. capital User comma and then our on delete. We'll have this be equal to We'll have this be equal to models and then all caps Cascade. models and then all caps Cascade.
Great. Great. Our next step is we want to add a stripe ID. Our next step is we want to add a stripe ID. And stripe ID is going to be models.Charfield. And stripe ID is going to be models.Charfield. In fact we can copy this from up above. In fact we can copy this from up above. Got our models.charfield here. Got our models.charfield here. Let's have that be 255. Let's have that be 255. Next we want to have a stripe_subscription Next we want to have a stripe_subscription _ID. _ID. We're going to have that also be equal to a Charfield.
We're going to have that also be equal to a Charfield. Next we need cancel Next we need cancel _at _at _period _period _end. _end. This is saying whether or not they want This is saying whether or not they want to cancel their subscription. We'll use this in a little bit, We'll use this in a little bit, and this is going to be a Boolean field. and this is going to be a Boolean field. So let's go ahead and copy this, paste. So let's go ahead and copy this, paste. 1 Although we want to default here to be equal to false. Although we want to default here to be equal to false. 1 And finally, we're going to have a membership. And finally, we're going to have a membership. 1 And a membership's also going to be a Boolean. And a membership's also going to be a Boolean. 1 So we're going to say membership is equal to.
So we're going to say membership is equal to. 1 We'll go ahead and paste that in again. We'll go ahead and paste that in again. 1 Let's set this equal to default. Let's set this equal to default. 1 This is going to say whether or not they have a membership. This is going to say whether or not they have a membership. 1 So with this all in place remember any time So with this all in place remember any time 1 you add a new model, we've got to let the database you add a new model, we've got to let the database 1 know about it so we're going to quit our server. know about it so we're going to quit our server. 1 Then we're going to remove our database completely. Then we're going to remove our database completely. 1 So we'll go ahead and remove that. So we'll go ahead and remove that. 1 Then we're going to say Python manage.py Then we're going to say Python manage.py 1 make migrations. make migrations. 1 And you can see it made a new migration for us.
And you can see it made a new migration for us. 1 Next step for us is we want to do the migrate. Next step for us is we want to do the migrate. 1 After the migration is complete let's go ahead and load After the migration is complete let's go ahead and load 1 our data like we've done before. our data like we've done before. 1 And after we've done that, all we have to do And after we've done that, all we have to do 1 is re-run our server. is re-run our server. 1 Great. Great. 1 We are in an awesome position to now move on We are in an awesome position to now move on 1 to the checkout page. to the checkout page.
Released
3/1/2019- Using APIs
- Leveraging the Stripe dashboard
- Building a checkout page
- Configuring payment periods
- Working with the Stripe frontend
- Handling data
- Implementing a coupon system
- Processing payments
- Analyzing Stripe data
- Creating user models
- Allowing for subscription cancellations
Share this video
Embed this video
Video: Select yearly or monthly