Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register only reusable payment methods when adding a payment method #4427

Conversation

mdmoore
Copy link
Member

@mdmoore mdmoore commented Jul 11, 2022

With multiple gateways being registered, the Add Payment Method page is broken with the error, This payment method does not support recurring payments. and new payment methods cannot be added.

Fixes #4396

Changes proposed in this Pull Request

This ensures that only reusable payment methods are available on the My Account > Payment Methods > Add Payment Method page rather than all UPE methods.

Testing instructions

  1. After checking out this branch, run npm run start, enable WooPay and the UPE.
  2. Enable a few UPE payment methods in the WCPay settings.
  3. Add a product to the cart and verify that both the CC and enabled UPE methods are present on checkout
  4. Go to My Account > Payment Methods > Add Payment Method and verify that no error is present on the page and that a new payment method can be added.

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Post merge

@mdmoore mdmoore requested review from a team and harriswong and removed request for a team July 11, 2022 20:44
@harriswong
Copy link
Contributor

👀

@harriswong
Copy link
Contributor

harriswong commented Jul 14, 2022

If I enabled giropay, sofort and sepa inside UPE, then visiting http://localhost:8082/my-account/add-payment-method/ should show cc, giropay, sofort and sepa right?

On mine, I only see credit card and sepa:
image

I also see this undefined upElement error in the console
image

@harriswong
Copy link
Contributor

Also, do we need to worry about the failed tests, or is this something we need to address separately in the poc/upe-instances-multiplied branch?

@harriswong
Copy link
Contributor

In my http://localhost:8082/my-account/add-payment-method/,
image

I see credit card and SEPA, but I don't see giropay and sofort. My checkout page does show those though. Is this the same case for you?
image

@mdmoore
Copy link
Member Author

mdmoore commented Jul 25, 2022

@harriswong Yes, that's the correct behavior. Only reusable payment gateways will be available here, so SEPA and CC should be the only gateways that appear when adding a payment method for future use.

The undefined UPEElement error you mentioned earlier is now resolved, but we're now getting these errors when submitting the form:

A WooCommerce Payments payment method was not provided is printed on the page and this in the console:

image

@mdmoore
Copy link
Member Author

mdmoore commented Aug 1, 2022

It turns out that the selectors used for payment gateways on the Add Payment Method page differs from those used on checkout and other pages, so getSelectedGatewayPaymentMethod() wasn't returning the correct payment method.

@harriswong After rebuilding JS, this should be working well now, as in, both credit card and SEPA payment methods can be added. It does surface another issue where SEPA tokens are appearing in the list of credit card tokens(where they've always appeared because it was the only place) when they should appear inside the SEPA gateway. That warrants a separate issue so I think we can push forward with this one.

selectedGatewayId = $(
'li.wc_payment_method input.input-radio:checked'
).attr( 'id' );
} else if ( $( 'li.woocommerce-PaymentMethod' ).length ) {
Copy link
Contributor

@harriswong harriswong Aug 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, 'li.woocommerce-PaymentMethod' is used inside http://localhost:8082/my-account/add-payment-method/. I was trying to look for this on the http://localhost:8082/checkout/ but I can't find it.

I wonder if it's worth adding a comment here so we don't accidentally remove it in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! This was a head-scratcher for me as well. Comment added.

if (
'woocommerce_payments' !==
$(
"#add_payment_method input:checked[name='payment_method']"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing this because in http://localhost:8082/my-account/add-payment-method/, it will no longer be only "Credit Card/debit card"?

image

Do you know why we needed to return; early before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we removing this because in http://localhost:8082/my-account/add-payment-method/, it will no longer be only "Credit Card/debit card"?

Yep. woocommerce_payments is the attribute we'll see for Credit Card/debit card while other gateways will append the gateway name, like woocommerce_payments_sepa_debit.

Do you know why we needed to return; early before?

I don't exactly 🤔.

}

if ( is_add_payment_method_page() ) {
return $reusable_methods;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense that http://localhost:8082/my-account/add-payment-method/ only display payment methods that are saved, but not every single payment method we support. 👍

Copy link
Contributor

@harriswong harriswong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this on both checkout and my my-account/add-payment-method/. I have some questions but LGTM otherwise!

@mdmoore mdmoore merged commit 7ce0482 into poc/upe-instances-multiplied Aug 8, 2022
@mdmoore mdmoore deleted the fix/4396-filter-reusable-add-payment-methods branch August 8, 2022 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multiple UPE - payment method does not support recurring payments error in my account
2 participants