WEBVTT 00:01.080 --> 00:06.750 So Streep has great documentation for how to refund or cancel a payment, and there's a link to this 00:06.750 --> 00:12.510 on the course resources for this lecture, but it's easy enough to find if you scroll on down, it gives 00:12.510 --> 00:17.700 you a simple example in various languages Ruby, Python, Java, Noad. 00:17.700 --> 00:20.690 And of course, we're interested in go for how to do a refund. 00:20.700 --> 00:22.610 And as you can see, it's very little code. 00:22.620 --> 00:23.500 So let's get started. 00:23.550 --> 00:30.900 Let's go over to our editor and I'm looking at the cards Daughton go file in the cards folder in the 00:30.900 --> 00:35.580 internal folder, and I'll go down to the almost the bottom just before the part where we have the error 00:35.580 --> 00:36.150 messages. 00:36.390 --> 00:44.310 And I'll create a new function here and I'll call it func with a receiver, see pointer to card, I'll 00:44.310 --> 00:44.970 call it refund. 00:45.450 --> 00:46.770 And it's going to take two arguments. 00:46.890 --> 00:53.440 Payment intent, which is a string, an amount which is an end, and it will potentially return an error. 00:54.540 --> 00:58.560 Now, as we do every time we're working with strike, we need to set our secret key. 00:58.710 --> 01:03.230 So we just call strike dot key is equal to from the receiver. 01:03.240 --> 01:04.500 See our secret. 01:06.150 --> 01:08.990 Now I want to calculate the amount to refund. 01:09.120 --> 01:12.510 Now that needs to be in an int sixty four. 01:12.510 --> 01:18.690 And of course we're getting it as an input so I'll just create a new variable amount to refund and that 01:18.690 --> 01:25.740 will be assigned a value of sixty four which is the format stripe expects to find it in the amount. 01:27.510 --> 01:30.390 Now I set up some refund parameters refund. 01:31.890 --> 01:40.890 Herranz is a sign the value of and we need a reference to from the strike package dot refund Perens 01:41.700 --> 01:45.900 right there so we'll give it an amount 01:48.720 --> 01:58.020 and that needs to be a reference to amount to refund and we're going to give it a payment intent and 01:58.020 --> 02:00.290 that needs to be a reference to part. 02:01.410 --> 02:02.660 We have our parameters also. 02:04.690 --> 02:10.170 Now we do the refund, now you will get a return value from this, and I'll talk about that in a minute, 02:10.180 --> 02:12.550 I'm going to ignore it because I want to refund the full amount. 02:15.660 --> 02:22.110 So I'm ignoring the first return parameter, but I'm checking for an error, so I call refund dot. 02:23.050 --> 02:28.130 Knew right there, and that might be the right one or this might be the right one. 02:28.150 --> 02:28.760 I can't tell. 02:28.780 --> 02:32.920 So we'll go, I'll choose this one and then check my imports refund. 02:32.930 --> 02:35.680 Otniel and I handed refund Perens. 02:37.990 --> 02:41.370 Now let's go see which one it imported because it might have imported the wrong version. 02:42.310 --> 02:43.060 Go to the top. 02:44.470 --> 02:49.780 And version seventy two, so if you did it and the V seventy two is not there on this line, make sure 02:49.780 --> 02:51.100 you put the V seventy two in there. 02:51.850 --> 02:54.700 Let's go back down and find a refund so we check for an error. 02:56.290 --> 03:01.960 If error is not equal to nil, then return the error, otherwise return nil. 03:03.190 --> 03:09.410 So now we have a method or a function in our cards package that allows us to refund something and all 03:09.430 --> 03:12.730 we have to hand it is the payment intent and the amount we want to refund. 03:13.450 --> 03:19.090 So the next step is to create a handler on our API that actually calls this function and we'll get started 03:19.090 --> 03:20.500 on that in the next lecture.