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

Hook up payment methods configuration #4091

Open
wants to merge 13 commits into
base: add/settings-synchronization
Choose a base branch
from

Conversation

hsingyuc
Copy link
Contributor

@hsingyuc hsingyuc commented Mar 19, 2025

Fixes #4088

Changes proposed in this Pull Request:

This PR hooks up payment method configuration settings to the admin Stripe enabled payment methods.

Out of scope:

  • Disabling unsupported payment methods on Stripe.
  • Google Pay / Apple Pay.
  • Boleto and OXXO
  • giropay and Sofort
  • Track updating payment methods will be added in another PR.
Screen.Recording.2025-03-13.at.3.00.23.PM.mov

Testing instructions

Test USD payment methods -
Test EURO payment methods - Cards,

Amazon Pay as an example. Please also test other payment gateways and remember to switch to EURO

  1. Turn the feature flag on, by setting the _wcstripe_feature_amazon_pay option to yes
  2. Verify that Amazon Pay is now available in Stripe settings
  3. Set the currency to USD
  4. Go to Stripe settings and enable Cards, Alipay, Amazon Pay, Cash app pay, Link, WeChat, Affirm, Afterpay, Klarna, and ACH Direct Debit.
  5. All payment gateway settings from step 5 for the merchant copy configuration in the Stripe dashboard your merchant copy should be enabled
  6. Disable All payment gateway settings from step 5 from Stripe dashboard settings
  7. All payment gateway settings from step 5 should be disabled in admin Stripe settings
  8. Set the currency to EURO
  9. Go to Stripe settings and enable Link, Multibanco, Bancontact, EPS, iDEAL, Przelewy24, and SEPA Direct Debit
  10. All payment gateway settings from step 10 for the merchant copy configuration in the Stripe dashboard your merchant copy should be enabled
  11. Disable All payment gateway settings from step 10 from Stripe dashboard settings
  12. All payment gateway settings from step 10 should be disabled in admin Stripe settings

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Post merge

@hsingyuc hsingyuc changed the base branch from develop to add/settings-synchronization March 19, 2025 02:40
@hsingyuc hsingyuc mentioned this pull request Mar 19, 2025
6 tasks
@hsingyuc hsingyuc marked this pull request as ready for review March 20, 2025 01:59
@hsingyuc hsingyuc requested review from a team and malithsen and removed request for a team March 20, 2025 02:00
Comment on lines 423 to 425
$payment_method_configurations = $this->stripe_api->get_payment_method_configurations() && property_exists( $this->stripe_api->get_payment_method_configurations(), 'data' )
? $this->stripe_api->get_payment_method_configurations()->data
: null;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we think about storing $this->stripe_api->get_payment_method_configurations() in an intermediate variable and doing the checks on that, to avoid multiple hits on the endpoint?

Something like

Suggested change
$payment_method_configurations = $this->stripe_api->get_payment_method_configurations() && property_exists( $this->stripe_api->get_payment_method_configurations(), 'data' )
? $this->stripe_api->get_payment_method_configurations()->data
: null;
$result = $this->stripe_api->get_payment_method_configurations();
$payment_method_configurations = $result->data ?? null;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @annemirasol! Updated ebb6e90

Copy link
Contributor

@malithsen malithsen left a comment

Choose a reason for hiding this comment

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

Nice work so far here 👍

Everything tests and works as expected.
✅ Updates to the payment methods on Stripe dashboard are reflected on the settings page.
✅ Updates to the settings page are propagated to Stripe's configuration.
✅ Tested with USD/EUR.

One question: On my Stripe dashboard, there are two configurations.

  1. "Your configuration"
  2. "WooCommerce Inc. Configuration"

2nd config is what this PR uses. Is that the correct behavior?

Left some comments about page load performance which we might want to address before merge.

* @return array|null
*/
private function get_merchant_payment_method_configuration() {
$payment_method_configurations = $this->stripe_api->get_payment_method_configurations() && property_exists( $this->stripe_api->get_payment_method_configurations(), 'data' )
Copy link
Contributor

@malithsen malithsen Mar 20, 2025

Choose a reason for hiding this comment

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

In addition to what Anne mentioned below, calling the Stripe API every time the settings page is loaded will impact page load performance.

Is there a way to avoid that?

One approach is to tie it up with the existing "Refresh account details" button and avoid automatic fetches.
If configuration updates result in a webhook event, another approach might be to listen to those for updates.

Copy link
Contributor

Choose a reason for hiding this comment

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

On a separate note, we'd want to add a log if the call to Stripe API fails for some reason.

if ( is_wp_error( $response ) ) {
    WC_Stripe_Logger::log( 'Failed to fetch payment method configurations from Stripe API.' );
    return null;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One approach is to tie it up with the existing "Refresh account details" button and avoid automatic fetches.
If configuration updates result in a webhook event, another approach might be to listen to those for updates.

This could work, but this would change how the feature works and prevent users who update settings from the Stripe dashboard from seeing them immediately in admin settings. @diegocurbelo, would this work for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On a separate note, we'd want to add a log if the call to Stripe API fails for some reason.

Yes, and we already have a log here

Copy link
Member

Choose a reason for hiding this comment

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

One approach is to tie it up with the existing "Refresh account details" button and avoid automatic fetches.
If configuration updates result in a webhook event, another approach might be to listen to those for updates.

This could work, but this would change how the feature works and prevent users who update settings from the Stripe dashboard from seeing them immediately in admin settings. @diegocurbelo, would this work for us?

Using the "Refresh payment methods" in the options menu was discussed in the Figma 0fiyiUe18lGU6kGyQNmXxE-fi-165_4304 (or maybe in P2 🤷🏼), but as the settings page is not frequently visited and most of the time (if not always) the merchant will want up-to-date information it makes sense to fetch the enabled PMs every time. Using webhooks would be a valid alternative, but it adds another point of failure.

/**
* Get the merchant payment method configuration in Stripe.
*
* @return array|null
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this function returns an object instead of an array.

Suggested change
* @return array|null
* @return object|null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @malithsen ! Updated ebb6e90

@hsingyuc
Copy link
Contributor Author

hsingyuc commented Mar 21, 2025

One question: On my Stripe dashboard, there are two configurations.
"Your configuration"
"WooCommerce Inc. Configuration"
2nd config is what this PR uses. Is that the correct behavior?

@diegocurbelo, WooCommerce Inc. configuration is the merchant copy that is the one we should update, correct?

@annemirasol
Copy link
Contributor

Is connecting the settings to the store front out of scope for this PR? For example, if I enable or disable Klarna in the settings page, the checkout page does not reflect the changes.

@diegocurbelo
Copy link
Member

One question: On my Stripe dashboard, there are two configurations.
"Your configuration"
"WooCommerce Inc. Configuration"
2nd config is what this PR uses. Is that the correct behavior?

@diegocurbelo, WooCommerce Inc. configuration is the p1741804587080839/1741751645.624259-slack-C05GDK92WGM that is the one we should update, correct?

Correct, that's the merchant-editable copy of the platform PMC.

@hsingyuc hsingyuc force-pushed the add/settings-synchronization branch from 97b5270 to 581556a Compare March 21, 2025 21: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.

Settings Synchronization: Hook up payment methods configuration
4 participants