Python for Entrepreneurs Transcripts
Chapter: Making money (credit cards and businesses)
Lecture: Demo: Checkout skeleton

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So like some of the other demos, there is a lot of moving parts
0:04 but you've seen them over and over and so seeing them one more time
0:07 is just going to slow things down.
0:10 So I did a little bit of pre-work to get the web app ready
0:13 for all this integration that we are going to do.
0:16 First of all, notice, I've created a Stripe checkout settings,
0:19 in our various configuration files, the development.ini and production.ini.
0:24 Now, when you create your Stripe account you are going to see
0:27 we have a public key and a private key.
0:30 The public key actually goes into your webpage, in that JavaScript form.
0:34 Your private key is what you use to finalize the token,
0:37 public key can be public, as you imagine.
0:40 Private keys should never be public. You want to protect those.
0:43 Also, you have two types of keys, you have a public test key,
0:47 you have a test key set of keys and you have a live set of keys.
0:52 So, you want to make sure that the development.ini has the test keys,
0:57 for most of the time, maybe one time you want to switch it to live
1:00 and do a purchase on your own credit card,
1:03 but the majority of the time you want this to be the test keys and then in production,
1:09 over here you want to put your actually live keys.
1:14 It's really nice because they actually have the word "live" or the word "test" in the API keys.
1:19 Next, we want to read these in, so we're doing that in the dunder init,
1:23 down here and I've added an init_credit_cards, so here I have this unset things,
1:28 you can see the warnings, we're just pointing those two keys
1:31 and I created this thing called a CreditCardProcessor
1:34 and we're passing that configuration over here.
1:37 And this thing is going to have a couple of functions about actually doing the purchase,
1:41 finalizing the purchase, reporting certain types of errors, things like that.
1:45 So what we're going to do in part of this demo is
1:49 we are going to write the code that goes here.
1:51 We've also created a few other things, I've created this store service,
1:56 which will actually finalize the purchase in a larger scope,
2:01 it's going to charge the credit card but it also record the purchase in the database
2:05 things like that, so we'll have, it will manage everything that has to be done
2:10 for sort of completing a purchase, recording in our system, record it on Stripe,
2:15 and up here we have somewhere in the database we want to store these purchases
2:20 so once we finalize it was Stripe, we don't want to depend on Stripe any further,
2:24 we want to have a record of the purchase in our database.
2:28 So this is pretty bare minimum, but it will do, we are going to have an id,
2:32 it can be autoincremented numerical, nobody is going to see this,
2:36 we want to know when the purchase was done and we have a default of when we insert it,
2:40 which basically is always correct, we're going to give it a description,
2:45 so we can say like "hey, they bought this album or that album", whatever.
2:50 How much did they pay, maybe they had a discount code,
2:53 if we do that kind of thing like coupon codes,
2:55 we'd want to store that here on the record as well,
2:58 but we're not doing that so we'll just say they paid this amount.
3:01 The price could change at the album over time.
3:03 And then we have just some relationships to say this is the album they bought
3:07 and this is the account or the user who bought it.
3:10 Finally, we have a store service in an album,
3:16 store controller and an album controller
3:20 so up here, we're going to have when we show our albums,
3:23 we're going to want to actually put that buy button next to each album,
3:26 now we don't have an album details page,
3:28 it would probably make much more sense to put the buy button on the details page,
3:32 but for now we are just going to stick it next to the album.
3:37 And once we do, we are going to need to have that post back go somewhere
3:41 so to isolate the credit card processing we have a store controller
3:45 so whenever we purchase something,
3:48 we'll tell that Stripe form to post back to store/complete,
3:52 and this method if things work correctly, we'll send them to success,
3:57 if they fail, well, we'll send them to the failed method here.
4:00 Alright, so that's what we have to build upon,
4:05 let's go and implement these various methods
4:08 and add our Stripe checkout code to the template.