Description
When using the Stripe Payment Element payment collection method, this filter can be used to manually set the payment types that will be considered for display in the Stripe Field.
This will override the payment method set within your Stripe Dashboard → Settings → Payment methods. It will force the payment method to be available even if the method is blocked or not enabled, and it will ignore a method even if set to “on” in your Stripe Dashboard. If a method is selected and cannot (or should not) be offered to the customer, the method will not display, or an error will appear. The payment method changes set by this filter will not be reflected in the connected Stripe Dashboard.
For a breakdown of how the various payment method inputs are used by Stripe to determine what is presented to your site visitor, refer to this help guide.
Note:Â The card payment method can’t be disabled. The Stripe Add-On requires the card payment type always to be enabled.
Usage
add_filter( 'gform_stripe_payment_element_payment_methods', function( $payment_methods, $feed, $form )
Example
The following would apply to all forms:
add_filter( 'gform_stripe_payment_element_payment_methods', function( $payment_methods, $feed, $form ) {
return array(
'card',
'us_bank_account',
'ideal',
'link',
);
}, 10, 3 );
Parameters
Parameter | Type | Description |
---|---|---|
$payment_methods | array | An array of payment methods to be whitelisted for possible presentation. Only the payment methods provided in the array will be considered. See notes below. |
$feed | array | The feed that is being processed. |
$form | array | The form which created the entry. |
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
return apply_filters( 'gform_stripe_payment_element_payment_methods', array(), $feed, $form );
This hook is located in GF_Payment_Element_Intent::get_payment_methods() in includes/payment-element/class-gf-payment-element-intent.php.
Notes
Populating the $payment_method parameter
The list of available payment methods and their enumerated codes are contained within this Stripe developer document.
If a method is selected and cannot (or should not) be offered to the customer, the method will not display, or an error will appear.
Sending an empty array will reset the filter, and control will be reverted back to the settings in your Stripe Dashboard.
Interaction With Stripe Dashboard Settings
If used to populate, this filter will override the payment method set within your Stripe Dashboard → Settings → Payment methods. It will force the payment method to be available even if the method is blocked or not enabled, and it will ignore a method that is on. The payment method changes set by this filter will not be reflected in the connected Stripe Dashboard.
Additional Troubleshooting
When using the gform_stripe_payment_element_payment_methods filter, you may receive an error for a specific payment method. This may be because the payment method doesn’t support one or more of the following:
- Subscriptions
- The currency being used
- Manual capture
For example, to use ACH Direct Debit (us_bank_account
), Stripe requires that the merchant be located in the United States and that the currency being charged is USD. To use a European payment method, you would need to be using EUR currency etc.
Check the Stripe documentation for a list of payment methods and what is supported.
Since
Stripe Add-On version 5.0.
Requires Gravity Forms version 2.7+.