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
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e18b8a9
Disabling BNPLs when other official plugins are active
wjrosa Jul 14, 2025
fc3d51a
Simplifying logic
wjrosa Jul 15, 2025
e90b2d3
Changelog and readme entries
wjrosa Jul 15, 2025
19d0206
Unit tests
wjrosa Jul 15, 2025
de89343
Checking for specific official plugins instead of any
wjrosa Jul 15, 2025
82fcb80
Adding constants
wjrosa Jul 15, 2025
21f2457
Unit test
wjrosa Jul 15, 2025
d6f85d2
Merge branch 'develop' into update/disable-bnpls-when-other-plugins-a…
wjrosa Jul 15, 2025
569443d
Merge branch 'develop' into update/disable-bnpls-when-other-plugins-a…
wjrosa Jul 15, 2025
644c10a
Merge branch 'develop' into update/disable-bnpls-when-other-plugins-a…
wjrosa Jul 16, 2025
6465faf
Fix methods availability in the block checkout
wjrosa Jul 16, 2025
c2dfbc9
Fix methods availability in the block checkout
wjrosa Jul 16, 2025
c33624d
Keeping methods visible in the settings page
wjrosa Jul 16, 2025
7d76068
Fix methods availability in the shortcode checkout
wjrosa Jul 16, 2025
ce86f94
New pill to inform about the conflict
wjrosa Jul 16, 2025
3b5160d
Unit test
wjrosa Jul 16, 2025
4f94543
Disable checkbox when unavailable
wjrosa Jul 16, 2025
3760220
Merge branch 'develop' into update/disable-bnpls-when-other-plugins-a…
wjrosa Jul 16, 2025
4a26e67
Reverting unit tests removal
wjrosa Jul 16, 2025
b5fc2a5
Update index.js
wjrosa Jul 16, 2025
ed7c159
Update index.test.js
wjrosa Jul 16, 2025
9bcd50f
Merge branch 'develop' into update/disable-bnpls-when-other-plugins-a…
wjrosa Jul 16, 2025
7144812
Update index.js
wjrosa Jul 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.7.0 - xxxx-xx-xx =
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active
* Fix - Moves the existing order lock functionality earlier in the order processing flow to prevent duplicate processing requests
* Add - Adds two new safety filters to the subscriptions detached debug tool: `wc_stripe_detached_subscriptions_maximum_time` and `wc_stripe_detached_subscriptions_maximum_count`
* Add - Show a notice when editing an active subscription that has no payment method attached
Expand Down
23 changes: 23 additions & 0 deletions client/settings/general-settings-section/payment-methods-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
PAYMENT_METHOD_AFTERPAY_CLEARPAY,
PAYMENT_METHOD_CARD,
PAYMENT_METHOD_GIROPAY,
PAYMENT_METHOD_KLARNA,
PAYMENT_METHOD_SOFORT,
} from 'wcstripe/stripe-utils/constants';

Expand Down Expand Up @@ -186,6 +187,28 @@ const GeneralSettingsSection = ( { isChangingDisplayOrder } ) => {
);
}

// Remove Affirm and Klarna if other official plugins are active
if (
// eslint-disable-next-line camelcase
wc_stripe_settings_params?.has_affirm_gateway_plugin &&
availablePaymentMethods.includes( PAYMENT_METHOD_AFFIRM )
) {
availablePaymentMethods.splice(
availablePaymentMethods.indexOf( PAYMENT_METHOD_AFFIRM ),
1
);
}
if (
// eslint-disable-next-line camelcase
wc_stripe_settings_params?.has_klarna_gateway_plugin &&
availablePaymentMethods.includes( PAYMENT_METHOD_KLARNA )
) {
availablePaymentMethods.splice(
availablePaymentMethods.indexOf( PAYMENT_METHOD_KLARNA ),
1
);
}

