Skip to content

Show payment methods available in the PMC on settings page #4252

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

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from

Conversation

Mayisha
Copy link
Contributor

@Mayisha Mayisha commented Apr 23, 2025

In the current PMC implementation, we are syncing the enabled/disable payment methods between plugin settings and Stripe dashboard. But the list of available payment methods in plugin settings is not aligned with the payment method configuration. As a result, we show some payment methods in the settings page that are not available in the PMC.

Changes proposed in this Pull Request:

  • Retrieve available payment methods from PMC when get_upe_available_payment_methods is called.
  • Aligned with the cache implementation.
  • If pmc is not enabled, fall back to the previous code.

Testing instructions

  • Go to your Stripe settings page and connect to a Stripe account that does not support some payment methods (i.e, I have tested with an Australian Stripe account)
  • In develop, go to the payment methods tab and notice that you have OXXO, Boleto, ACSS available in the payment method list.
Screenshot 2025-04-30 at 2 55 07 AM
  • Go to the payment methods page in your Stripe dashboard and choose the payment configuration under WooCommerce.
  • Notice that, you do not have OXXO/Boleto/ACSS available here.
  • Now set your store currency to CAD and enable ACSS (Pre-authorized debit).
  • Click Save and refresh your page.
  • Notice that, ACSS is still disabled.
  • In your store logs, you will find the error Error: acss_debit is not available to this merchant.
  • Now checkout to this branch and refresh the Stripe settings page.
  • Confirm that you don't see the unsupported payment methods anymore.
  • Try to enable/disable a few methods and confirm that the changes persists in your plugin settings page and also synced in the Stripe dashboard.

@Mayisha Mayisha marked this pull request as draft April 23, 2025 08:07
@Mayisha Mayisha changed the base branch from develop to fix/add-caching-for-stripe-configuration April 23, 2025 16:56
Base automatically changed from fix/add-caching-for-stripe-configuration to develop April 24, 2025 10:20
Copy link
Member

@diegocurbelo diegocurbelo left a comment

Choose a reason for hiding this comment

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

The implementation looks good, the only comment is renaming the get_upe_available_payment_methods function in WC_Stripe_Payment_Method_Configurations

@diegocurbelo diegocurbelo self-requested a review April 24, 2025 20:52
@daledupreez daledupreez self-requested a review April 29, 2025 09:47
@daledupreez
Copy link
Contributor

@Mayisha, could you add more context to the PR so we can test it before @diegocurbelo is available?

@Mayisha Mayisha marked this pull request as ready for review April 30, 2025 06:53
@Mayisha
Copy link
Contributor Author

Mayisha commented Apr 30, 2025

@daledupreez I have added the description and addressed the feedback.

Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

It looks like there are a number of legitimate unit test failures that we need to resolve before we can merge this.

@Mayisha, let me know if you'd like to hand over work on getting the tests working.

Comment on lines +247 to 250
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods( true ) : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$ordered_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_ordered_payment_method_ids( $this->gateway ) : $available_payment_method_ids;
$enabled_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_enabled_payment_method_ids( true ) : WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();

Copy link
Contributor

Choose a reason for hiding this comment

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

I have one concern here: we're forcing two refreshes of the PMC from Stripe when $is_upe_enabled, as we're supplying $force_refresh = true to both $this->gateway->get_upe_available_payment_methods() and $this->gateway->get_upe_enabled_payment_method_ids( true ). We should only trigger one re-fetch.

Suggested change
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods( true ) : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$ordered_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_ordered_payment_method_ids( $this->gateway ) : $available_payment_method_ids;
$enabled_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_enabled_payment_method_ids( true ) : WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();
// Note that we specify the $force_refresh parameter for this fetch only, and not when fetching enabled payment methods below.
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods( true ) : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$ordered_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_ordered_payment_method_ids( $this->gateway ) : $available_payment_method_ids;
$enabled_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_enabled_payment_method_ids( false ) : WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();

$available_payment_method_ids = [];
$merchant_payment_method_configuration = self::get_primary_configuration( $force_refresh );

if ( $merchant_payment_method_configuration ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not clear on why this code is not checking/calling self::is_enabled(). We are checking that in get_upe_enabled_payment_method_ids() below, and in the current calling code, so I am not sure why we're skipping the check here.

My initial suspicion is that is_enabled() is checking for write permissions, where we only need to read what functions are available for the account. But then I got confused across the various cases.

@@ -39,7 +38,6 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
WC_Stripe_Payment_Methods::OXXO => WC_Stripe_UPE_Payment_Method_Oxxo::class,
WC_Stripe_Payment_Methods::SEPA => WC_Stripe_UPE_Payment_Method_Sepa::class,
WC_Stripe_Payment_Methods::P24 => WC_Stripe_UPE_Payment_Method_P24::class,
WC_Stripe_Payment_Methods::SOFORT => WC_Stripe_UPE_Payment_Method_Sofort::class,
Copy link
Contributor

Choose a reason for hiding this comment

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

This removal is causing unit test failures, and I am not sure how it's related to fixing the original issue.
At the very least we need to fix the unit test failures, but it feels like this should be something tackled by a different PR.

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.

3 participants