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

Allow the forceNetworkSavedCards payment method setting to be overridden #9460

Conversation

romarioraffington
Copy link
Contributor

@romarioraffington romarioraffington commented Sep 18, 2024

Fixes https://github.com/Automattic/payments-florin/issues/605
Relates to D161783-code and D161783-code

These changes were introduced in #7869

Changes proposed in this Pull Request

Allow the network saved card payment method setting to be overridden by the wcpay_force_network_saved_cards filter. See https://github.com/Automattic/payments-florin/issues/605 for additional context.

Testing instructions

Testing instructions can be found in D161783-code


  • 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

…idden

Allow the network saved card setting to be overriden by the `wcpay_force_network_saved_cards` filter
@romarioraffington romarioraffington changed the title Allow the forceNetworkSavedCards payment method setting to be overridden by wcpay_force_network_saved_cards filter Allow the forceNetworkSavedCards payment method setting to be overridden Sep 18, 2024
Copy link
Contributor

github-actions bot commented Sep 18, 2024

Size Change: 0 B

Total Size: 1.33 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.08 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.08 kB
release/woocommerce-payments/assets/css/success.css 173 B
release/woocommerce-payments/assets/css/success.rtl.css 173 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.52 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.52 kB
release/woocommerce-payments/dist/blocks-checkout.js 66.5 kB
release/woocommerce-payments/dist/cart-block.js 16.2 kB
release/woocommerce-payments/dist/cart.js 5.73 kB
release/woocommerce-payments/dist/checkout-rtl.css 927 B
release/woocommerce-payments/dist/checkout.css 927 B
release/woocommerce-payments/dist/checkout.js 32.4 kB
release/woocommerce-payments/dist/express-checkout-rtl.css 230 B
release/woocommerce-payments/dist/express-checkout.css 230 B
release/woocommerce-payments/dist/express-checkout.js 14.2 kB
release/woocommerce-payments/dist/frontend-tracks.js 858 B
release/woocommerce-payments/dist/index-rtl.css 39.3 kB
release/woocommerce-payments/dist/index.css 39.2 kB
release/woocommerce-payments/dist/index.js 302 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 3.41 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.6 kB
release/woocommerce-payments/dist/multi-currency.css 3.41 kB
release/woocommerce-payments/dist/multi-currency.js 55.6 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/order.js 42.7 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.35 kB
release/woocommerce-payments/dist/payment-gateways.css 1.35 kB
release/woocommerce-payments/dist/payment-gateways.js 39.3 kB
release/woocommerce-payments/dist/payment-request-rtl.css 230 B
release/woocommerce-payments/dist/payment-request.css 230 B
release/woocommerce-payments/dist/payment-request.js 13.6 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 20.1 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 11.5 kB
release/woocommerce-payments/dist/settings-rtl.css 11.6 kB
release/woocommerce-payments/dist/settings.css 11.5 kB
release/woocommerce-payments/dist/settings.js 224 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.2 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.3 kB
release/woocommerce-payments/dist/tokenized-payment-request-rtl.css 230 B
release/woocommerce-payments/dist/tokenized-payment-request.css 230 B
release/woocommerce-payments/dist/tokenized-payment-request.js 14.4 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21.8 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.14 kB
release/woocommerce-payments/dist/woopay-express-button.js 24 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.54 kB
release/woocommerce-payments/dist/woopay.css 4.51 kB
release/woocommerce-payments/dist/woopay.js 71.3 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 735 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/react-jsx-runtime.js 553 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.2 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.45 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 417 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 584 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 621 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

@botwoo
Copy link
Collaborator

botwoo commented Sep 18, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 9460 or branch name fix/re-introduce-support-for-wcpay_force_network_saved_cards-filter in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 04aad8b
  • Build time: 2024-09-24 16:03:29 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

@timur27 timur27 left a comment

Choose a reason for hiding this comment

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

@romarioraffington The code change looks good, thanks! I wonder if testing steps for this PR should contain sanity checks within WooPayments plugin only, while the rest is done in https://href.li/?https://code.a8c.com/D161783. I also asked in https://a8c.slack.com/archives/C011RA2S7BJ/p1726733430075369

Copy link
Contributor

@timur27 timur27 left a comment

Choose a reason for hiding this comment

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

