Skip to content

Disabling BNPLs when other official plugins are active #4492

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

Merged
merged 23 commits into from
Jul 16, 2025

Conversation

wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Jul 14, 2025

Fixes STRIPE-431

Changes proposed in this Pull Request:

To prevent Affirm and Klarna from being displayed alongside other official plugins, we are now removing them when the other plugins are active. Instead of checking for any of the plugins, we are disabling each corresponding method.

I am also adding some new helper methods specific to this logic to reduce duplicate code.

Testing instructions

  • Checkout to the develop branch on your test environment
  • Connect a US Stripe account
  • Install Affirm or Klarna extensions (only one is enough)
  • Confirm you can see Klarna and Affirm in the payment methods settings page (wp-admin/admin.php?page=wc-settings&tab=checkout&section=stripe&panel=methods)
  • Enable both
  • As a shopper, add at least 50 USD in products to your cart
  • Go to the checkout page and confirm both methods are available
  • Now checkout to this branch instead (update/disable-bnpls-when-other-plugins-are-active)
  • As a shopper, confirm Klarna and Affirm are now gone from the payment methods settings page (depending on the official extension you installed, or both if you installed both)
  • As a merchant, go to the checkout page and confirm that the same happened

  • 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

Comment

Post merge

@wjrosa wjrosa self-assigned this Jul 14, 2025
*
* @return bool
*/
public static function has_other_bnpl_plugins_active() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we need this logic in multiple places, I moved it to a new helper function.

}
}
if ( $has_other_bnpl_plugins_active ) {
if ( WC_Stripe_Helper::has_other_bnpl_plugins_active() ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making use of the new helper function.

@@ -287,7 +278,7 @@ public function admin_scripts( $hook_suffix ) {
'is_oc_available' => WC_Stripe_Feature_Flags::is_oc_available(),
'oauth_nonce' => wp_create_nonce( 'wc_stripe_get_oauth_urls' ),
'is_sepa_tokens_enabled' => 'yes' === $this->gateway->get_option( 'sepa_tokens_for_other_methods', 'no' ),
'has_other_bnpl_plugins' => $has_other_bnpl_plugins_active,
'has_other_bnpl_plugins' => WC_Stripe_Helper::has_other_bnpl_plugins_active(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making use of the new helper function.

@wjrosa wjrosa marked this pull request as ready for review July 15, 2025 12:44
@wjrosa wjrosa requested a review from Copilot July 15, 2025 13:43
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR disables Stripe’s UPE BNPL methods (Affirm & Klarna) when the corresponding official plugins are active and centralizes the detection logic in helper methods.

  • Introduces has_gateway_plugin_active and has_other_bnpl_plugins_active with constants for official plugin IDs.
  • Updates UPE payment gateway, promotion note, and settings controller to use the new helpers.
  • Adds/testing adjustments for the new helpers and updates changelog/readme and client-side JS to remove BNPL methods.

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/phpunit/WC_Stripe_Helper_Test.php Replaces old tests, adds tests for has_other_bnpl_plugins_active and has_gateway_plugin_active.
readme.txt Adds entry about disabling BNPL when official plugins are active.
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php Skips Affirm/Klarna methods via new helper checks.
includes/notes/class-wc-stripe-bnpl-promotion-note.php Uses has_other_bnpl_plugins_active instead of manual loop.
includes/class-wc-stripe-helper.php Adds constants and helper methods for plugin detection.
includes/admin/class-wc-stripe-settings-controller.php Removes manual checks and localizes flags with new helper methods.
client/settings/general-settings-section/payment-methods-list.js Removes BNPL methods in the UI when official plugins are active.
changelog.txt Reflects the BNPL disabling feature.
Comments suppressed due to low confidence (4)

tests/phpunit/WC_Stripe_Helper_Test.php:222

  • The data provider key 'payment gateways' should be 'payment_gateways' to exactly match the test method’s $payment_gateways parameter name.
				'payment gateways' => [

tests/phpunit/WC_Stripe_Helper_Test.php:273

  • The data provider key 'plugin id' should be 'plugin_id' to align with the test method’s $plugin_id parameter name.
				'plugin id'        => WC_Stripe_Helper::OFFICIAL_PLUGIN_ID_KLARNA,

tests/phpunit/WC_Stripe_Helper_Test.php:274

  • Also update this key from 'payment gateways' to 'payment_gateways' so PHPUnit can map it to the $payment_gateways parameter.
				'payment gateways' => [

client/settings/general-settings-section/payment-methods-list.js:194

  • Import PAYMENT_METHOD_AFFIRM from 'wcstripe/stripe-utils/constants' at the top of the file, since it’s referenced here but not imported.
		availablePaymentMethods.includes( PAYMENT_METHOD_AFFIRM )

@wjrosa wjrosa requested review from a team, diegocurbelo and Mayisha and removed request for a team July 15, 2025 13:49
'has_other_bnpl_plugins' => $has_other_bnpl_plugins_active,
'has_affirm_gateway_plugin' => WC_Stripe_Helper::has_gateway_plugin_active( WC_Stripe_Helper::OFFICIAL_PLUGIN_ID_AFFIRM ),
'has_klarna_gateway_plugin' => WC_Stripe_Helper::has_gateway_plugin_active( WC_Stripe_Helper::OFFICIAL_PLUGIN_ID_KLARNA ),
'has_other_bnpl_plugins' => WC_Stripe_Helper::has_other_bnpl_plugins_active(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Another option here would be to reuse the return of both WC_Stripe_Helper::has_gateway_plugin_active. Not sure if it is worth it.

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.

After installing and enabling the WooCommerce Gateway Affirm plugin:

As a shopper, confirm Klarna and Affirm are now gone from the payment methods settings page (depending on the official extension you installed, or both if you installed both)

This works as indicated; the Stripe payment method is no longer shown in the payment method list in the settings.

As a merchant, go to the checkout page and confirm that the same happened

But it's still visible in the checkout.

Image

--

Additionally, removing the Affirm/Klarna methods from the payment method list in the settings without providing any feedback may be confusing.

Maybe we can set it as disabled and add a yellow pill, similar to the one we use for "Requires activation"?

Or show a notice or message explaining why Affirm/Klarna are not available in the list, or group them at the bottom under an 'Unavailable Payment Methods' group?

@Mayisha
Copy link
Contributor

Mayisha commented Jul 16, 2025

Additionally, removing the Affirm/Klarna methods from the payment method list in the settings without providing any feedback may be confusing.
Maybe we can set it as disabled and add a yellow pill, similar to the one we use for "Requires activation"?
Or show a notice or message explaining why Affirm/Klarna are not available in the list, or group them at the bottom under an 'Unavailable Payment Methods' group?

+1 to this. Completely removing the payment methods could be confusing for the user. I like the idea of showing it disabled, preferably with a tooltip explaining the reason for it being disabled.

@wjrosa wjrosa requested review from annemirasol and malithsen July 16, 2025 14:16
@malithsen malithsen added this to the 9.7.0 milestone Jul 16, 2025
@wjrosa
Copy link
Contributor Author

wjrosa commented Jul 16, 2025

Thanks for the reviews, folks!

Maybe we can set it as disabled and add a yellow pill, similar to the one we use for "Requires activation"?

Makes sense. I went for this option in my latest commits. Preview here:
Screenshot 2025-07-16 at 13 46 28

I have also fixed the methods availability in both the shortcode and block checkout.

@wjrosa wjrosa requested a review from diegocurbelo July 16, 2025 16:48
@wjrosa wjrosa requested a review from annemirasol July 16, 2025 16:53
Copy link
Contributor

@annemirasol annemirasol left a comment

Choose a reason for hiding this comment

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

This looks good and works as expected. Left a suggestion about the wording in the pill.

Tested:

When official plugin is installed and active:
✅ Klarna unavailable in settings, and not shown in block/classic checkout
✅ Affirm unavailable in settings, and not shown in block/classic checkout

When official plugin is not enabled:
✅ Klarna available in settings, and shown in block/classic checkout if enabled
✅ Affirm available in settings, and shown in block/classic checkout if enabled

Noting our earlier discussion where in a future iteration, we may also disable Klarna/Affirm in the merchant's PMC. Right now, they are disabled for the store when a conflict exists, but they remain enabled in the PMC, even after a settings update.

@annemirasol
Copy link
Contributor

Noting our earlier discussion where in a future iteration, we may also disable Klarna/Affirm in the merchant's PMC. Right now, they are disabled for the store when a conflict exists, but they remain enabled in the PMC, even after a settings update.

Actually, I want to double-check that I am understanding the earlier discussion correctly. This is the flow I'm wondering about:

  1. Enable Klarna.
  2. Install the other plugin and enable it.
  3. Notice how Klarna is now unavailable and disabled in Stripe settings.
  4. Enable or disable some other payment method, and click "Save changes".
  5. Notice in your Stripe dashboard that Klarna is still enabled.

We are okay with this flow, and will update things for OC, is that correct?

@wjrosa
Copy link
Contributor Author

wjrosa commented Jul 16, 2025

Noting our earlier discussion where in a future iteration, we may also disable Klarna/Affirm in the merchant's PMC. Right now, they are disabled for the store when a conflict exists, but they remain enabled in the PMC, even after a settings update.

Actually, I want to double-check that I am understanding the earlier discussion correctly. This is the flow I'm wondering about:

  1. Enable Klarna.
  2. Install the other plugin and enable it.
  3. Notice how Klarna is now unavailable and disabled in Stripe settings.
  4. Enable or disable some other payment method, and click "Save changes".
  5. Notice in your Stripe dashboard that Klarna is still enabled.

We are okay with this flow, and will update things for OC, is that correct?

Thanks for the review, Anne! Yes, that's my understanding as well

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.

Image

Looks good!

✅ Tested settings page with Klarna/Affirm official plugins active/inactive.
✅ Tested checkout pages (Blocks/Classic) with official plugins active/inactive.

@wjrosa wjrosa merged commit 8f01d94 into develop Jul 16, 2025
49 of 50 checks passed
@wjrosa wjrosa deleted the update/disable-bnpls-when-other-plugins-are-active branch July 16, 2025 21:20
Copy link

📈 PHP Unit Code Coverage Report

Package Line Rate Health
includes/admin/class-wc-stripe-settings-controller.php 18%
includes/class-wc-stripe-helper.php 61%
includes/notes/class-wc-stripe-bnpl-promotion-note.php 65%
includes/payment-methods/class-wc-stripe-upe-payment-gateway.php 48%
includes/payment-methods/class-wc-stripe-upe-payment-method-affirm.php 97%
includes/payment-methods/class-wc-stripe-upe-payment-method-klarna.php 57%
Summary 45% (7621 / 16998)

malithsen pushed a commit that referenced this pull request Jul 17, 2025
* Disabling BNPLs when other official plugins are active

* Simplifying logic

* Changelog and readme entries

* Unit tests

* Checking for specific official plugins instead of any

* Adding constants

* Unit test

* Fix methods availability in the block checkout

* Fix methods availability in the block checkout

* Keeping methods visible in the settings page

* Fix methods availability in the shortcode checkout

* New pill to inform about the conflict

* Unit test

* Disable checkbox when unavailable

* Reverting unit tests removal

* Update index.js

* Update index.test.js

* Update index.js
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.

5 participants