1 00:00:01,340 --> 00:00:05,720 We've now got some code inside of here to actually create a charge and build user's credit card. 2 00:00:05,720 --> 00:00:10,380 They're not going to try to test this out manually if we test out manually however I want you to understand 3 00:00:10,380 --> 00:00:12,380 only about the stripe API. 4 00:00:12,380 --> 00:00:15,770 Right now if I go back over to my stripe dashboard here it is right here. 5 00:00:15,770 --> 00:00:19,960 I'm currently operating my stripe account in what is called test mode. 6 00:00:20,150 --> 00:00:24,440 So if you look at the very bottom left hand side you can see something down here that says viewing test 7 00:00:24,440 --> 00:00:29,690 data and you'll see that little toggle around several different locations while your account is in test 8 00:00:29,690 --> 00:00:30,020 mode. 9 00:00:30,020 --> 00:00:33,300 You are not actually working with any real money whatsoever. 10 00:00:33,350 --> 00:00:35,020 And so we can tried to make API requests. 11 00:00:35,030 --> 00:00:41,220 We can pretend that we are building a user's credit card but in the end no money is moving around whatsoever. 12 00:00:41,270 --> 00:00:46,490 It's only once we decide that we want to take our application public deploy it that we will want to 13 00:00:46,490 --> 00:00:52,270 toggle off test mode which is a little bit of involved process involves verifying a banking account. 14 00:00:52,310 --> 00:00:55,850 A couple of other steps which is something we're not going to go through because it really starts to 15 00:00:55,850 --> 00:00:57,980 get into the money side of things. 16 00:00:59,310 --> 00:01:03,230 So how are we going to actually test this out while our stripe account is in the test mode. 17 00:01:03,300 --> 00:01:08,070 Well at a very practical level what we really need to do here is first create a ticket. 18 00:01:08,070 --> 00:01:12,990 We then have to create an order and then we have to try to make a request to this payments and point 19 00:01:14,090 --> 00:01:18,020 but how are we going to make a request this payment end point without a token. 20 00:01:18,020 --> 00:01:23,360 Once again our account is in test mode right now our stripe account is in test mode while our account 21 00:01:23,420 --> 00:01:24,510 is in test mode. 22 00:01:24,590 --> 00:01:29,790 There is a very special token that we can provide that will always succeed with the stripe API. 23 00:01:29,840 --> 00:01:34,850 In other words there's kind of like a secret escape hatch of sorts or a little shortcut a very specific 24 00:01:34,850 --> 00:01:36,050 token that we can provide. 25 00:01:36,110 --> 00:01:38,710 That is always going to lead to a successful charge. 26 00:01:38,900 --> 00:01:43,890 And that is how we can test and make sure that our code here can successfully Bill a credit card. 27 00:01:43,890 --> 00:01:46,090 We'll show you exactly what that token is in a moment. 28 00:01:46,100 --> 00:01:48,320 First let's kind of do a little bit of setup. 29 00:01:48,320 --> 00:01:54,530 We're going to create a ticket we'll create an order and then eventually create a payment over inside 30 00:01:54,530 --> 00:01:57,120 of postman as usual. 31 00:01:57,130 --> 00:01:59,360 I will first make sure that I am signed in. 32 00:01:59,370 --> 00:02:03,490 Yep looks like I am then going to create a new ticket. 33 00:02:03,640 --> 00:02:06,130 The post request to API tickets. 34 00:02:06,140 --> 00:02:06,840 I'll send that off. 35 00:02:07,170 --> 00:02:13,310 There's my I.D. I'm going to copy the I.D. I'll then create an order for this ticket. 36 00:02:13,480 --> 00:02:21,160 So a post request to API orders on enter and my ticket idea right there send that off and here's my 37 00:02:21,160 --> 00:02:27,080 new order and I'm going to take that I.D. And do keep in mind that we now have a 60 second window to 38 00:02:27,080 --> 00:02:28,250 actually purchase this order. 39 00:02:28,250 --> 00:02:31,520 So we do have to write out some code here rather quickly. 40 00:02:31,520 --> 00:02:33,910 Chances are we'll go over that 60 second timer. 41 00:02:34,010 --> 00:02:34,590 No problem. 42 00:02:34,610 --> 00:02:39,170 We can just go through the process of creating another ticket and an order so I can open up a new tab 43 00:02:39,410 --> 00:02:51,660 I can make a post request to HDD P.S. ticketing dot Dev flash API slash payments under headers on entering 44 00:02:51,780 --> 00:02:54,810 content type of application. 45 00:02:54,810 --> 00:02:59,210 Jason her body all enter raw. 46 00:02:59,290 --> 00:03:01,460 I'll make sure Jason is left on the right. 47 00:03:01,550 --> 00:03:11,910 And then remember we are required to provide an order I.D. and that token for the order I.D. I'll paste 48 00:03:11,910 --> 00:03:17,810 in the order I.D. that I just copied a moment ago from our previous request to create the order and 49 00:03:17,810 --> 00:03:25,180 then for the token normally this token value would come from the stripe library running inside of our 50 00:03:25,180 --> 00:03:26,050 browser. 51 00:03:26,050 --> 00:03:30,000 So this would be something that's going to take the user's actual credit card and give us back a token. 52 00:03:30,000 --> 00:03:33,370 But in this case we have not done anything around the browser just yet. 53 00:03:33,460 --> 00:03:35,940 This is where that little shortcut comes into play. 54 00:03:36,100 --> 00:03:37,940 We're going to enter in a very special token here. 55 00:03:37,960 --> 00:03:42,790 That is always going to work 100 percent of the time or stripe accounts that are in the test mode and 56 00:03:42,790 --> 00:03:49,070 it's very special little token is T OK underscore visa. 57 00:03:49,080 --> 00:03:50,600 So again this is always going to work. 58 00:03:50,610 --> 00:03:56,510 We can bill it for just about whatever money we can imagine and the requested always exceed all right 59 00:03:56,510 --> 00:04:02,090 so now we should be able to send this request off and chances are it's been over 60 seconds. 60 00:04:02,120 --> 00:04:06,280 So I suspect that our order has probably expired by this point in time. 61 00:04:06,410 --> 00:04:08,490 We could send the request anyways and see what happens. 62 00:04:08,570 --> 00:04:12,590 And as a matter fact yep it looks like my order has been canceled because I have left that time out 63 00:04:12,590 --> 00:04:14,720 window at 60 seconds right now. 64 00:04:14,760 --> 00:04:18,770 Did you have to very quickly go through the process once again of creating a ticket and then order and 65 00:04:18,770 --> 00:04:19,680 then I'll update the order. 66 00:04:19,690 --> 00:04:29,320 I.D. it's going to make another ticket there's my I.D. I'll then make another order. 67 00:04:29,440 --> 00:04:38,730 I'll take the order I.D. and then provide that to the agents API so now send this off and I get back. 68 00:04:38,730 --> 00:04:44,940 Success true which in theory means that we have now successfully charged some amount of money the stripe 69 00:04:46,010 --> 00:04:51,860 so that means that this call right here worked as expected to actually verify that worked as expected. 70 00:04:51,860 --> 00:04:56,870 We should be able to go over to our stripe dashboard and take a look at all the different charges we 71 00:04:56,870 --> 00:05:01,420 have created over time to back on the stripe dashboard on the left hand side. 72 00:05:01,420 --> 00:05:06,070 I'll go to payments and I should see a payment right there for 15 dollars. 73 00:05:06,100 --> 00:05:06,260 Yeah. 74 00:05:06,370 --> 00:05:10,960 So that's the payment that I just created two seconds ago that deputy means that we were able to create 75 00:05:10,990 --> 00:05:15,720 a charge and Bill some money to our users let's say this looks pretty good. 76 00:05:15,720 --> 00:05:18,090 We've now verified that this works correctly. 77 00:05:18,090 --> 00:05:20,410 Let's also make sure that it works incorrectly as well. 78 00:05:20,410 --> 00:05:23,370 So let's try providing a different token and just see what happens 79 00:05:26,600 --> 00:05:28,540 I will once again create a ticket. 80 00:05:28,540 --> 00:05:29,140 Very quickly 81 00:05:31,930 --> 00:05:40,740 I will create an order out of that ticket here's my order and I'll create a payment using that order 82 00:05:40,740 --> 00:05:45,840 I.D. And this time around rather than using that little fake always works token I'll put in some gibberish 83 00:05:45,840 --> 00:05:52,220 like so so if I now send this off I'll see an error of something went wrong and if I go to my eternal 84 00:05:52,220 --> 00:05:57,380 window running scaffold I should see an error being thrown from the stripe library. 85 00:05:57,530 --> 00:05:57,850 Yep. 86 00:05:57,920 --> 00:06:01,710 Here's the error right here. 87 00:06:01,730 --> 00:06:09,170 Now if you do not see an error right here that is totally ok however we will want to make sure that 88 00:06:09,170 --> 00:06:11,850 we only see an error as a message right here. 89 00:06:11,850 --> 00:06:16,310 And the reason I say that you might not see an error at your terminal is just in case you did not put 90 00:06:16,310 --> 00:06:23,270 a console log into our final version of that era handle handler middleware that we put together okay. 91 00:06:23,310 --> 00:06:24,750 Well I'd say this looks pretty good. 92 00:06:24,750 --> 00:06:26,790 We are now able to build some money to a user. 93 00:06:26,890 --> 00:06:28,840 And we've gone through it with some manual testing. 94 00:06:28,930 --> 00:06:32,670 But we should probably try to add in some kind of automated test as well. 95 00:06:32,670 --> 00:06:34,980 Let's take a look and figure out how we could do that in just a moment.