Looked at this code once again and I have some thoughts. I tried to review the original change for this area, and it seems that forceNetworkSavedCards is applicable only for cards. My question is whether we're OK with adding WC_Payments::is_network_saved_cards_enabled() to payment methods other than card, which your change seems to do, especially in terms of potential side effects.

When using should_use_stripe_platform_on_checkout_page before, it checks the payment method type to be card, while is_network_saved_cards_enabled could potentially return true for non-card methods as well, if network-saved cards are enabled. Given the complexity of this legacy feature (I also asked if anyone from WooPayments group possesses the knowledge for this feature these days: p1726739953413419-slack-CGGCLBN58), we might consider adding the check against the card payment method type either as part of $settings[ $payment_method_id ]['forceNetworkSavedCards']assignment or as part of is_network_saved_cards_enabled, right before applying the filter. Another option would be to make JS take forceNetworkSavedCards from paymentMethodsConfig for non-cards only, but take it from here in case of card payment method.

@romarioraffington
Copy link
Contributor Author

@romarioraffington The code change looks good, thanks! I wonder if testing steps for this PR should contain sanity checks within WooPayments plugin only,

I agree! Sanity checks are always good. Do you have a link to another PR or docs with sanity checks to include? I'm not as familiar with WooPayments dev setup / testing.

Looked at this code once again and I have some thoughts. I tried to review https://github.com/Automattic/woocommerce-payments-server/pull/694 for this area, and it seems that forceNetworkSavedCards is applicable only for cards. My question is whether we're OK with adding WC_Payments::is_network_saved_cards_enabled() to payment methods other than card, which your change seems to do, especially in terms of potential side effects.

Given the complexity of this legacy feature (I also asked if anyone from WooPayments group possesses the knowledge for this feature these days: p1726739953413419-slack-CGGCLBN58), we might consider adding the check against the card payment method type either as part of $settings[ $payment_method_id ]['forceNetworkSavedCards']assignment or as part of is_network_saved_cards_enabled, right before applying the filter. Another option would be to make JS take forceNetworkSavedCards from paymentMethodsConfig for non-cards only, but take it from here in case of card payment method.

You're right. It's best to error on the side of caution here and only allow the filter to override settings for cards. I'll make the improvements as suggested. Thanks!

Copy link
Contributor

@timur27 timur27 left a comment

Choose a reason for hiding this comment

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

Thanks for quick responses and for all the work so far @romarioraffington! I've left two related comments which should impact the functionality, I'm looking forward to hearing from you whether this makes sense to you.

In the meantime, I've tested WooPayments with the changes proposed in my comments (moving the payment method check to class-wc-payments-checkout) and below are the results:

  1. Used add_filter( 'wcpay_force_network_saved_cards', '__return_true' ); to return true and false consequently and check whether the correct result of the is_network_saved_cards_enabled() method is taken into account for card payment method only ✅
  2. Performed a payment with credit card ✅
  3. Performed a payment and saved the credit card ✅
  4. Paid with a saved credit card ✅
  5. Paid with non-card payment methods - Bancontact and SEPA ✅

I also tested in sandbox per testing instructions and it works but there are two things to keep in mind:

  • I tested your current version of the code from D161783-code which means that is_network_saved_cards_enabled returns the filter value for every payment method, not only cards
  • I assume D161783-code will be tested additionally by someone from your team as well, as you have more context and might catch up things that I could potentially miss
image

