Using 'gform stripe checkout payment methods' add_filter to target a specific form

I want to target a specific form to limit it’s payment option ouput. Ultimately the end goal is to have two pages, each with a form on it. One pages form will only display a cash payment option. The other pages form will only display a card payment option. I am trying to use the following example as my starting point:

add_filter( 'gform_stripe_checkout_payment_methods', function( $payment_methods, $feed, $form ) {
    return array( 'card', 'us_bank_account' );
}, 10, 3);

I am trying to use something like this to achieve my goal, but I know thi is not it:

add_filter( 'gform_stripe_checkout_payment_methods', function( $payment_methods, $feed, $form ) {
	if ( $form = '3' ) {
		return array( 'card' );
	}
	if ( $form = '4' ) {
		return array( 'us_bank_account' );
	}
}, 10, 3);

Any help is appreciated. Thank you.

Not sure if I just have something way off, but this in the child functions.php has no effect on the forms at all:

add_filter( 'gform_stripe_checkout_payment_methods', function( $payment_methods, $feed, $form ) {
    return array( 'us_bank_account' );
}, 10, 3);

Hi Wesley. Give this a try:

add_filter( 'gform_stripe_checkout_payment_methods', function( $payment_methods, $feed, $form ) {
    // Check the form ID and conditionally allow payment methods
    if ( $form['id'] == 3 ) {
        return array( 'card' );
    } elseif ( $form['id'] == 4 ) {
        return array( 'us_bank_account' );
    } else {
        // Default case, allow both payment methods
        return array( 'card', 'us_bank_account' );
    }
}, 10, 3 );
1 Like

I added the code you sent but both forms are still showing both payment methods.

That looks like you may be using the Stripe field and not Stripe Checkout (which is a hosted checkout page from Stripe, not a field in the form).

The filter you’re using here I believe only works with the latter and you’d need to use this filter instead for the former.

2 Likes

OK. Using this code:

add_filter( 'gform_stripe_payment_element_payment_methods', function( $payment_methods, $feed, $form ) {
    // Check the form ID and conditionally allow payment methods
    if ( $form['id'] == 3 ) {
        return array( 'card' );
    } elseif ( $form['id'] == 4 ) {
        return array( 'us_bank_account' );
    } else {
        // Default case, allow both payment methods
        return array( 'card', 'us_bank_account' );
    }
}, 10, 3 );

The card version is working. But the elseif for the bank version is not. Any ideas. Here’s screenshots to show the results and the form id’s are matching. One working as expected, the other is not.


Thank you for all your help thus far

So in testing a few things. I have determined that trying to get just ‘us_bank_account’ doesn’t work. I changed my function to check this a few ways and I can get just card to display, but never just ‘us_bank_account’ to display. Not sure if something isn’t updated in the documentation for this payment type, or if it’s just not allowed to have only the bank option available?

Not sure if I’m reading this right, but this code in the plugin itself may be supporting this theory that it’s not possible?
Line 106 of /includes/payment-element/class-gf-payment-element.php

		$payment_methods = $this->payment->get_payment_methods( $feed, $form );
		if ( ! empty( $payment_methods ) ) {
			// When payment method types are explicitly defined, 'card' must be one of the methods.
			$intent_information['payment_method_types'] = array_unique( array_merge( $payment_methods, array( 'card' ) ) );
		}

From Support:
This is a Stripe.com limitation. They don’t allow you to turn off the Cards payment method.
Closing this out.