Home › Forums › Stripe Payments Plugin › I need to hook into the cancel subscription function › Reply To: I need to hook into the cancel subscription function
August 31, 2021 at 10:54 am
#4235
alexanderfoxc
Participant
Hi Jesper.
There are two hooks related to subscription deletion – asp_subscription_ended
and asp_subscription_canceled
. The latter is what you need. Here’s how you can hook to it:
add_action ('asp_subscription_canceled', 'asp_subscription_canceled_handler', 10, 2);
function asp_subscription_canceled_handler ($sub_id, $event_data) {
ASP_Debug_Logger::log(json_encode($event_data));
}
$sub_id
is Stripe’s subscription ID
$event_data
is event data received from Stripe’s hook.
This code dumps event data into plugin’s debug log (if it’s enabled). This way you would be able to see what kind of data is available.
To trigger the event, just create a subscription in test mode and then cancel it using cancel URL.