Skip to main content

Track the payment-failed license grace lifecycle

Free Intermediate Since v1.0.0

Consume all three payment-failed grace lifecycle actions to maintain per-site grace state for admin dashboards, external monitoring, customer-facing emails, and Analytics Dashboard rollup segmentation.

benecaster_license_grace_started fires once when the first payment fails (opening the 30-day window). benecaster_license_grace_expired fires on every subsequent cron cycle once the deadline passes — guard against re-alerting. benecaster_license_grace_recovered fires once when billing is updated and the license returns to valid. By the time recovery fires, subscriber tokens are already unflagged and private feeds are live.

Only payment_failed opens a grace window. cancelled and license_not_found do not fire _started.

Code

<?php
add_action( 'benecaster_license_grace_started', function ( int $started_at, string $reason ): void {
    // Payment just failed. Enqueue a "billing update needed" email to the
    // site operator, or push an event to your monitoring pipeline.
    wp_mail( get_option( 'admin_email' ), 'Benecaster: payment failed', sprintf(
        'Your Benecaster subscription just failed a payment (%s). You have 30 days to update billing at benecaster.com before subscribers drop to the public feed.',
        $reason
    ) );
}, 10, 2 );

add_action( 'benecaster_license_grace_expired', function ( int $started_at ): void {
    // 30 days elapsed — subscribers are now on the public feed. Fires
    // once per cron cycle; guard with a wp_option if you only want the
    // FIRST expiry to trigger an alert.
    if ( ! get_option( 'my_addon_grace_expiry_alerted' ) ) {
        update_option( 'my_addon_grace_expiry_alerted', 1 );
        // ... send the "subscribers now on public feed" alert ...
    }
} );

add_action( 'benecaster_license_grace_recovered', function ( int $started_at, int $duration_seconds ): void {
    // Payment recovered. Clear any expiry-side state and, if grace ran
    // long enough that expired fired, notify recovery.
    delete_option( 'my_addon_grace_expiry_alerted' );
    if ( $duration_seconds >= 30 * DAY_IN_SECONDS ) {
        // ... send "your subscribers have their private feeds back" alert ...
    }
}, 10, 2 );

View on GitHub →

Hooks Used