1 00:00:00,490 --> 00:00:01,000 OK. 2 00:00:01,050 --> 00:00:08,310 Right back to it we're still working on our Strype API handler for making a POST request with the token 3 00:00:08,340 --> 00:00:09,870 from the front end. 4 00:00:09,870 --> 00:00:13,860 Now you might be thinking that doing all the striked stuff in here is going to be a bunch of really 5 00:00:13,920 --> 00:00:20,220 nasty looking logic to actually build the credit card or exchange the token for an actual charge with 6 00:00:20,220 --> 00:00:21,250 the stripe API. 7 00:00:21,420 --> 00:00:25,600 But I've got good news is actually way more straightforward than you might think. 8 00:00:25,620 --> 00:00:27,540 So let's see what it actually looks like. 9 00:00:27,830 --> 00:00:33,810 We are going to install an MP module that is specifically for use on the server side of our application 10 00:00:34,050 --> 00:00:36,520 to help us work with the stripe API. 11 00:00:36,810 --> 00:00:41,740 So we've got one stripe module on the front end that's the check out at J.S. library. 12 00:00:41,790 --> 00:00:45,450 That thing is all about just showing a credit card form to our users. 13 00:00:45,450 --> 00:00:50,850 And then on the back end we are going to use a completely separate Strype library that's all about helping 14 00:00:50,850 --> 00:00:56,010 us take the token that we got from the front end and exchanging it for an actual charge to the user's 15 00:00:56,010 --> 00:00:57,090 credit card. 16 00:00:57,090 --> 00:01:01,980 So rather than just installing it and diving right in I think this would be a pretty good place to look 17 00:01:01,980 --> 00:01:06,240 through a little bit of documentation just to get some guidance on exactly how we're going to pull this 18 00:01:06,240 --> 00:01:07,270 off. 19 00:01:07,320 --> 00:01:13,080 So to look at the documentation I'm going to change over to my browser I'm going to open up a new tab 20 00:01:13,260 --> 00:01:18,450 and go to NPM J person NPM J.S. dot com and there we go. 21 00:01:19,650 --> 00:01:27,270 And then once here I'll search for a module called Strype so simply Strype like so we are looking for 22 00:01:27,270 --> 00:01:30,230 the one called Strype API wrapper. 23 00:01:30,300 --> 00:01:35,030 So a click on that and we'll see some documentation around the Strype library. 24 00:01:35,040 --> 00:01:40,110 So this is a library specifically for working inside of node applications. 25 00:01:40,140 --> 00:01:46,170 Now there is a little bit of documentation on this page right here but the full documentation is at 26 00:01:46,170 --> 00:01:49,470 this link right here saying node API docs. 27 00:01:49,500 --> 00:01:54,780 So we're going to go there and we're going to specifically attempt to find some documentation around 28 00:01:54,780 --> 00:01:58,260 charging a user's credit card or debit card. 29 00:01:58,260 --> 00:02:02,700 Now remember what we had said previously about Strype when we were looking out the stripe dashboard 30 00:02:03,120 --> 00:02:07,540 stripe has a tremendous number of products inside of it. 31 00:02:07,590 --> 00:02:11,870 You know they do credit card charges but they do a lot of other stuff as well. 32 00:02:11,910 --> 00:02:17,400 So if you look at the documentation here on the left hand side you'll see all of these different things 33 00:02:17,400 --> 00:02:19,090 going on all these different things. 34 00:02:19,110 --> 00:02:20,730 A lot of stuff is going on. 35 00:02:20,970 --> 00:02:26,250 So we want to look at one very specific area which is the core resources right here. 36 00:02:26,310 --> 00:02:29,890 The charges section you look at. 37 00:02:30,050 --> 00:02:34,020 So if you look at this very closely we want to charge a credit card or debit card. 38 00:02:34,040 --> 00:02:35,030 Yup that's us. 39 00:02:35,030 --> 00:02:41,030 OK we want to create a charge object and that gives us some documentation around the charge object. 40 00:02:41,360 --> 00:02:44,010 Now to be clear this charge object right here. 41 00:02:44,090 --> 00:02:47,580 This is something that is returned to us by the Strype API. 42 00:02:47,750 --> 00:02:52,410 So they're kind of telling us hey when you use this API Here's what you get in response. 43 00:02:52,580 --> 00:02:54,740 And we don't really you know that's kind of jumping the gun here. 44 00:02:54,740 --> 00:02:56,170 We don't even know what to give them. 45 00:02:56,180 --> 00:03:01,730 So to actually figure out what we have to provide to the Strype API in the first place we're going to 46 00:03:01,730 --> 00:03:09,160 scroll down past this and find ways down here create a charge. 47 00:03:09,230 --> 00:03:13,300 And of course you can always just click on the left and Nav. over here too OK. 48 00:03:13,310 --> 00:03:17,700 So this is how we create an urge to me this is how we actually charge a credit card. 49 00:03:18,170 --> 00:03:21,680 And when we charge it we create a charge object. 50 00:03:21,680 --> 00:03:24,480 Now creating the object really straightforward again. 51 00:03:24,560 --> 00:03:28,370 All we really do is essentially this block of code over here. 52 00:03:28,490 --> 00:03:33,770 So we're going to require the Strype library we're going to pass in the secret key. 53 00:03:33,770 --> 00:03:39,830 We then call Strype charges create and pass and configuration to do this to essentially say hey here's 54 00:03:39,830 --> 00:03:43,580 what we're trying to charge the user for and that's pretty much it. 55 00:03:43,610 --> 00:03:47,690 Now one last thing I want to point out in here is that when we create the charge and when we zoom in 56 00:03:47,690 --> 00:03:53,740 on this you can see it very easily when we create the charge. 57 00:03:53,750 --> 00:03:55,340 So here's the charge creation. 58 00:03:55,340 --> 00:04:01,280 One of the properties required is source and that essentially is saying what credit card or what source 59 00:04:01,280 --> 00:04:03,020 of payment we are using. 60 00:04:03,020 --> 00:04:08,160 So this right here is the token that we got back from the check out at J.S. library. 61 00:04:08,300 --> 00:04:09,940 Remember when we put out everything. 62 00:04:09,940 --> 00:04:14,600 Or when we kicked our user into check out G-S or when they put in their credit card information that 63 00:04:14,600 --> 00:04:20,450 returns us kind of like an authorization or something that says you are authorized to charge up to five 64 00:04:20,450 --> 00:04:21,960 dollars on this card. 65 00:04:22,010 --> 00:04:26,140 So we refer to that kind of as like a source of money or a source of credit. 66 00:04:26,360 --> 00:04:31,310 So when you create the actual charge we specify Here's where to pull the money from. 67 00:04:31,890 --> 00:04:32,240 OK. 68 00:04:32,270 --> 00:04:33,580 So that's pretty much it. 69 00:04:34,130 --> 00:04:39,920 Let's install the striped G-S library on the back end after we do so we'll make sure that we pass in 70 00:04:39,920 --> 00:04:43,690 the secret key and then we'll start to set up the charge. 71 00:04:43,730 --> 00:04:47,670 So let's first change over to our terminal or find my running server. 72 00:04:47,690 --> 00:04:48,740 Here it is. 73 00:04:48,740 --> 00:04:54,640 I'm going to kill the running server and then making sure that I'm still inside of the server project 74 00:04:54,680 --> 00:04:58,710 because we want to install this module to the server side of our project. 75 00:04:58,780 --> 00:05:07,750 I would run and install dash dash save and the name The library is simply Strype OK. 76 00:05:07,860 --> 00:05:08,750 So it looks good. 77 00:05:09,000 --> 00:05:11,950 Let's take a quick break and let this install and come back. 78 00:05:11,970 --> 00:05:12,230 OK. 79 00:05:12,240 --> 00:05:12,900 That was fast. 80 00:05:12,900 --> 00:05:14,160 Well regardless. 81 00:05:14,160 --> 00:05:18,410 Let's take a break come back in the next section in where this thing up so I'll see you in just a minute.