const onReorder = ( newOrderedPaymentMethodIds ) => {
setOrderedPaymentMethodIds( newOrderedPaymentMethodIds );
};
Expand Down
13 changes: 3 additions & 10 deletions includes/admin/class-wc-stripe-settings-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,6 @@ public function admin_scripts( $hook_suffix ) {
// Show the BNPL promotional banner only if no BNPL payment methods are enabled.
&& ! array_intersect( WC_Stripe_Payment_Methods::BNPL_PAYMENT_METHODS, $enabled_payment_methods );

$has_other_bnpl_plugins_active = false;
$available_payment_gateways = WC()->payment_gateways->payment_gateways;
foreach ( $available_payment_gateways as $gateway ) {
if ( ( 'affirm' === $gateway->id || 'klarna_payments' === $gateway->id ) && 'yes' === $gateway->enabled ) {
$has_other_bnpl_plugins_active = true;
break;
}
}

$params = [
'time' => time(),
'i18n_out_of_sync' => $message,
Expand All @@ -287,7 +278,9 @@ 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_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.

Making use of the new helper function.

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.

'is_payments_onboarding_task_completed' => $this->is_payments_onboarding_task_completed(),
];
wp_localize_script(
Expand Down
45 changes: 45 additions & 0 deletions includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ class WC_Stripe_Helper {
const META_NAME_STRIPE_CURRENCY = '_stripe_currency';
const PAYMENT_AWAITING_ACTION_META = '_stripe_payment_awaiting_action';

/**
* The identifier for the official Affirm gateway plugin.
*
* @var string
*/
const OFFICIAL_PLUGIN_ID_AFFIRM = 'affirm';

/**
* The identifier for the official Klarna gateway plugin.
*
* @var string
*/
const OFFICIAL_PLUGIN_ID_KLARNA = 'klarna_payments';

/**
* List of legacy Stripe gateways.
*
Expand Down Expand Up @@ -1851,4 +1865,35 @@ public static function get_refund_reason_description( $refund_reason_key ) {
return __( 'Unknown reason', 'woocommerce-gateway-stripe' );
}
}

/**
* Checks if there are other Buy Now Pay Later plugins active.
*
* @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.

$other_bnpl_gateway_ids = [ self::OFFICIAL_PLUGIN_ID_AFFIRM, self::OFFICIAL_PLUGIN_ID_KLARNA ];
foreach ( $other_bnpl_gateway_ids as $bnpl_gateway_id ) {
if ( self::has_gateway_plugin_active( $bnpl_gateway_id ) ) {
return true;
}
}
return false;
}

/**
* Checks if a given payment gateway plugin is active.
*
* @param string $plugin_id
* @return bool
*/
public static function has_gateway_plugin_active( $plugin_id ) {
$available_payment_gateways = WC()->payment_gateways->payment_gateways ?? [];
foreach ( $available_payment_gateways as $available_payment_gateway ) {
if ( $plugin_id === $available_payment_gateway->id && 'yes' === $available_payment_gateway->enabled ) {
return true;
}
}
return false;
}
}
11 changes: 1 addition & 10 deletions includes/notes/class-wc-stripe-bnpl-promotion-note.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,7 @@ public static function init( WC_Stripe_Payment_Gateway $gateway ) {
}
}

$has_other_bnpl_plugins_active = false;
$available_payment_gateways = WC()->payment_gateways->payment_gateways;
$other_bnpl_gateway_ids = [ 'affirm', 'klarna_payments' ];
foreach ( $available_payment_gateways as $available_payment_gateway ) {
if ( in_array( $available_payment_gateway->id, $other_bnpl_gateway_ids, true ) && 'yes' === $available_payment_gateway->enabled ) {
$has_other_bnpl_plugins_active = true;
break;
}
}
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.

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@ public function __construct() {
continue;
}

// Disable BNPLs when other official plugins are installed and enabled.
if ( WC_Stripe_UPE_Payment_Method_Affirm::class === $payment_method_class && WC_Stripe_Helper::has_gateway_plugin_active( WC_Stripe_Helper::OFFICIAL_PLUGIN_ID_AFFIRM ) ) {
continue;
}

if ( WC_Stripe_UPE_Payment_Method_Klarna::class === $payment_method_class && WC_Stripe_Helper::has_gateway_plugin_active( WC_Stripe_Helper::OFFICIAL_PLUGIN_ID_KLARNA ) ) {
continue;
}

$payment_method = new $payment_method_class();
$this->payment_methods[ $payment_method->get_id() ] = $payment_method;
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 9.7.0 - xxxx-xx-xx =
* Update - Removes BNPL payment methods (Klarna and Affirm) when other official plugins are active
* Fix - Moves the existing order lock functionality earlier in the order processing flow to prevent duplicate processing requests
* Add - Adds two new safety filters to the subscriptions detached debug tool: `wc_stripe_detached_subscriptions_maximum_time` and `wc_stripe_detached_subscriptions_maximum_count`
* Add - Show a notice when editing an active subscription that has no payment method attached
Expand Down
Loading
Loading