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

Talk Python's Mastodon Michael Kennedy's Mastodon