How to automatically cancel Woocommerce order before the payment completes?
On my WordPress / Woocommerce website I sell car history reports which I fetch through an API.
Only after a customer presses the “pay now” button on my website, the API will be called.
Sometimes, however, the API is not able to correctly return the report. In this case, I like to automatically cancel the payment. How do I do this?
The reason I want to do this is so that I don’t have to send a manual refund to the customer later on.
For extra clarity; the flow is as follows:
- Customer presses “pay now” button
- Order status changes to “processing”
- API is called
- correct/incorrect return from the API is received
- IF incorrect return -> completely abort/cancel the order and make sure that the payment doesn’t complete
What function do I need to call to implement this last step? Does Woocommerce offer a function that aborts the payment process?
Thanks in advance.