1 00:00:00,670 --> 00:00:04,120 In the last section we use the Strype library to create a new charge. 2 00:00:04,120 --> 00:00:09,960 Remember this will make a request over to the Strype API and tell it hey we want to finalize this transaction 3 00:00:09,970 --> 00:00:14,250 we want to build a customer for 500 cents. 4 00:00:14,250 --> 00:00:19,620 Now if you look carefully back at the documentation that we were looking at just a second ago you could 5 00:00:19,620 --> 00:00:25,620 see right here there was a second argument of a callback function that we could pass into this Create 6 00:00:25,620 --> 00:00:26,310 call. 7 00:00:26,640 --> 00:00:32,010 So any time we reach out to another API Strype included Remember it's always a synchronous. 8 00:00:32,070 --> 00:00:38,190 And so we have to deal with it either by using a callback function by using a promise or by using that 9 00:00:38,280 --> 00:00:40,550 async await syntax. 10 00:00:40,620 --> 00:00:45,780 So the documentation right here is clearly kind of pointing you towards using a callback function which 11 00:00:45,780 --> 00:00:53,370 we could definitely do but if we go and look out the API documentation that we saw on NPM around Strype. 12 00:00:53,370 --> 00:00:55,830 So here's A.I.M. we looked at this just a little bit ago. 13 00:00:55,930 --> 00:00:57,160 The Strype library. 14 00:00:57,330 --> 00:01:03,540 If you scroll down here a little bit you'll notice that right here it says using promises. 15 00:01:03,600 --> 00:01:09,750 Every method returns a chain will provenance that can be used instead of a regular callback. 16 00:01:10,020 --> 00:01:16,680 So for us we can use promises but remember we have already spoken about the async 08 syntax which we 17 00:01:16,680 --> 00:01:21,250 can use in any place inside of our application that is using promises. 18 00:01:21,480 --> 00:01:27,240 So because the Strype library returns a promise any time you create a charge like what we're doing right 19 00:01:27,240 --> 00:01:33,260 now the returns of promise and to handle that promise we will use the async await syntax. 20 00:01:33,570 --> 00:01:34,770 So let's give it a shot. 21 00:01:36,120 --> 00:01:39,230 So the Create call right here is what returns a promise. 22 00:01:39,270 --> 00:01:44,010 So let's keep that in mind as we do this little rock factor or I should say as we add in the syncopate 23 00:01:44,010 --> 00:01:45,050 syntax at all. 24 00:01:45,330 --> 00:01:50,520 So the first thing we're going to do is find a function that has some asynchronous requestion side of 25 00:01:50,520 --> 00:01:51,080 it. 26 00:01:51,330 --> 00:01:54,090 That's definitely the request handler right here. 27 00:01:54,150 --> 00:02:01,860 So in front of that function that contains the asynchronous logic we will mark it with a keyword async. 28 00:02:01,950 --> 00:02:04,440 Next we'll find the call that returns a promise. 29 00:02:04,440 --> 00:02:07,320 Like I said it's this Create call right here. 30 00:02:07,560 --> 00:02:13,410 We'll put the a weight keyword in front that and then whatever this promise resolves with we are going 31 00:02:13,410 --> 00:02:19,620 to pass off to a new variable in this case oh we call it charge because that's what it really returns 32 00:02:19,620 --> 00:02:23,840 or returns an object that represents the charge that just occurred. 33 00:02:24,450 --> 00:02:24,820 Okay. 34 00:02:24,870 --> 00:02:25,860 So this is looking good. 35 00:02:25,860 --> 00:02:28,950 Now the very last thing I want to do what's canceling out that church. 36 00:02:28,980 --> 00:02:33,630 We'll see what we're working with now and we'll get a better sense of what to do after we successfully 37 00:02:33,630 --> 00:02:35,320 build the user. 38 00:02:35,370 --> 00:02:39,840 So I'm going to go back to my counsel and make sure I don't have any heirs over here outside of those 39 00:02:40,320 --> 00:02:42,690 really really really annoying deprecation warnings. 40 00:02:42,690 --> 00:02:44,310 I know they are annoying. 41 00:02:44,310 --> 00:02:49,200 Hopefully by the time you're watching this mongoose has this stuff all fixed up but as I'm ready right 42 00:02:49,200 --> 00:02:51,740 now obviously it's not fixed. 43 00:02:51,750 --> 00:02:52,030 OK. 44 00:02:52,050 --> 00:02:53,630 We'll go back over to our browser. 45 00:02:53,820 --> 00:02:58,260 We're going to Smithey credit card charge again and we'll see what happens. 46 00:02:58,390 --> 00:03:09,810 And to clear up my request log on bring up my credit card form put in our fake e-mail for two for two. 47 00:03:09,810 --> 00:03:13,560 And then the other stuff OK. 48 00:03:13,630 --> 00:03:16,880 So this is definitely going to make the request off to our API. 49 00:03:17,020 --> 00:03:20,820 Yes the request is still pending because we're not actually dealing with it appropriately. 50 00:03:21,190 --> 00:03:28,150 But if we go over to our terminal we should now see a big huge object that describes the charge that 51 00:03:28,150 --> 00:03:29,680 was just created. 52 00:03:29,680 --> 00:03:30,150 Here we go. 53 00:03:30,220 --> 00:03:30,460 OK. 54 00:03:30,460 --> 00:03:31,660 So here's the idea. 55 00:03:31,660 --> 00:03:36,830 Notice how the idea starts off with the C.H. That's short for as you might guess charge. 56 00:03:36,830 --> 00:03:39,010 So we're dealing with a charged object. 57 00:03:39,010 --> 00:03:43,620 We build them for five hundred cents and somewhere else in here is going to be currency. 58 00:03:43,660 --> 00:03:44,770 Actually here it is right here. 59 00:03:44,950 --> 00:03:46,100 U.S. dollars. 60 00:03:46,150 --> 00:03:47,230 We got that description. 61 00:03:47,230 --> 00:03:49,880 We got some transaction ID. 62 00:03:50,020 --> 00:03:55,350 We got basically just a whole lot of information about the charge that was just created. 63 00:03:55,950 --> 00:03:57,510 And that's pretty much it. 64 00:03:57,660 --> 00:03:58,130 Cool. 65 00:03:58,150 --> 00:04:00,940 So we're definitely making that charge successfully. 66 00:04:00,970 --> 00:04:05,110 That is pretty much all we really have to do as far as Strype is concerned. 67 00:04:05,110 --> 00:04:06,850 So we take Check out Jay. 68 00:04:06,860 --> 00:04:07,440 Yes. 69 00:04:07,570 --> 00:04:12,160 We received some information that identifies the user's credit card that they just entered. 70 00:04:12,160 --> 00:04:15,300 That essentially authorizes us to bill a certain amount of money. 71 00:04:15,550 --> 00:04:21,690 We then post it to the back end where we use the Strype module to create the actual charge and build 72 00:04:21,690 --> 00:04:23,190 the user. 73 00:04:23,200 --> 00:04:23,450 OK. 74 00:04:23,470 --> 00:04:25,270 So let's take a break right here. 75 00:04:25,390 --> 00:04:30,610 When we come back now that we are actually billing the user for some amount of money we'll talk about 76 00:04:30,820 --> 00:04:31,790 what we want to do. 77 00:04:31,900 --> 00:04:36,610 So remember we want to like a sign these are some amount of credits We'll talk about exactly how we 78 00:04:36,610 --> 00:04:37,520 will take care of that. 79 00:04:37,720 --> 00:04:39,630 So I'll see you in just a minute.