gform_stripe_charge_authorization_only

Description

The gform_stripe_charge_authorization_only filter allows authorization-only transactions by preventing the capture request from being made after the saved entry. Use this filter when using the Stripe Card Element in your form. If you are using the Stripe Payment Element, use the gform_stripe_payment_element_authorization_only filter instead.

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

Stripe Field with Use Stripe's Payment Element unchecked which enables Stripe's Card Element

Usage

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

add_filter( 'gform_stripe_charge_authorization_only', 'your_function_name', 10, 5 );

Parameters

VariableTypeDescription
$authorization_onlyboolDefaults to false; return true to prevent payment from being captured.
$feedFeed ObjectThe feed object currently being processed.
$submission_dataSubmission DataContains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values, and any discounts from coupons.
$formForm ObjectThe Form which is currently being processed.
$entryEntry ObjectThe entry from which the subscription was created.

Examples

1. Apply to all product and service feeds.

add_filter( 'gform_stripe_charge_authorization_only', '__return_true' );

2. Apply to a specific feed.

The following example shows how you can set the charge to authorize only for a specific feed by checking the feed name.

add_filter( 'gform_stripe_charge_authorization_only', 'stripe_charge_authorization_only', 10, 2 );

function stripe_charge_authorization_only( $authorization_only, $feed ) {
	gf_stripe()->log_debug( __METHOD__ . '(): Running...' );

	$feed_name = rgars( $feed, 'meta/feedName' );

	if ( $feed_name === 'your feed name here' ) {
		gf_stripe()->log_debug( __METHOD__ . '(): Authorization only charge for feed ' . $feed_name );
		return true;
	}

	return $authorization_only;
}

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 2.1.

Source Code

$authorization_only = apply_filters( 'gform_stripe_charge_authorization_only', false, $feed, $submission_data, $form, $entry );

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