Note: Use the gform_stripe_session_data filter instead if using Stripe Checkout.
Description
The gform_stripe_payment_intent_pre_create filter allows for the changing of the payment intent data before creating it.
Note: This filter is applicable only to Products and Services feeds. Subscription feeds do not utilize Payment Intents, so this filter cannot be used. Please use the gform_stripe_subscription_params_pre_update_customer filter to target subscription feeds.
Usage
The hook which would run for all Stripe product and service feeds can be used like so:
add_filter( 'gform_stripe_payment_intent_pre_create', 'your_function_name', 10, 2 );
Parameters
- $data array
The payment intent data.
- $feed Feed Object
The feed object currently being processed.
Examples
1. Add the statement_descriptor property
The following example shows how you can add the statement_descriptor property to the payment intent data.
add_filter( 'gform_stripe_payment_intent_pre_create', 'add_statement_descriptor', 10, 2 );
function add_statement_descriptor( $data, $feed ) {
$data['statement_descriptor'] = 'STATEMENTDESC';
return $data;
}
2. Attach payment method to the customer
The following example shows how you can tell Stripe.com to attach the payment method to the customer for forms using the Stripe Card field.
// This sets setup_future_usage parameter to off_session to save the payment method.
add_filter( 'gform_stripe_payment_intent_pre_create', function( $data, $feed ) {
gf_stripe()->log_debug( __METHOD__ . '(): Adding setup_future_usage for feed ' . rgars( $feed, 'meta/feedName' ) );
$data['setup_future_usage'] = 'off_session';
return $data;
}, 10, 2 );
Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This hook was added in Stripe version 3.5.
Source Code
$data = apply_filters( 'gform_stripe_payment_intent_pre_create', $data, $feed );
This hook is located in GFStripe::create_payment_intent() in class-gf-stripe.php.