The “problem” we have right now is that we’re using stripe checkout with “form completed” notification event but we have the add_filter( ‘gform_stripe_charge_authorization_only’, ‘__return_true’ ) filter enabled. If someone completes the form and submits payment properly all is good! BUT if someone completes the form and then clicks the ‘back’ button in the stripe checkout the notification event will still fire even though the payment wasn’t authorized. And because we have the authorization only event enabled if we switch to the “payment completed” event a notification this will solve the ‘back’ button issue but it will only fire once we manually accept a payment (which we don’t want). So we are really looking for a filter that causes gravity form to send a notification only once stripe authorization event is successful.
This is the code I have written following the documentation.
add_filter( 'gform_notification_events', function ( $notification_events, $form ) {
$has_stripe_feed = function_exists( 'gf_stripe' ) ? gf_stripe()->get_feeds( $form['id'] ) : false;
if ( $has_stripe_feed ) {
$payment_events = array(
'complete_payment' => __( 'Payment Completed', 'gravityforms' ),
'complete_authorization' => __( 'Payment Authorized', '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 );
add_filter( 'gform_stripe_webhook', 'stripe_webhook_custom_action', 10, 2 );
function stripe_webhook_custom_action( $action, $event ) {
$type = rgar( $event, 'type' );
switch ( $type ) {
case 'issuing_authorization.created':
$action['type'] = 'complete_authorization';
break;
}
return $action;
}
add_action( 'gform_post_payment_callback', function ( $entry, $action ) {
$form = GFAPI::get_form( $entry['form_id'] );
GFAPI::send_notifications( $form, $entry, rgar( $action, 'type' ) );
}, 10, 3 );