|
/ Documentation /Developer Hooks & Events/Actions/ Handle Custom Stripe Webhook Events

Handle Custom Stripe Webhook Events

Overview

The suredonation_webhook_handle_event filter allows developers to process Stripe webhook events that are not handled by SureDonation’s core plugin.

This filter is executed from the default branch of the Stripe webhook event dispatcher. SureDonation Pro uses it to process subscription-related events such as customer.subscription.created and invoice.payment_succeeded, but you can also use it to handle your own custom Stripe webhook events.

When This Filter Runs

The filter runs whenever SureDonation receives a Stripe webhook event that does not have a native handler.

This allows you to extend SureDonation without modifying the plugin’s core files.

Filter Signature

apply_filters(
    'suredonation_webhook_handle_event',
    null,
    $event_type,
    $event_data,
    $mode
);

Parameters

ParameterTypeDescription
$valuemixedThe current filter result. Starts as null, indicating the event has not yet been handled.
$event_typestringThe Stripe webhook event type.
$event_dataarrayThe Stripe event object data.
$modestringThe Stripe payment mode. Possible values are live and test.

Return Values

This filter uses a short-circuit pattern. Your callback should return one of the following values.

Return ValueDescription
nullIndicates that your callback did not handle the event. SureDonation continues processing normally and acknowledges the webhook to Stripe.
trueIndicates that the event was successfully handled.
WP_Error with code permanent_failure or invalid_eventIndicates an unrecoverable error. SureDonation acknowledges the webhook so Stripe stops retrying the event.
Any other WP_ErrorIndicates a temporary failure. SureDonation returns the error so Stripe retries the webhook according to its retry schedule.

Basic Usage

Register a callback using add_filter().

add_filter( 'suredonation_webhook_handle_event', 'your_custom_function', 10, 4 );

function your_custom_function( $result, $event_type, $event_data, $mode ) {

    // Return null if you do not handle this event.
    return $result;

}

Example

The following example handles the Stripe charge.dispute.created event.

add_filter( 'suredonation_webhook_handle_event', 'mysite_handle_dispute', 10, 4 );

function mysite_handle_dispute( $result, $event_type, $event_data, $mode ) {

    if ( 'charge.dispute.created' === $event_type ) {
        mysite_flag_dispute( $event_data );
        return true;
    }

    return $result;

}

Best Practices

  • Always return the original $result for events that your callback does not handle.
  • Only return true after your custom logic completes successfully.
  • Return an appropriate WP_Error when an error occurs so Stripe can determine whether the webhook should be retried.
  • Avoid modifying or interrupting the processing of unrelated webhook events.
Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top