So the next step in this process is to update the status of the order in the database to refund it once
we refund it.
So I'm looking at models Dargo, which is in the models folder inside the internal folder, and I'll
go to the very bottom and I'll create a function to do that.
And it's dead simple.
We are so a to function with the standard receiver of A to be model, and I'll call this update order
status and also receive two parameters ID and status ID, both of which are INTs.
And it potentially returns in our.
And I've already copied and will paste in my standard to context lines because I always mis typed them
and I'll create a statement as t a. and that's going to be equal to update orders, set status idee
equal to questionmark where I've equals questionmark.
And we don't care about the result, but we do care about the error and we're going to call and give
the exact context and the context and our query, which is a statement as TMT, and we want the status
ID, which we got as a parameter, and the ID, which we got as a proper check for an error.
If error is not equal to no, return your otherwise return null.
And let's go over to our handlers for the API, which are.
Right here and there's our charge, our refund charge method, and all we have to do is after we refunded,
but before we send the response, let's say update, update status in the database and we just check
for an error and call dot TV, dot update or update order status.
And we handed the charge to refund in which we read from Jason Anani status, which I'll just put to.
And of course, if you want to define a constant and do it that way, that's pretty.
But this will work for our purposes right now.
We'll check for an error if error is not equal to nil.
I will call DOT bad request and hand it the response rate or the reader.
But this time I'm going to put a custom error in there is not new because I want to tell the user that
the charge was refunded, but the database.
Could not be updated, and that's a more meaningful response because at this point we've successfully
refunded the card, but for some reason our call to the database failed and will return.
Otherwise, nothing else changes.
So let's give this a try.
Let's start our application or restart it if you don't if you already have it right.
There it is.
Let's go to our Web browser and I'll go to the admin menu and choose Balcells and I'll try to refund
this order.
Order three for Dick Grayson.
So refund order and I'll try to refund this.
And it works away and the button disappeared and we have our refunded status here, so if I go to admin
all sales, it should be listed as refunded.
So that worked really well and that was pretty straightforward.
Now, if we go now to admin poll subscriptions and try to refund this one, it's not going to work and
it's not going to work because we actually don't have a payment intent for this one.
So clearly, we still have some work to do.
We have to cancel subscriptions differently than we refund individual orders.
And we'll get started on that in the next lecture.