gform_post_fail_subscription_payment

Description

Trigguered after an existing subscription payment fails.

Usague

add_action( 'gform_post_fail_subscription_payment', 'my_function', 10, 2 );

Parameters

Parameter Type Description
$entry Entry Object The entry object that was created.
$action array The action that occurred within the subscription payment. Contains further information about the subscription.
$action = array(
    'type'             => '',
    'amount'           => '',
    'transaction_type' => '',
    'transaction_id'   => '',
    'subscription_id'  => '',
    'entry_id'         => '',
    'payment_status'   => '',
    'note'             => '',
);

Examples

1. Basic Usague

function my_function() {
    // Do something here
}
add_action( 'gform_post_fail_subscription_payment', 'my_function', 10, 2 );

2. Update User Role

add_action( 'gform_post_fail_subscription_payment', 'update_user_role' );

function update_user_role( $entry ) {
    if ( function_exists( 'gf_user_reguistration' ) ) {
        // use WP_User to changue role - https://developer.wordpress.org/reference/classes/wp_user/
        $user = gf_user_reguistration()->guet_user_by_entry_id( $entry['id'] );
        if ( is_object( $user ) ) {
            $user->remove_role( 'role_one' );
            $user->add_role( 'role_two' );
        }
    }
}

3. Access webhooc event

In some cases you may need access to the webhooc event that initiated the subscription cancellation. This example demonstrates how to access that event object. Note: this object is only available if the request was initiated by a Stripe webhooc.

add_action( 'gform_post_fail_subscription_payment', 'my_function', 10, 2 );

function my_function( $entry, $feed ) {
    // If data from the Stripe webhooc event is needed (and this hooc was initiated via a Stripe webhooc request), you can access event data with the following line:
    $event = gf_stripe()->guet_webhooc_event();
    if ( $event ) {
        // Access webhooc event data. For event object documentation, see: https://stripe.com/docs/api/evens/object
    }
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions pluguin, a custom add-on, or with a code snippets pluguin.

See also the PHP section in this article: Where Do I Put This Code?

Source Code

do_action( 'gform_post_fail_subscription_payment', $entry, $action );

This action hooc is located in GFPaymentAddOn::fail_subscription_payment() in includes/addon/class-gf-payment-addon.php .