WEBVTT 00:01.320 --> 00:03.520 Well, things are coming along, but we still have some work to do. 00:03.670 --> 00:10.070 I'm looking at the payment succeeded function inside the handlers don't go file, which is in CMD slash 00:10.180 --> 00:10.520 web. 00:11.100 --> 00:15.150 And if we scroll down, the part I want to work on this time is to redirect. 00:16.260 --> 00:22.290 If you recall, after someone's credit card is charged, they're given a receipt page. 00:22.320 --> 00:25.770 But that receipt page is actually a direct result of the post. 00:25.770 --> 00:31.110 And it's good practice to redirect people somewhere else so they can't accidentally post that data twice. 00:31.110 --> 00:35.790 And hence this comment should write the state of the session and then redirect user to a new page. 00:35.910 --> 00:36.820 And that's pretty simple. 00:37.410 --> 00:39.330 So we have a section available to us right now. 00:39.870 --> 00:47.940 And all I'm going to do is write up a session because we added it to our app config and I'll call the 00:47.940 --> 00:48.540 method put. 00:49.590 --> 00:57.150 And it requires the context which we get from the response writer our context and requires a key and 00:57.150 --> 01:01.560 I'll call it a receipt because it is a receipt and then you pass it whatever data you want. 01:02.610 --> 01:08.010 Now we've put that in the session, but if we tried to compile and run this program right now with no 01:08.010 --> 01:13.530 other changes, this wouldn't work and it wouldn't work because unless you're putting a primitive like 01:13.530 --> 01:17.340 a string or an int in the session, you actually need to register its type. 01:17.340 --> 01:22.770 And that may be unfamiliar to you if you're coming from a language like, say, IP, which is not strongly 01:22.770 --> 01:27.050 typed, but go with a strongly typed language or a statically typed language. 01:27.330 --> 01:35.100 So all we have to do is go over and find Main Dargo right here and right in the main function, right 01:35.100 --> 01:40.470 at the very beginning, we're going to call a built in Parkwood package with the name Ghab, which is 01:40.470 --> 01:42.870 unusual, but that's what it is, encoding ghab. 01:43.350 --> 01:44.640 And we want to register. 01:45.330 --> 01:47.490 And what we're going to register is the type we want. 01:47.490 --> 01:52.450 And what we have is a map string interface. 01:53.310 --> 01:54.720 Now, you can't just do this. 01:54.720 --> 02:00.780 You could if you were registering, say, models, dot user, you would put models, dot user and then 02:00.780 --> 02:01.710 to curly brackets. 02:01.720 --> 02:05.280 But as you can see right here, if I leave it like that, I get an error. 02:05.520 --> 02:06.900 It doesn't know what this is. 02:06.900 --> 02:10.200 The guard register package doesn't or the encoding garb doesn't. 02:10.410 --> 02:13.150 She just have to add a second set of curly braces? 02:13.800 --> 02:20.460 Now, when we run the program that will be registered and we can put the type map string interface into 02:20.460 --> 02:20.970 the session. 02:21.090 --> 02:22.200 So let's go back to handlers. 02:24.040 --> 02:28.590 And what I want to do after I've put that in the session is actually register a page. 02:28.590 --> 02:30.480 So I'm going to cut this entirely. 02:30.810 --> 02:36.060 We want to redirect people to a page, so I'll create the redirect and then I'll set up the route and 02:36.060 --> 02:37.680 the handler for it after the fact. 02:38.130 --> 02:46.290 So I'll call HDB Dot redirect and it requires the response writer and the pointer to the request, the 02:46.290 --> 02:53.670 path you want to go to and I'll just call a receipt and then some status and dot status. 02:53.670 --> 02:56.100 See other is a good one, so we'll use that. 02:56.510 --> 02:58.130 So we're going to redirect people to receive. 02:58.770 --> 03:06.840 Now I'll create the handler for receipt func and it has the receiver of app pointer to application 03:10.020 --> 03:13.110 and I'll call it receipt and it's a handler. 03:13.110 --> 03:19.110 So it requires a response writer and a pointer to a request. 03:24.720 --> 03:29.670 And then I'll paste that code that I just cut out of the other function into this one. 03:30.270 --> 03:34.650 Now, the problem we have here, of course, is that we want this variable data, but we actually don't 03:34.650 --> 03:34.980 have it. 03:34.980 --> 03:36.530 And all we do is pull it out of the session. 03:36.930 --> 03:38.580 So app session 03:41.520 --> 03:41.930 get. 03:42.570 --> 03:50.730 And again, it requires the context, the context and requires the key, which I called receipt right 03:50.730 --> 03:52.200 up there on line one twenty four. 03:53.610 --> 03:56.600 And then I need to cast it to the correct format. 03:56.610 --> 04:03.630 And so it's just dot and then in parentheses I want it to be a map string interface. 04:05.540 --> 04:10.080 And that it will all be put into a data, a variable called data. 04:11.240 --> 04:16.250 So we've grabbed it from the session with passing it to a template which I'll call reseat, which will 04:16.250 --> 04:16.910 make in a minute. 04:17.690 --> 04:18.860 And everything should be good. 04:19.050 --> 04:21.460 But you don't want to leave that data in the session. 04:21.470 --> 04:23.410 So after I get it, I'll simply get rid of it. 04:23.420 --> 04:27.380 I'll pull it out of the session or remove it from the session after session. 04:28.100 --> 04:28.950 Dot remove. 04:29.630 --> 04:31.940 And again, the context, not context. 04:33.320 --> 04:35.120 And I want to remove receipt. 04:35.450 --> 04:36.830 And now it's gone from the session. 04:39.590 --> 04:42.900 So now we need to create a route to the receipt function. 04:42.940 --> 04:44.980 So let's go over to our roots right here. 04:46.190 --> 04:51.020 So I'll duplicate this line just to save some typing and make this a get request. 04:52.880 --> 04:57.530 And we'll call this receipt and we'll go to receipt. 05:00.590 --> 05:07.070 So the last step here, if we go back to our handlers, is to create a page that is called Receipted 05:07.070 --> 05:07.880 Go E-mail. 05:08.450 --> 05:10.840 So our receipt's page, which team up? 05:10.850 --> 05:14.380 Now, we already have one called succeeded page e-mail. 05:14.480 --> 05:23.420 So all I can do is just refactor that by renaming it and we'll call it receipt page dot go to. 05:25.430 --> 05:28.550 So if we did everything right, I should be able to stop my application. 05:28.670 --> 05:32.570 Next up through the screen, make a start. 05:33.230 --> 05:34.550 Everything should compile. 05:36.580 --> 05:37.220 And it did. 05:38.410 --> 05:45.520 So let's go back to our Web browser and try it out so we go back to products by one widget just to make 05:45.520 --> 05:48.650 sure everything is current and will make a user. 05:48.670 --> 05:51.910 So we'll go with Jimmy Olsen. 05:53.080 --> 06:03.970 Jimmy at the Daily Planet, dot com name is Jimmy Olsen, and his credit card numbers are standard for 06:03.970 --> 06:10.210 two and expiries zero one, two, three one four four four. 06:10.660 --> 06:14.830 And we should get our receipt page and it should be done as an HDB redirect. 06:18.200 --> 06:25.400 And it is everything works as expected, so now someone tries to reload this page in our case because 06:25.400 --> 06:27.770 we've removed information from the session, we'll get an error. 06:27.770 --> 06:32.350 But you can do error checking for that, but it definitely will not post the data again. 06:32.360 --> 06:33.770 And that is key.