gform_stripe_payment_element_authorization_only

Description

This filter allows authorization-only transactions by preventing the capture request from being made after saving the entry. The payment can be captured later from the entry details page.

This filter acts like gform_stripe_charge_authorization_only, which is used for the Stripe Card Element. Use gform_stripe_payment_element_authorization_only for the Stripe Payment Element.

Note: This filter does not apply to subscriptions because subscriptions require an immediate capture of the initial payment. The filter applies only to Product and Service feeds and should only be used when Use Stripe’s Payment Element is checked within the Stripe Field settings. If you are not using Stripe’s Payment Element, please use the gform_stripe_charge_authorization_only filter instead.

Usage

The hook, which would run for all Stripe product and service feeds, can be used like so:

add_filter( 'gform_stripe_payment_element_authorization_only', 'your_function_name', 10, 3 );

Parameters

ParameterTypeDescription
$resultboolIndicates if the charge should be authorized rather than captured. Default is false.
$formForm ObjectThe form currently being processed.
$feedFeed ObjectThe feed which is currently being processed.

Example

1. Apply to all product and service feeds.

add_filter( 'gform_stripe_payment_element_authorization_only', '__return_true' );

2. Apply to a specific form.

add_filter( 'gform_stripe_payment_element_authorization_only', function ( $result, $form, $feed ) {

    if( $form['id'] === 1 ) {
       return true; // This will enable authorization only.
   }

   return false; // This will automatically try to capture the payment.
}, 10, 3 );

3. Apply to a specific feed.

add_filter( 'gform_stripe_payment_element_authorization_only', 'stripe_charge_authorization_only', 10, 3 );
function stripe_charge_authorization_only( $result, $form, $feed ) {
	gf_stripe()->log_debug( __METHOD__ . '(): Running... ');
	$feed_name  = rgars( $feed, 'meta/feedName' );
	if ( $feed_name == 'your feed name here' ) { // Replace your feed name here with the actual feed name.
		gf_stripe()->log_debug( __METHOD__ . '(): Authorization only charge for feed ' . $feed_name );
		return true;
	}
 
	return $result;
}

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?

Since

This hook was added in Stripe version 5.0.

Source Code

$authorization_only = apply_filters( 'gform_stripe_payment_element_authorization_only', false, $form, $feed );

This hook is located in GFStripe::capture() in class-gf-stripe.php.