WEBVTT 00:01.960 --> 00:06.880 So I've managed to subscribe to customer and captured the subscription idea and of course the payment 00:06.880 --> 00:12.420 method idea, and now I need to implement some functionality that will allow me to cancel a subscription. 00:13.120 --> 00:17.320 And if you look at the strike documentation and I'll put a link to this in the course resources for 00:17.320 --> 00:22.270 this lecture, it's pretty straightforward and it's about the same amount of code as it is to refund 00:22.270 --> 00:22.940 a charge. 00:23.890 --> 00:29.920 Now, up here, it says by default, subscriptions and billing continue until cancellation as configured 00:29.920 --> 00:32.020 in your subscription life cycle settings. 00:32.020 --> 00:37.840 And you can go read that a subscription may cancel automatically after up to four unsuccessful attempts 00:37.840 --> 00:38.650 to build a customer. 00:38.680 --> 00:39.460 Well, that's perfect. 00:39.490 --> 00:41.140 That's exactly what I want. 00:41.470 --> 00:44.500 And here is the sample code for how to cancel the subscription. 00:44.530 --> 00:48.800 So let's go back to our editor to Visual Studio Code and open up cards. 00:48.800 --> 00:49.600 Don't go. 00:50.140 --> 00:53.320 And I'll create another method or another function right here. 00:54.250 --> 01:05.110 Func C pointer to card and I'll call this one cancel subscription and it will take a sub ID subscription, 01:05.620 --> 01:06.430 which is a string. 01:06.910 --> 01:12.940 And that's the thing we just added to the database when we insert a transaction and it potentially returns 01:12.940 --> 01:13.360 an error. 01:15.160 --> 01:21.130 And of course I need to do the same thing I do here, Strachey, so I'll just copy that to set our secret 01:21.130 --> 01:21.580 key. 01:21.610 --> 01:22.770 Otherwise, nothing will work. 01:24.760 --> 01:28.750 And now I need to create some parameters which I'll just call her arms. 01:28.930 --> 01:36.190 And that's equal to a reference to Stripe Dot subscription Prem's. 01:38.080 --> 01:48.250 And all I need to put in there is cancel at period end and set that to strike rule. 01:51.370 --> 01:51.720 True. 01:53.590 --> 01:59.950 So the only parameter I'm sending is this person wants to cancel his or her subscription, so don't 01:59.950 --> 02:03.070 renew it, cancel it as soon as their current period ends. 02:03.070 --> 02:04.750 So they're paying me twenty dollars a month. 02:05.080 --> 02:09.250 If the period ends in two weeks, in two weeks their subscription will be cancelled. 02:09.420 --> 02:11.470 OK, so that's pretty simple. 02:11.710 --> 02:16.870 And now I just cancel the subscription, so I'll ignore the first return parameter, but I will check 02:16.870 --> 02:21.430 for an error and I'll call sub dot update. 02:23.450 --> 02:25.020 And hopefully that imported the right version. 02:25.040 --> 02:30.320 I'll check in a moment and I hand it the subscription ID, which I received as a parameter to this function 02:30.740 --> 02:32.270 and the presence that we just created. 02:32.390 --> 02:35.420 And I'll check for an error if error is not equal to nil. 02:39.810 --> 02:45.510 Return the girl, otherwise return them. 02:49.000 --> 02:57.720 OK, so there is any function available to us from our current package and we can use that in a handler 02:57.720 --> 02:59.430 to actually cancel a subscription. 02:59.460 --> 03:01.800 And we'll get started on that in the next lecture.