@@ -1544,7 +1544,7 @@ public static function remove_woo_admin_notes() {
* @return bool Normal WCPay behavior (false, default) or TRUE if the site should only use network-wide saved payment methods.
*/
public static function is_network_saved_cards_enabled() {
return apply_filters( 'wcpay_force_network_saved_cards', false );
return Payment_Method::CARD === self::$card_gateway->get_selected_stripe_payment_type_id() && apply_filters( 'wcpay_force_network_saved_cards', false );
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree this makes sense, but unfortunately, get_selected_stripe_payment_type_id() from the $card_gateway will always return card. I agree that semantically this method seems to be able to return the currently selected payment method, but it doesn't.

My proposal would be to keep is_network_saved_cards_enabled() as it is, without changes, and move the check against card payment method to the place where we assign value to $settings[ $payment_method_id ]['forceNetworkSavedCards'] in class-wc-payments-checkout.php

@@ -332,7 +332,7 @@ public function get_enabled_payment_method_config() {
'number' => '<button type="button" class="js-woopayments-copy-test-number" aria-label="' . esc_attr( __( 'Click to copy the test number to clipboard', 'woocommerce-payments' ) ) . '" title="' . esc_attr( __( 'Copy to clipboard', 'woocommerce-payments' ) ) . '"><i></i><span>',
]
);
$settings[ $payment_method_id ]['forceNetworkSavedCards'] = $gateway_for_payment_method->should_use_stripe_platform_on_checkout_page();
$settings[ $payment_method_id ]['forceNetworkSavedCards'] = WC_Payments::is_network_saved_cards_enabled() || $gateway_for_payment_method->should_use_stripe_platform_on_checkout_page();
Copy link
Contributor

Choose a reason for hiding this comment

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

As per another comment, I think it would be more safe to move the check here as shown below (or a similar syntax which achieves the same result):

Suggested change
$settings[ $payment_method_id ]['forceNetworkSavedCards'] = WC_Payments::is_network_saved_cards_enabled() || $gateway_for_payment_method->should_use_stripe_platform_on_checkout_page();
$settings[ $payment_method_id ]['forceNetworkSavedCards'] =
'card' === $payment_method_id &&
(WC_Payments::is_network_saved_cards_enabled() ||
$gateway_for_payment_method->should_use_stripe_platform_on_checkout_page());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me. Addressed in 2c840ae

@romarioraffington
Copy link
Contributor Author

I assume D161783-code will be tested additionally by someone from your team as well, as you have more context and might catch up things that I could potentially miss

For sure!

@mdmoore
Copy link
Member

mdmoore commented Sep 23, 2024

Hey @romarioraffington and @timur27! I've tested this again from the WooPayments side.

  1. Used add_filter( 'wcpay_force_network_saved_cards', '__return_true' ); to return true and false consequently and check whether the correct result of the is_network_saved_cards_enabled() method is taken into account for card payment method only ✅
  2. Performed a payment with credit card ✅
  3. Performed a payment and saved the credit card ✅
  4. Paid with a saved credit card ✅
  5. Paid with non-card payment methods - Bancontact and SEPA ✅

I'd like to note that when add_filter( 'wcpay_force_network_saved_cards', '__return_true' );, checkout with card fails with this message:

Error: No such PaymentMethod: 'pm_1Q2DgXJ5cIRIG92x11mn8FsK'; OAuth key or Stripe-Account header was used but API request was provided with a platform-owned payment method ID. Please ensure that the provided payment method matches the specified account.

I think this is expected due to the nature of the change, with the payment method not being available on the platform account, the inverse of what prompted this issue. If it's OK, I'd like to confirm that with @timur27 before approving.

@romarioraffington
Copy link
Contributor Author

I'd like to note that when add_filter( 'wcpay_force_network_saved_cards', '__return_true' );, checkout with card fails with this message:

Error: No such PaymentMethod: 'pm_1Q2DgXJ5cIRIG92x11mn8FsK'; OAuth key or Stripe-Account header was used but API request was provided with a platform-owned payment method ID. Please ensure that the provided payment method matches the specified account.

Thanks for taking a look @mdmoore. Based on the error message above, my understanding is that the payment method is available on the platform account but the request was sent to the connected account.

For TumblrPay, we expect the platform payment method to be passed to the backend and attached to the platform customer, but I suspect this is custom TumlbrPay logic.

Copy link
Contributor

@timur27 timur27 left a comment

Choose a reason for hiding this comment

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

The change looks good @romarioraffington, thanks for all your efforts! 🚀
Regarding

add_filter( 'wcpay_force_network_saved_cards', '__return_true' );

causing the error, which was rightly pointed out by @mdmoore - I also think this is expected because we're trying to use a payment method that belongs to the platform account (due to wcpay_force_network_saved_cards returning true) with a connected account's API request. My understanding is that this filter returns true for Tumblrpay only, based on this original PR. I started the discussion about this flag in p1726739953413419-slack-CGGCLBN58 because it seems that this feature is not well known.

@romarioraffington romarioraffington added this pull request to the merge queue Sep 24, 2024
Merged via the queue into develop with commit 7cd304e Sep 24, 2024
25 checks passed
@romarioraffington romarioraffington deleted the fix/re-introduce-support-for-wcpay_force_network_saved_cards-filter branch September 24, 2024 16:50
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.

4 participants