The gform_stripe_charge_pre_create Gravity Forms PHP filter allows the charge properties to be overridden before the charge is created by the Stripe API.
Usage
add_filter('gform_stripe_charge_pre_create', 'your_custom_function', 10, 5);
Parameters
- $charge_meta (array) – The properties for the charge to be created.
- $feed (Feed Object) – The feed object currently being processed.
- $submission_data (Submission Data) – Contains the form title, payment amount, setup fee amount, trial amount, line items created using the submitted pricing field values and any discounts from coupons.
- $form (Form Object) – The Form which is currently being processed.
- $entry (Entry Object) – The entry from which the subscription was created.
More information
See Gravity Forms Docs: gform_stripe_charge_pre_create
Examples
Add the statement_descriptor property
Add the statement_descriptor property to the charge meta. Check Stripe’s documentation for requirements.
add_filter('gform_stripe_charge_pre_create', 'stripe_charge_pre_create', 10, 5); function stripe_charge_pre_create($charge_meta, $feed, $submission_data, $form, $entry) { $charge_meta['statement_descriptor'] = 'STATEMENTDESC'; return $charge_meta; }
Attach payment method to the customer
This example should be used in combination with gform_stripe_customer_id. It shows how you can tell Stripe.com to attach the payment method to the customer for forms using the Stripe Card field.
add_filter('gform_stripe_charge_pre_create', function($charge_meta, $feed, $submission_data, $form, $entry) { $charge_meta['setup_future_usage'] = 'off_session'; return $charge_meta; }, 10, 5);
Add the description property
Add the description property to the charge meta.
add_filter('gform_stripe_charge_pre_create', function($charge_meta, $feed, $submission_data, $form, $entry) { if (empty($charge_meta['description'])) { $charge_meta['description'] = gf_stripe()->get_payment_description($entry, $submission_data, $feed); } return $charge_meta; }, 10, 5);
Override the currency
Override the currency for the charge. This example sets the currency to EUR.
add_filter('gform_stripe_charge_pre_create', function($charge_meta, $feed, $submission_data, $form, $entry) { $charge_meta['currency'] = 'eur'; return $charge_meta; }, 10, 5);
Add metadata to the charge
Add custom metadata to the charge.
add_filter('gform_stripe_charge_pre_create', function($charge_meta, $feed, $submission_data, $form, $entry) { $charge_meta['metadata'] = array( 'custom_key_1' => 'custom_value_1', 'custom_key_2' => 'custom_value_2' ); return $charge_meta; }, 10, 5);