Skip to content

Commit f17b935

Browse files
Remove connection type check from PMC sync (#4581)
* Remove connection type check from PMC migration * Check for invalid connection types * Handle migration for BNPL default-on * Add changelog and readme entries * Fix unit tests * Fix more unit tests * Merge DB and PMC enabled payment methods * Revert "Check for invalid connection types" This reverts commit 5b0cf28. * Log the enabled payment methods that are migrated Co-authored-by: daledupreez <[email protected]> * Log a few more details * Update changelog and readme --------- Co-authored-by: daledupreez <[email protected]>
1 parent 0d08dd6 commit f17b935

File tree

6 files changed

+104
-77
lines changed

6 files changed

+104
-77
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Fix - Ensure all Javascript strings use the correct text domain for translation
99
* Tweak - Use more specific selector in express checkout e2e tests
1010
* Fix - Relax customer validation that was preventing payments from the pay for order page
11+
* Fix - Remove connection type requirement from PMC sync migration attempt
1112

1213
= 9.8.0 - 2025-08-11 =
1314
* Add - Adds the current setting value for the Optimized Checkout to the Stripe System Status Report data

includes/class-wc-stripe-payment-method-configurations.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,7 @@ function ( $id ) use ( $is_test_mode ) {
303303
* @return bool
304304
*/
305305
public static function is_enabled() {
306-
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
307-
$connection_type_key = WC_Stripe_Mode::is_test() ? 'test_connection_type' : 'connection_type';
308-
309-
// If the account is not a Connect OAuth account, we can't use the payment method configurations API.
310-
if ( ! isset( $stripe_settings[ $connection_type_key ] ) || 'connect' !== $stripe_settings[ $connection_type_key ] ) {
311-
return false;
312-
}
306+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
313307

314308
// If we have the pmc_enabled flag, and it is set to no, we should not use the payment method configurations API.
315309
// We only disable the PMC if the flag is set to no explicitly, an empty value means the migration has not been attempted yet.
@@ -362,18 +356,35 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr
362356
);
363357
}
364358

365-
// Update the PMC if there are any enabled payment methods
359+
// Update the PMC if there are locally enabled payment methods
366360
if ( ! empty( $enabled_payment_methods ) ) {
367-
368361
// Get all available payment method IDs from the configuration.
369362
// We explicitly disable all payment methods that are not in the enabled_payment_methods array
370363
$available_payment_method_ids = [];
371364
foreach ( $merchant_payment_method_configuration as $payment_method_id => $payment_method ) {
372365
if ( isset( $payment_method->display_preference ) ) {
373366
$available_payment_method_ids[] = $payment_method_id;
374367
}
368+
369+
// We want to also include payment methods enabled in the PMC, except for express payment methods.
370+
if (
371+
! in_array( $payment_method_id, WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS, true ) &&
372+
! in_array( $payment_method_id, $enabled_payment_methods, true ) &&
373+
isset( $payment_method->display_preference->value ) && 'on' === $payment_method->display_preference->value
374+
) {
375+
$enabled_payment_methods[] = $payment_method_id;
376+
}
375377
}
376378

379+
WC_Stripe_Logger::error(
380+
'Switching to Stripe-hosted payment method configuration',
381+
[
382+
'pmc_id' => $merchant_payment_method_configuration->id,
383+
'enabled_payment_methods' => $enabled_payment_methods,
384+
'available_payment_method_ids' => $available_payment_method_ids,
385+
]
386+
);
387+
377388
self::update_payment_method_configuration(
378389
$enabled_payment_methods,
379390
$available_payment_method_ids
@@ -395,7 +406,7 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr
395406
* This is called when no Payment Method Configuration is found that inherits from the WooCommerce Platform.
396407
*/
397408
private static function disable_payment_method_configuration_sync() {
398-
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
409+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
399410
$stripe_settings['pmc_enabled'] = 'no';
400411
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
401412
}

includes/constants/class-wc-stripe-payment-methods.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ class WC_Stripe_Payment_Methods {
7979
self::WECHAT_PAY,
8080
];
8181

82+
const EXPRESS_PAYMENT_METHODS = [
83+
self::AMAZON_PAY,
84+
self::APPLE_PAY,
85+
self::GOOGLE_PAY,
86+
self::LINK,
87+
];
88+
8289
/**
8390
* List of express payment methods labels. Amazon Pay and Link are not included,
8491
* as they have their own payment method classes.

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,6 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
118118
* Fix - Ensure all Javascript strings use the correct text domain for translation
119119
* Tweak - Use more specific selector in express checkout e2e tests
120120
* Fix - Relax customer validation that was preventing payments from the pay for order page
121+
* Fix - Remove connection type requirement from PMC sync migration attempt
121122

122123
[See changelog for full details across versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

tests/phpunit/Admin/WC_Stripe_Admin_Notices_Test.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,6 @@ public function set_up() {
3838
'test' => 'test',
3939
]
4040
);
41-
$this->mock_payment_method_configurations(
42-
[
43-
WC_Stripe_Payment_Methods::CARD,
44-
WC_Stripe_Payment_Methods::BANCONTACT,
45-
WC_Stripe_Payment_Methods::EPS,
46-
]
47-
);
4841
}
4942

5043
/**
@@ -131,25 +124,27 @@ function () {
131124
}
132125
);
133126
wp_set_current_user( $this->factory->user->create( [ 'role' => 'administrator' ] ) );
134-
WC_Stripe_Helper::update_main_stripe_settings(
135-
[
136-
'enabled' => 'yes',
137-
'testmode' => 'no',
138-
'publishable_key' => 'pk_live_valid_test_key',
139-
'secret_key' => 'sk_live_valid_test_key',
140-
'upe_checkout_experience_enabled' => 'yes',
141-
'connection_type' => 'connect',
142-
]
143-
);
144127

145128
$this->mock_payment_method_configurations(
146129
[
130+
WC_Stripe_Payment_Methods::CARD,
147131
WC_Stripe_Payment_Methods::GIROPAY,
148132
WC_Stripe_Payment_Methods::BANCONTACT,
149133
WC_Stripe_Payment_Methods::EPS,
150134
]
151135
);
152136

137+
WC_Stripe_Helper::update_main_stripe_settings(
138+
[
139+
'enabled' => 'yes',
140+
'testmode' => 'yes',
141+
'test_publishable_key' => 'pk_test_valid_test_key',
142+
'test_secret_key' => 'sk_test_valid_test_key',
143+
'upe_checkout_experience_enabled' => 'yes',
144+
'connection_type' => 'connect',
145+
]
146+
);
147+
153148
update_option( 'wc_stripe_show_style_notice', 'no' );
154149
update_option( 'home', 'https://...' );
155150
update_option( 'wc_stripe_show_sca_notice', 'no' );

tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_Test.php

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -925,78 +925,90 @@ public function test_update_payment_token() {
925925
}
926926

927927
/**
928-
* Tests that UPE methods are enabled if Stripe is enabled and the account is connected to the platform.
928+
* Tests that UPE methods are enabled if Stripe is enabled and the method is enabled in the PMC,
929+
* for accounts with PMC sync.
929930
*/
930931
public function test_upe_method_enabled() {
931932
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
932933
$stripe_settings['enabled'] = 'yes';
933934
$stripe_settings['test_connection_type'] = 'connect';
935+
$stripe_settings['pmc_enabled'] = 'yes';
934936
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
935937

936-
$this->mock_payment_method_configurations( [ WC_Stripe_Payment_Methods::LINK ], [] );
937-
938-
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
938+
$this->mock_payment_method_configurations( [ WC_Stripe_Payment_Methods::LINK, WC_Stripe_Payment_Methods::CASHAPP_PAY ], [] );
939+
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
940+
$cashapp_upe_method = new WC_Stripe_UPE_Payment_Method_Cash_App_Pay();
941+
$wechat_upe_method = new WC_Stripe_UPE_Payment_Method_Wechat_Pay();
939942
$this->assertTrue( $link_upe_method->is_enabled() );
943+
$this->assertTrue( $cashapp_upe_method->is_enabled() );
944+
$this->assertFalse( $wechat_upe_method->is_enabled() );
940945
}
941946

942947
/**
943-
* Tests that UPE methods are not enabled if Stripe is disabled.
948+
* Tests that UPE methods are not enabled if Stripe is disabled,
949+
* for accounts with PMC sync.
944950
*/
945951
public function test_upe_method_disabled() {
946-
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
947-
$stripe_settings['enabled'] = 'no';
952+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
953+
$stripe_settings['enabled'] = 'no';
954+
$stripe_settings['test_connection_type'] = 'connect';
955+
$stripe_settings['pmc_enabled'] = 'no';
948956
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
949957

950-
$this->mock_payment_method_configurations( [ WC_Stripe_Payment_Methods::LINK ], [] );
951-
952-
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
958+
$this->mock_payment_method_configurations( [ WC_Stripe_Payment_Methods::LINK, WC_Stripe_Payment_Methods::CASHAPP_PAY ], [] );
959+
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
960+
$cashapp_upe_method = new WC_Stripe_UPE_Payment_Method_Cash_App_Pay();
961+
$wechat_upe_method = new WC_Stripe_UPE_Payment_Method_Wechat_Pay();
953962
$this->assertFalse( $link_upe_method->is_enabled() );
963+
$this->assertFalse( $cashapp_upe_method->is_enabled() );
964+
$this->assertFalse( $wechat_upe_method->is_enabled() );
954965
}
955966

956967
/**
957-
* Tests that UPE methods are only enabled if Stripe is enabled and the account is not connected to the platform.
968+
* Tests that UPE methods are only enabled if Stripe is enabled and the method is enabled in the local settings,
969+
* for accounts with no PMC sync.
958970
*/
959-
public function test_upe_method_enabled_for_non_connected_accounts() {
971+
public function test_upe_method_enabled_no_pmc_sync() {
960972
// Enable Stripe and reset the accepted payment methods.
961-
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
962-
$stripe_settings['enabled'] = 'yes';
963-
$stripe_settings['upe_checkout_experience_accepted_payments'] = [];
973+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
974+
$stripe_settings['enabled'] = 'yes';
975+
$stripe_settings['test_connection_type'] = 'connect';
976+
$stripe_settings['pmc_enabled'] = 'no';
977+
$stripe_settings['upe_checkout_experience_accepted_payments'] = [
978+
WC_Stripe_Payment_Methods::LINK,
979+
WC_Stripe_Payment_Methods::CASHAPP_PAY,
980+
];
964981
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
965982

966-
// For each method we'll test the following combinations:
967-
$stripe_enabled_settings = [ 'yes', 'no', '' ];
968-
$upe_method_enabled_options = [ true, false ];
969-
970-
foreach ( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS as $payment_method ) {
971-
foreach ( $stripe_enabled_settings as $stripe_enabled ) {
972-
foreach ( $upe_method_enabled_options as $upe_method_enabled_option ) {
973-
// CARD is always enabled for UPE and non connected accounts.
974-
if ( WC_Stripe_Payment_Methods::CARD === $payment_method::STRIPE_ID && ! $upe_method_enabled_option ) {
975-
continue;
976-
}
977-
978-
// Update the settings.
979-
$stripe_settings['enabled'] = $stripe_enabled;
980-
981-
$payment_method_index = array_search( $payment_method::STRIPE_ID, $stripe_settings['upe_checkout_experience_accepted_payments'] );
982-
if ( $upe_method_enabled_option && false === $payment_method_index ) {
983-
$stripe_settings['upe_checkout_experience_accepted_payments'][] = $payment_method::STRIPE_ID;
984-
} elseif ( ! $upe_method_enabled_option && false !== $payment_method_index ) {
985-
unset( $stripe_settings['upe_checkout_experience_accepted_payments'][ $payment_method_index ] );
986-
}
987-
988-
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
989-
990-
// Verify that the payment method is enabled/disabled.
991-
$payment_method_instance = new $payment_method();
992-
// The UPE method is only enabled if Stripe is enabled and the method is enabled in the settings.
993-
if ( 'yes' === $stripe_enabled && $upe_method_enabled_option ) {
994-
$this->assertTrue( $payment_method_instance->is_enabled() );
995-
} else {
996-
$this->assertFalse( $payment_method_instance->is_enabled() );
997-
}
998-
}
999-
}
1000-
}
983+
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
984+
$cashapp_upe_method = new WC_Stripe_UPE_Payment_Method_Cash_App_Pay();
985+
$wechat_upe_method = new WC_Stripe_UPE_Payment_Method_Wechat_Pay();
986+
$this->assertTrue( $link_upe_method->is_enabled() );
987+
$this->assertTrue( $cashapp_upe_method->is_enabled() );
988+
$this->assertFalse( $wechat_upe_method->is_enabled() );
989+
}
990+
991+
/**
992+
* Tests that UPE methods are only enabled if Stripe is enabled and the method is enabled in the local settings,
993+
* for accounts with no PMC sync.
994+
*/
995+
public function test_upe_method_disabled_no_pmc_sync() {
996+
// Enable Stripe and reset the accepted payment methods.
997+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
998+
$stripe_settings['enabled'] = 'yes';
999+
$stripe_settings['test_connection_type'] = 'connect';
1000+
$stripe_settings['pmc_enabled'] = 'no';
1001+
$stripe_settings['upe_checkout_experience_accepted_payments'] = [
1002+
WC_Stripe_Payment_Methods::LINK,
1003+
WC_Stripe_Payment_Methods::CASHAPP_PAY,
1004+
];
1005+
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
1006+
1007+
$link_upe_method = new WC_Stripe_UPE_Payment_Method_Link();
1008+
$cashapp_upe_method = new WC_Stripe_UPE_Payment_Method_Cash_App_Pay();
1009+
$wechat_upe_method = new WC_Stripe_UPE_Payment_Method_Wechat_Pay();
1010+
$this->assertTrue( $link_upe_method->is_enabled() );
1011+
$this->assertTrue( $cashapp_upe_method->is_enabled() );
1012+
$this->assertFalse( $wechat_upe_method->is_enabled() );
10011013
}
10021014
}

0 commit comments

Comments
 (0)