1 00:00:00,510 --> 00:00:05,790 The front end of our application is now taking the Strype token and attempting to send it to our express 2 00:00:05,820 --> 00:00:06,660 API. 3 00:00:06,870 --> 00:00:13,500 However our express API does not yet have a route handler set up to watch for post requests to the route 4 00:00:13,590 --> 00:00:14,860 API slash. 5 00:00:15,090 --> 00:00:18,260 And that's why we get this 404 not found error. 6 00:00:18,360 --> 00:00:22,760 So we're now going to transition over to our backend over to the Express side of the app. 7 00:00:22,920 --> 00:00:28,410 We are going to first create a new route handler for watch to watch two or four post requests to the 8 00:00:28,410 --> 00:00:31,200 API slash Strype route after we do that. 9 00:00:31,200 --> 00:00:36,150 We'll then add in some additional logic to handle all this Strype charging stuff. 10 00:00:36,150 --> 00:00:37,750 So let's get to it. 11 00:00:37,800 --> 00:00:43,870 I'm going to change over to my code editor and remember how we defined routes inside of our application. 12 00:00:44,010 --> 00:00:50,610 We had previously been creating a file inside of our route's directory We had called it all routes and 13 00:00:50,610 --> 00:00:55,250 inside of a year we put a bunch of handlers associated with authentication. 14 00:00:55,260 --> 00:01:01,800 Now when we think about billing not terribly closely related to authentication really billing and authentication 15 00:01:01,830 --> 00:01:03,660 are two separate tasks. 16 00:01:03,660 --> 00:01:09,390 So I'm thinking that maybe we should make a new file to handle all the different billing related handlers 17 00:01:09,450 --> 00:01:10,960 inside of our application. 18 00:01:11,120 --> 00:01:13,460 So let's do that inside the route's directory. 19 00:01:13,470 --> 00:01:17,110 I'm going to make a new file called billing routes. 20 00:01:17,240 --> 00:01:19,090 Yes. 21 00:01:19,320 --> 00:01:24,680 And then inside of here remember the kind of boiler plate that we set up with inside the author house 22 00:01:24,690 --> 00:01:31,020 file we had created an arrow function that gets called with our express app object and then inside of 23 00:01:31,020 --> 00:01:36,520 that function body we set up the different route handlers that we wanted to create then immediately 24 00:01:36,610 --> 00:01:42,850 exported that function and then we made use of it inside of our top level index G-S file. 25 00:01:42,880 --> 00:01:47,770 So we're going to do the exact same thing this time around as well. 26 00:01:47,770 --> 00:01:52,720 So I'm going to change over to the billing round Scott Jacobs file and we will create an arrow function 27 00:01:52,810 --> 00:01:54,790 and immediately export it. 28 00:01:54,820 --> 00:01:55,920 So we'll say module. 29 00:01:56,020 --> 00:02:01,890 Exports equals app like so OK. 30 00:02:01,930 --> 00:02:04,250 That's pretty much it for the set up. 31 00:02:04,260 --> 00:02:08,830 Now we can do some different route handlers inside of here but before we do I want to make sure that 32 00:02:08,830 --> 00:02:14,490 we require this into our index not G-S file and hook it up with our express app object. 33 00:02:14,500 --> 00:02:16,050 So let's do that right now. 34 00:02:16,360 --> 00:02:17,970 I'm going to save this file. 35 00:02:17,980 --> 00:02:24,220 I'll change over to the index file and I'll scroll on down towards the bottom right where we had required 36 00:02:24,220 --> 00:02:31,970 in the previous auth routes helper right underneath that will add in an additional required statement 37 00:02:32,530 --> 00:02:35,600 for routes slash billing routes. 38 00:02:36,410 --> 00:02:40,620 And then we'll pass in the app with a second set of parentheses. 39 00:02:40,700 --> 00:02:46,700 So remember both of these files the author routes and billing routes files they return a function they 40 00:02:46,760 --> 00:02:48,330 export a function. 41 00:02:48,350 --> 00:02:53,480 So this requires statement right here is going to turn into a function which we then immediately call 42 00:02:53,540 --> 00:02:55,570 with the express object. 43 00:02:55,640 --> 00:03:00,160 So having the two sets of parentheses right here completely valid javascript. 44 00:03:00,210 --> 00:03:01,440 OK so this looks good. 45 00:03:01,520 --> 00:03:05,690 Let's save this and change back over to our billing routes file. 46 00:03:05,720 --> 00:03:07,290 So here's billing routes. 47 00:03:07,790 --> 00:03:12,860 So I want to start off by not really thinking about any of the special Strypes stuff or what we're doing 48 00:03:12,860 --> 00:03:13,910 with a token. 49 00:03:13,910 --> 00:03:18,110 I want to just focus on putting together the route handler first. 50 00:03:18,110 --> 00:03:26,030 So for this row handler we want to watch for post requests that are made to the API slash stripe route. 51 00:03:26,030 --> 00:03:34,940 So to set up that row handler will say don't post API slash stripe and then as a second argument we 52 00:03:34,940 --> 00:03:41,630 pass in the response handler where the request handler which is our arrow function that gets called 53 00:03:41,630 --> 00:03:44,890 with the request and rez objects. 54 00:03:45,540 --> 00:03:45,980 OK. 55 00:03:46,010 --> 00:03:47,130 So it's looking pretty good. 56 00:03:47,330 --> 00:03:49,680 We definitely are off to a good start. 57 00:03:49,760 --> 00:03:55,430 So now we've got the row handlers setup and if we ran the front end application and sent off the token 58 00:03:55,430 --> 00:04:00,560 again it would get redirected or I should say redirected but that token would end up inside of this 59 00:04:00,560 --> 00:04:02,580 request handler right here. 60 00:04:02,600 --> 00:04:08,900 So this right here is where we are going to want to put some logic to handle the token somehow reach 61 00:04:08,900 --> 00:04:13,150 out to the Strype API and finalize the actual charge. 62 00:04:13,250 --> 00:04:20,780 And then after we finalize the charge we'll make sure that we update the users number of credits. 63 00:04:20,780 --> 00:04:22,350 Let's take a quick break right now. 64 00:04:22,370 --> 00:04:26,810 When we come back in the next section we're going to start to do the actual Strype integration into 65 00:04:26,810 --> 00:04:30,450 the server side of our application so I'll see you in just a second.