gform_post_add_subscription_payment

Description

Triggered after a payment is made to an existing subscription.

Usage

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

Parameters

  • $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. See below for Array configuration.
$action = array(
	'type'				=> '',
	'amount'			=> '',
	'transaction_type'	=> '',
	'transaction_id'	=> '',
	'subscription_id'	=> '',
	'entry_id'			=> '',
	'payment_status'	=> '',
	'note'				=> '',
);

Examples

1. Basic usage

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

2. Cancel a Stripe subscription after # payments

See the Cancel a Stripe Subscription After a Specified Number of Payments article for an example showing how this hook can be used to cancel a Stripe subscription after a set number of payments have occurred.

3. Access webhook event

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

add_action( 'gform_post_add_subscription_payment', 'my_function', 10, 2 );
function my_function( $entry, $feed ) {
    // 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_add_subscription_payment', $entry, $action );

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