Well, things are coming along, but we still have some work to do.
I'm looking at the payment succeeded function inside the handlers don't go file, which is in CMD slash
web.
And if we scroll down, the part I want to work on this time is to redirect.
If you recall, after someone's credit card is charged, they're given a receipt page.
But that receipt page is actually a direct result of the post.
And it's good practice to redirect people somewhere else so they can't accidentally post that data twice.
And hence this comment should write the state of the session and then redirect user to a new page.
And that's pretty simple.
So we have a section available to us right now.
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
method put.
And it requires the context which we get from the response writer our context and requires a key and
I'll call it a receipt because it is a receipt and then you pass it whatever data you want.
Now we've put that in the session, but if we tried to compile and run this program right now with no
other changes, this wouldn't work and it wouldn't work because unless you're putting a primitive like
a string or an int in the session, you actually need to register its type.
And that may be unfamiliar to you if you're coming from a language like, say, IP, which is not strongly
typed, but go with a strongly typed language or a statically typed language.
So all we have to do is go over and find Main Dargo right here and right in the main function, right
at the very beginning, we're going to call a built in Parkwood package with the name Ghab, which is
unusual, but that's what it is, encoding ghab.
And we want to register.
And what we're going to register is the type we want.
And what we have is a map string interface.
Now, you can't just do this.
You could if you were registering, say, models, dot user, you would put models, dot user and then
to curly brackets.
But as you can see right here, if I leave it like that, I get an error.
It doesn't know what this is.
The guard register package doesn't or the encoding garb doesn't.
She just have to add a second set of curly braces?
Now, when we run the program that will be registered and we can put the type map string interface into
the session.
So let's go back to handlers.
And what I want to do after I've put that in the session is actually register a page.
So I'm going to cut this entirely.
We want to redirect people to a page, so I'll create the redirect and then I'll set up the route and
the handler for it after the fact.
So I'll call HDB Dot redirect and it requires the response writer and the pointer to the request, the
path you want to go to and I'll just call a receipt and then some status and dot status.
See other is a good one, so we'll use that.
So we're going to redirect people to receive.
Now I'll create the handler for receipt func and it has the receiver of app pointer to application
and I'll call it receipt and it's a handler.
So it requires a response writer and a pointer to a request.
And then I'll paste that code that I just cut out of the other function into this one.
Now, the problem we have here, of course, is that we want this variable data, but we actually don't
have it.
And all we do is pull it out of the session.
So app session
get.
And again, it requires the context, the context and requires the key, which I called receipt right
up there on line one twenty four.
And then I need to cast it to the correct format.
And so it's just dot and then in parentheses I want it to be a map string interface.
And that it will all be put into a data, a variable called data.
So we've grabbed it from the session with passing it to a template which I'll call reseat, which will
make in a minute.
And everything should be good.
But you don't want to leave that data in the session.
So after I get it, I'll simply get rid of it.
I'll pull it out of the session or remove it from the session after session.
Dot remove.
And again, the context, not context.
And I want to remove receipt.
And now it's gone from the session.
So now we need to create a route to the receipt function.
So let's go over to our roots right here.
So I'll duplicate this line just to save some typing and make this a get request.
And we'll call this receipt and we'll go to receipt.
So the last step here, if we go back to our handlers, is to create a page that is called Receipted
Go E-mail.
So our receipt's page, which team up?
Now, we already have one called succeeded page e-mail.
So all I can do is just refactor that by renaming it and we'll call it receipt page dot go to.
So if we did everything right, I should be able to stop my application.
Next up through the screen, make a start.
Everything should compile.
And it did.
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
sure everything is current and will make a user.
So we'll go with Jimmy Olsen.
Jimmy at the Daily Planet, dot com name is Jimmy Olsen, and his credit card numbers are standard for
two and expiries zero one, two, three one four four four.
And we should get our receipt page and it should be done as an HDB redirect.
And it is everything works as expected, so now someone tries to reload this page in our case because
we've removed information from the session, we'll get an error.
But you can do error checking for that, but it definitely will not post the data again.
And that is key.