IntroductionRegistering the Add-On EventsTriggering the Sending of the NotificationsGFPaymentAddOnGFFeedAddOnEvents Supported by GFPaymentAddOn
Introduction
Since Gravity Forms 1.9.12, add-ons which extend GFFeedAddOn or GFPaymentAddOn can register custom events for which they will send notifications.
Once the events your add-on supports are registered, the user can then edit their 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.
Registering the Add-On Events
To register the events for which your add-on will trigger the sending of notifications, override supported_notification_events() with an array containing the event keys and labels.
In this example we are registering a number of events which the Stripe Add-On supports, but only if the form has a Stripe feed.
123456789101112131415public function supported_notification_events( $form ) { if ( ! $this->has_feed( $form['id'] ) ) { return false; } return array( 'complete_payment' => esc_html__( 'Payment Completed', 'gravityformsstripe' ), 'refund_payment' => esc_html__( 'Payment Refunded', 'gravityformsstripe' ), 'fail_payment' => esc_html__( 'Payment Failed', 'gravityformsstripe' ), 'create_subscription' => esc_html__( 'Subscription Created', 'gravityformsstripe' ), 'cancel_subscription' => esc_html__( 'Subscription Canceled', 'gravityformsstripe' ), 'add_subscription_payment' => esc_html__( 'Subscription Payment Added', 'gravityformsstripe' ), 'fail_subscription_payment' => esc_html__( 'Subscription Payment Failed', 'gravityformsstripe' ), );}
Triggering the Sending of the Notifications
GFPaymentAddOn
If your add-on extends GFPaymentAddOn and the events are listed under Events supported by GFPaymentAddOn, there』s nothing else to do; the payment framework will handle triggering the notifications when those payment events occur.
If your add-on overrides callback() and specifices a callback parameter in the $action array returned then you would need to trigger the sending of notifications in the function you registered as the callback. You can do that by including the following line in your custom callback:
1$this->post_payment_action( $entry, $action );
GFFeedAddOn
For add-ons which extend GFFeedAddOn you would need to trigger the notifications using the GFAPI::send_notifications method at the appropriate time.
In this example we are triggering notifications for a custom event called feed_processed at the end of the process_feed function.
1234567public function process_feed( $feed, $entry, $form ) { // feed processing code here GFAPI::send_notifications( $form, $entry, 'feed_processed' ); return;}
Events Supported by GFPaymentAddOn
GFPaymentAddOn() will automatically trigger the sending of notifications for the following events:
complete_payment
refund_payment
fail_payment
add_pending_payment
void_authorization
create_subscription
cancel_subscription
expire_subscription
add_subscription_payment
fail_subscription_payment