WEBVTT 00:01.590 --> 00:08.040 So the next step in this process is to update the status of the order in the database to refund it once 00:08.040 --> 00:08.790 we refund it. 00:09.240 --> 00:13.920 So I'm looking at models Dargo, which is in the models folder inside the internal folder, and I'll 00:13.920 --> 00:17.040 go to the very bottom and I'll create a function to do that. 00:17.050 --> 00:18.210 And it's dead simple. 00:20.950 --> 00:30.300 We are so a to function with the standard receiver of A to be model, and I'll call this update order 00:30.480 --> 00:38.820 status and also receive two parameters ID and status ID, both of which are INTs. 00:39.270 --> 00:40.710 And it potentially returns in our. 00:42.760 --> 00:48.400 And I've already copied and will paste in my standard to context lines because I always mis typed them 00:48.790 --> 00:57.980 and I'll create a statement as t a. and that's going to be equal to update orders, set status idee 00:58.000 --> 01:00.850 equal to questionmark where I've equals questionmark. 01:02.830 --> 01:07.840 And we don't care about the result, but we do care about the error and we're going to call and give 01:07.840 --> 01:16.900 the exact context and the context and our query, which is a statement as TMT, and we want the status 01:16.900 --> 01:21.220 ID, which we got as a parameter, and the ID, which we got as a proper check for an error. 01:21.850 --> 01:28.510 If error is not equal to no, return your otherwise return null. 01:30.250 --> 01:34.210 And let's go over to our handlers for the API, which are. 01:36.320 --> 01:44.260 Right here and there's our charge, our refund charge method, and all we have to do is after we refunded, 01:44.270 --> 01:53.900 but before we send the response, let's say update, update status in the database and we just check 01:53.900 --> 01:59.960 for an error and call dot TV, dot update or update order status. 02:00.290 --> 02:07.880 And we handed the charge to refund in which we read from Jason Anani status, which I'll just put to. 02:07.890 --> 02:11.570 And of course, if you want to define a constant and do it that way, that's pretty. 02:11.690 --> 02:13.470 But this will work for our purposes right now. 02:13.520 --> 02:16.400 We'll check for an error if error is not equal to nil. 02:17.030 --> 02:24.050 I will call DOT bad request and hand it the response rate or the reader. 02:24.200 --> 02:30.770 But this time I'm going to put a custom error in there is not new because I want to tell the user that 02:30.770 --> 02:36.320 the charge was refunded, but the database. 02:40.720 --> 02:47.530 Could not be updated, and that's a more meaningful response because at this point we've successfully 02:47.530 --> 02:52.210 refunded the card, but for some reason our call to the database failed and will return. 02:52.300 --> 02:53.780 Otherwise, nothing else changes. 02:54.010 --> 02:55.070 So let's give this a try. 02:55.870 --> 02:59.950 Let's start our application or restart it if you don't if you already have it right. 03:01.880 --> 03:02.520 There it is. 03:02.570 --> 03:10.700 Let's go to our Web browser and I'll go to the admin menu and choose Balcells and I'll try to refund 03:10.700 --> 03:11.630 this order. 03:12.080 --> 03:14.210 Order three for Dick Grayson. 03:15.290 --> 03:18.590 So refund order and I'll try to refund this. 03:20.210 --> 03:26.960 And it works away and the button disappeared and we have our refunded status here, so if I go to admin 03:27.680 --> 03:31.390 all sales, it should be listed as refunded. 03:31.460 --> 03:33.680 So that worked really well and that was pretty straightforward. 03:34.560 --> 03:43.860 Now, if we go now to admin poll subscriptions and try to refund this one, it's not going to work and 03:43.860 --> 03:47.840 it's not going to work because we actually don't have a payment intent for this one. 03:48.540 --> 03:50.310 So clearly, we still have some work to do. 03:50.430 --> 03:55.470 We have to cancel subscriptions differently than we refund individual orders. 03:55.740 --> 03:58.230 And we'll get started on that in the next lecture.