In the WooCommerce admin, there is the cancel subscription option. I am able to hook into this to trap when a subscription has been cancelled. However, I would prefer if I check the gateway and cancel the subscription on the gateway before it is cancelled in WooCommerce.
It needs to be
- User/Admin selects "Cancel Subscription"
- API request goes to the gateway to give a success/fail response.
- On success, WooCommerce cancels the subscription.
In the current setup where it hooks in after the subscription is cancelled there is the possibility of the API call failing. The subscription appearing cancelled to the user while at the gateway it may continue to process the payment.
I found the post status hook change will trigger before the subscription has changed, but I am unable to stop further processing on failure without a die().
Does anyone know the best way to handle this situation?