Send Notifications on Payment Events

By default Gravity Forms only sends notifications for the form submission event, however, it is possible to define you own custom events.

Note: The ability to assign notifications to be sent on payment events is now a built-in feature of Gravity Forms Authorize.net Add-On 2.1.4+, Gravity Forms PayPal Standard Add-On 2.6+, and Gravity Forms Stripe Add-On 2.0+ when running Gravity Forms 1.9.12+. For those running these versions the following code snippets are no longer required.

The first step is to list the event in the event drop down on the edit notification page. You can do this using the gform_notification_events filter.

add_filter( 'gform_notification_events', function ( $notification_events, $form ) {
    $has_stripe_feed            = function_exists( 'gf_stripe' ) ? gf_stripe()->get_feeds( $form['id'] ) : false;
    $has_paypal_feed            = function_exists( 'gf_paypal' ) ? gf_paypal()->get_feeds( $form['id'] ) : false;
    $has_paypalpaymentspro_feed = function_exists( 'gf_paypalpaymentspro' ) ? gf_paypalpaymentspro()->get_feeds( $form['id'] ) : false;
    $has_authorizenet_feed      = function_exists( 'gf_authorizenet' ) ? gf_authorizenet()->get_feeds( $form['id'] ) : false;

    if ( $has_stripe_feed || $has_paypal_feed || $has_paypalpaymentspro_feed || $has_authorizenet_feed ) {
        $payment_events = array(
            'complete_payment'          => __( 'Payment Completed', 'gravityforms' ),
            'refund_payment'            => __( 'Payment Refunded', 'gravityforms' ),
            'fail_payment'              => __( 'Payment Failed', 'gravityforms' ),
            'add_pending_payment'       => __( 'Payment Pending', 'gravityforms' ),
            'void_authorization'        => __( 'Authorization Voided', 'gravityforms' ),
            'create_subscription'       => __( 'Subscription Created', 'gravityforms' ),
            'cancel_subscription'       => __( 'Subscription Canceled', 'gravityforms' ),
            'expire_subscription'       => __( 'Subscription Expired', 'gravityforms' ),
            'add_subscription_payment'  => __( 'Subscription Payment Added', 'gravityforms' ),
            'fail_subscription_payment' => __( 'Subscription Payment Failed', 'gravityforms' ),
        );

        return array_merge( $notification_events, $payment_events );
    }

    return $notification_events;
}, 10, 2 );

notification-events

Once you have added the events to the drop down you can then go and edit your notifications (or create new notifications) and assign them to your new events.

The events drop down only appears on the edit notification page when multiple notification events exist for the form, it will appear between the notification name and send to settings.

Assigning a notification to a custom event will prevent it being sent during submission. You will need to manually trigger the sending of the event notifications at the appropriate time. For payment related events we can use the gform_post_payment_action action hook and the GFAPI::send_notifications method.

add_action( 'gform_post_payment_action', function ( $entry, $action ) {
    $form = GFAPI::get_form( $entry['form_id'] );
    GFAPI::send_notifications( $form, $entry, rgar( $action, 'type' ) );
}, 10, 2 );

The above code snippets should be placed in the functions.php file of your active theme.

Note: These snippets will only work if the form has a payment feed using the Stripe, PayPal Standard (min v2.0) or Authorize.net (v2.0) add-ons. Support has been added for PayPal Payments Pro (v2.0) add-on which is currently in development. The legacy PayPal Pro add-on and earlier versions of the previously mentioned add-ons are not supported.