Skip to main content

Register an add-on handler on the shared Stripe webhook endpoint

Free Intermediate Since v1.0.0

StripeWebhookController is a single shared endpoint at POST /benecaster/v1/stripe-webhook that verifies the Stripe-Signature header once and dispatches to per-event handlers. Add-ons register additional handlers via benecaster_stripe_webhook_handlers rather than introducing a second endpoint. Keys are full Stripe event names; values are callables that receive the \Stripe\Event. Throw to fail the delivery and let Stripe retry; return cleanly to ack. Events with no registered handler are silently acknowledged.

Code

<?php
add_filter( 'benecaster_stripe_webhook_handlers', function ( array $handlers ): array {
    $handlers['customer.subscription.created'] = static function ( \Stripe\Event $event ): void {
        $sub = $event->data->object;
        my_addon_record_subscription( $sub->id, $sub->customer, $sub->status );
    };
    return $handlers;
} );

View on GitHub →

Hooks Used

  • benecaster_stripe_webhook_handlers