So Streep has great documentation for how to refund or cancel a payment, and there's a link to this
on the course resources for this lecture, but it's easy enough to find if you scroll on down, it gives
you a simple example in various languages Ruby, Python, Java, Noad.
And of course, we're interested in go for how to do a refund.
And as you can see, it's very little code.
So let's get started.
Let's go over to our editor and I'm looking at the cards Daughton go file in the cards folder in the
internal folder, and I'll go down to the almost the bottom just before the part where we have the error
messages.
And I'll create a new function here and I'll call it func with a receiver, see pointer to card, I'll
call it refund.
And it's going to take two arguments.
Payment intent, which is a string, an amount which is an end, and it will potentially return an error.
Now, as we do every time we're working with strike, we need to set our secret key.
So we just call strike dot key is equal to from the receiver.
See our secret.
Now I want to calculate the amount to refund.
Now that needs to be in an int sixty four.
And of course we're getting it as an input so I'll just create a new variable amount to refund and that
will be assigned a value of sixty four which is the format stripe expects to find it in the amount.
Now I set up some refund parameters refund.
Herranz is a sign the value of and we need a reference to from the strike package dot refund Perens
right there so we'll give it an amount
and that needs to be a reference to amount to refund and we're going to give it a payment intent and
that needs to be a reference to part.
We have our parameters also.
Now we do the refund, now you will get a return value from this, and I'll talk about that in a minute,
I'm going to ignore it because I want to refund the full amount.
So I'm ignoring the first return parameter, but I'm checking for an error, so I call refund dot.
Knew right there, and that might be the right one or this might be the right one.
I can't tell.
So we'll go, I'll choose this one and then check my imports refund.
Otniel and I handed refund Perens.
Now let's go see which one it imported because it might have imported the wrong version.
Go to the top.
And version seventy two, so if you did it and the V seventy two is not there on this line, make sure
you put the V seventy two in there.
Let's go back down and find a refund so we check for an error.
If error is not equal to nil, then return the error, otherwise return nil.
So now we have a method or a function in our cards package that allows us to refund something and all
we have to hand it is the payment intent and the amount we want to refund.
So the next step is to create a handler on our API that actually calls this function and we'll get started
on that in the next lecture.