Description
Allow manual setting of the payment methods used by Stripe Checkout.
When using the Stripe Payment Form (Stripe Checkout) payment collection method, this filter can manually set the payment types that will be considered for display in the Stripe Checkout Stripe Payment Form.
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.
Usage
add_filter( 'gform_stripe_checkout_payment_methods', 'your_function_name', 10, 3);
Parameters
Parameter | Type | Description |
---|---|---|
$payment_methods | array | An array of payment methods. These will be white-listed to be presented according to the payment method presentation rules. |
$feed | Feed Object | The feed being processed. |
$form | Form Object | The form which created the current entry. |
Examples
add_filter( 'gform_stripe_checkout_payment_methods', function( $payment_methods, $feed, $form ) {
return array( 'card', 'us_bank_account' );
}, 10, 3);
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?
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.
Country and Currency
Note that implementation of specific payment methods via hook may be limited by your country and the currency you are using. For example, to use us_bank_account
Stripe requires that the merchant be located in the United States, and that the currency being charged is $US.
Refer to this Stripe reference table regarding the limitations of payment methods and currency.
Since
This filter was added in Stripe version 5.0.
Source Code
$payment_methods = apply_filters( 'gform_stripe_checkout_payment_methods', array( 'card' ), $feed, $form );
This filter is located in GFStripe::register_init_scripts() in gravityformsstripe/class-gf-stripe.php.