Using Gravity Forms ‘gform_stripe_entry_not_found_status_code’ PHP filter

The gform_stripe_entry_not_found_status_code filter in Gravity Forms Stripe Add-On allows you to override the status code for the “entry not found” WP_Error.

Usage

add_filter('gform_stripe_entry_not_found_status_code', 'your_function_name', 10, 3);

Parameters

  • $status_code (int): The status code. Default is 200.
  • $action (array): An associative array containing the event details.
  • $event (Stripe Event Object): The Stripe event object for the webhook which was received.

More information

See Gravity Forms Docs: gform_stripe_entry_not_found_status_code

Examples

Changing the status code

Change the status code for the “entry not found” WP_Error.

add_filter('gform_stripe_entry_not_found_status_code', 'change_status_code', 10, 3);

function change_status_code($status_code, $action, $event) {
    return "205";
}

Set a custom status code based on event type

Set a custom status code depending on the Stripe event type.

add_filter('gform_stripe_entry_not_found_status_code', 'custom_status_code', 10, 3);

function custom_status_code($status_code, $action, $event) {
    if ($event->type == "charge.failed") {
        return "404";
    }
    return "200";
}

Log events with entry not found errors

Log all events that have “entry not found” errors.

add_filter('gform_stripe_entry_not_found_status_code', 'log_entry_not_found_errors', 10, 3);

function log_entry_not_found_errors($status_code, $action, $event) {
    error_log("Entry not found error for event ID: " . $event->id);
    return $status_code;
}

Set different status codes for different actions

Set different status codes depending on the action taken.

add_filter('gform_stripe_entry_not_found_status_code', 'set_status_code_based_on_action', 10, 3);

function set_status_code_based_on_action($status_code, $action, $event) {
    if ($action['type'] == "update") {
        return "204";
    } elseif ($action['type'] == "delete") {
        return "410";
    }
    return $status_code;
}

Set status code based on event metadata

Set a custom status code based on event metadata.

add_filter('gform_stripe_entry_not_found_status_code', 'set_status_code_based_on_metadata', 10, 3);

function set_status_code_based_on_metadata($status_code, $action, $event) {
    if (isset($event->metadata->custom_status_code)) {
        return $event->metadata->custom_status_code;
    }
    return $status_code;
}