Best method to cancel order after refund

I am implementing a method to allow for a customer to cancel an order after the order has already been paid for. I currently am refunding the customer when they request the cancellation. Now I am looking for a way to update the order.state to be set to “CANCELED” after I refund the payments attached to this order.

This is the error response I receive:
{"errors": [{"code": "BAD_REQUEST","detail": "Orders cannot be canceled after payments have been processed.","field": "order.state","category": "INVALID_REQUEST_ERROR"}]}

How can I set the order.state after the refund to “CANCELED”?

Unfortunately, you can’t. You will be unable to cancel it once an order has a payment attached to it; and if it was already marked as COMPLETED you can’t edit the order at all unfortunately. However, if you do do a refund, a new Order object will be created, and will reference the original order as a source_order_id.

So the original order will be left with a state of “OPEN” indefinitely? How will my client’s POS system or online dashboard understand that this order should not be worked on anymore? Also, what are the advantages of creating a new order based on the original order? It seems to make things more complicated.

Is there a guide explaining how to properly handle “cancelling” an order? I was not able to find one on developer.squareup.com.

Technically, yes. But, you can cancel the fulfillment that is within the order, and that would make it be removed from the POS/Dashboard. It’s easier/possible to cancel orders without payments, to be clear.

Another alternative solution would be to use CreatePayment with autocomplete=false which is not a “processed payment”. You would have up to 7 days before it auto-voids, but before then you could mark the fulfillment and order as canceled. Otherwise, call CompletePayment to actually capture the payment.

1 Like

Is there any benefit to having the order have a state of “CANCELED”? My current setup has it simply refunding the payment(s) for an order and then setting the fulfillment state to “CANCELED” which leaves the order having a state of “OPEN”.

I’m also facing this issue. Did you find a way?

I’ve refunded an order (POS), but it is not cancelled. People in order fulfillment will think this order needs to be filled. How do I cancel it? I’ve not found a way through the POS or the API to do this. I’m hoping there is a way to this in both, but at this point, I’d take either.

The hack is to mark it as COMPLETED in the POS. But,
a) shouldn’t that happen automatically?
b) why can’t I do this through the API?

Thanks,
Ryan

As mentioned above, you can cancel the fulfillment via the API, which will remove it from the orders tab on the dashboard and POS application. I’m following up with the orders team to see if they have thoughts about whether it should be canceled or not and will follow up here when I have more info.

They confirmed there’s no great way to do this. You can cancel the fulfillment via the API is pretty much the best way, unfortunately.

For future reference, after canceling the fulfillments, you can then cancel the order. The advantage for me, besides accurate data, is I need to make a query later and it now returns less data that I need to transfer and sort through.