gform_post_payment_action

Description

This action hook can be used to perform custom actions after processing of the following payment events has occurred:

  • complete_payment
  • refund_payment
  • fail_payment
  • add_pending_payment
  • void_authorization
  • create_subscription
  • cancel_subscription
  • expire_subscription
  • add_subscription_payment
  • fail_subscription_payment
  • fail_create_subscription

Usage

This action hook, which would run for all payment add-on feeds, can be used like so:

add_action( 'gform_post_payment_action', 'your_function_name', 10, 2 );

Parameters

  • $entry Entry object
    The entry for which the payment event occurred.
  • $action Array
    An associative array containing the event details.
$action = array(
    'type'             => '',
    'amount'           => '',
    'transaction_type' => '',
    'transaction_id'   => '',
    'subscription_id'  => '',
    'entry_id'         => '',
    'payment_status'   => '',
    'note'             => '',
);

Examples

1. Send event notification

The following example shows how you can trigger the sending of form notifications registered for the event. See the Send Notifications On Payment Events article for a more detailed tutorial.

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 );

2. Access webhook event

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

add_action( 'gform_post_payment_action', 'my_function', 10, 2 );
function my_function( $entry, $action ) {
 
    // If data from the Stripe webhook event is needed (and this hook was initiated via a Stripe webhook request), you can access event data with the following line:
    $event = gf_stripe()->get_webhook_event();
    if ( $event ){
       // Access webhook event data. For event object documentation, see: https://stripe.com/docs/api/events/object
   }

}

Placement

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

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

Source Code

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

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

Since

This filter was added in Gravity Forms 1.9.10.21.