Hook into the three buy-up lifecycle actions to drive integrations
Three actions track the lifecycle of a buy-up grant. Normal customer flow: _purchased (subscriber clicks Add to my plan) → _cancelled (subscriber clicks Remove; cancel-at-period-end is set but the grant remains active until the period elapses) → _revoked (the paid period has elapsed, the base subscription was cancelled, or Stripe removed the item out-of-band). A grant can go directly from _purchased to _revoked when the base subscription is terminated mid-period. _revoked deliberately omits the Stripe item id. Idempotency: the listener guards with the row’s status === 'active' check so replayed Stripe webhooks collapse to no-ops.
Code
<?php
// Send a Slack alert when a buy-up grant ends.
add_action( 'benecaster_buyup_revoked', function ( int $user_id, int $buyup_id, int $show_id ): void {
$user = get_userdata( $user_id );
$buyup = $GLOBALS['benecaster_container']->make( \Benecaster\Membership\BuyupRepository::class )->find( $buyup_id );
if ( ! $user || ! $buyup ) {
return;
}
wp_remote_post( 'https://hooks.slack.com/services/XXX/YYY/ZZZ', [
'body' => wp_json_encode( [
'text' => sprintf( '%s lost their %s grant on show %d.', $user->user_login, $buyup['name'], $show_id ),
] ),
] );
}, 10, 3 );