From 9109f75b6c7df25536c7880ffcceb9ba76aabe3b Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 17:57:40 -0300 Subject: [PATCH 01/17] Removing card requirement for OC --- client/blocks/upe/index.js | 42 ++++++++----------- .../payment-method-description.js | 5 --- .../payment-method.js | 5 +-- includes/class-wc-stripe.php | 18 +------- 4 files changed, 21 insertions(+), 49 deletions(-) diff --git a/client/blocks/upe/index.js b/client/blocks/upe/index.js index 12f8a438f6..96936280d7 100644 --- a/client/blocks/upe/index.js +++ b/client/blocks/upe/index.js @@ -5,7 +5,6 @@ import { import { PAYMENT_METHOD_AFFIRM, PAYMENT_METHOD_AMAZON_PAY, - PAYMENT_METHOD_CARD, PAYMENT_METHOD_GIROPAY, PAYMENT_METHOD_KLARNA, PAYMENT_METHOD_LINK, @@ -40,32 +39,25 @@ const api = new WCStripeAPI( const paymentMethodsConfig = getBlocksConfiguration()?.paymentMethodsConfig ?? {}; -// Register UPE Elements. -if ( getBlocksConfiguration()?.isOCEnabled ) { - registerPaymentMethod( - upeElement( PAYMENT_METHOD_CARD, api, paymentMethodsConfig.card ) - ); -} else { - const methodsToFilter = [ - PAYMENT_METHOD_AMAZON_PAY, - PAYMENT_METHOD_LINK, - PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024. - ]; - - // Filter out some BNPLs when other official extensions are present. - if ( getBlocksConfiguration()?.hasAffirmGatewayPlugin ) { - methodsToFilter.push( PAYMENT_METHOD_AFFIRM ); - } - if ( getBlocksConfiguration()?.hasKlarnaGatewayPlugin ) { - methodsToFilter.push( PAYMENT_METHOD_KLARNA ); - } +const methodsToFilter = [ + PAYMENT_METHOD_AMAZON_PAY, + PAYMENT_METHOD_LINK, + PAYMENT_METHOD_GIROPAY, // Skip giropay as it was deprecated by Jun, 30th 2024. +]; - Object.entries( paymentMethodsConfig ) - .filter( ( [ method ] ) => ! methodsToFilter.includes( method ) ) - .forEach( ( [ method, config ] ) => { - registerPaymentMethod( upeElement( method, api, config ) ); - } ); +// Filter out some BNPLs when other official extensions are present. +if ( getBlocksConfiguration()?.hasAffirmGatewayPlugin ) { + methodsToFilter.push( PAYMENT_METHOD_AFFIRM ); } +if ( getBlocksConfiguration()?.hasKlarnaGatewayPlugin ) { + methodsToFilter.push( PAYMENT_METHOD_KLARNA ); +} + +Object.entries( paymentMethodsConfig ) + .filter( ( [ method ] ) => ! methodsToFilter.includes( method ) ) + .forEach( ( [ method, config ] ) => { + registerPaymentMethod( upeElement( method, api, config ) ); + } ); if ( getBlocksConfiguration()?.isECEEnabled ) { // Register Express Checkout Elements. diff --git a/client/settings/general-settings-section/payment-method-description.js b/client/settings/general-settings-section/payment-method-description.js index 026b603a87..42582b0132 100644 --- a/client/settings/general-settings-section/payment-method-description.js +++ b/client/settings/general-settings-section/payment-method-description.js @@ -5,7 +5,6 @@ import RecurringPaymentIcon from '../../components/recurring-payment-icon'; import PaymentMethodCapabilityStatusPill from 'wcstripe/components/payment-method-capability-status-pill'; import PaymentMethodDeprecationPill from 'wcstripe/components/payment-method-deprecation-pill'; import PaymentMethodUnavailableDueConflictPill from 'wcstripe/components/payment-method-unavailable-due-conflict-pill'; -import PaymentMethodRequiredForOCPill from 'wcstripe/components/payment-method-required-for-oc-pill'; const Wrapper = styled.div` display: flex; @@ -75,10 +74,6 @@ const PaymentMethodDescription = ( { id={ id } label={ label } /> - ) } diff --git a/client/settings/general-settings-section/payment-method.js b/client/settings/general-settings-section/payment-method.js index e511c9ffde..98f788e85e 100644 --- a/client/settings/general-settings-section/payment-method.js +++ b/client/settings/general-settings-section/payment-method.js @@ -7,7 +7,7 @@ import interpolateComponents from 'interpolate-components'; import PaymentMethodsMap from '../../payment-methods-map'; import PaymentMethodDescription from './payment-method-description'; import PaymentMethodCheckbox from './payment-method-checkbox'; -import { useIsOCEnabled, useManualCapture } from 'wcstripe/data'; +import { useManualCapture } from 'wcstripe/data'; import { PAYMENT_METHOD_AFFIRM, PAYMENT_METHOD_AFTERPAY_CLEARPAY, @@ -105,7 +105,6 @@ const StyledFees = styled( PaymentMethodFeesPill )` `; const PaymentMethod = ( { method, data } ) => { - const [ isOCEnabled ] = useIsOCEnabled(); const [ isManualCaptureEnabled ] = useManualCapture(); const paymentMethodCurrencies = usePaymentMethodCurrencies( method ); @@ -138,7 +137,7 @@ const PaymentMethod = ( { method, data } ) => { // eslint-disable-next-line camelcase wc_stripe_settings_params.has_klarna_gateway_plugin ); - const isDisabledButChecked = PAYMENT_METHOD_CARD === method && isOCEnabled; + const isDisabledButChecked = false; return (
diff --git a/includes/class-wc-stripe.php b/includes/class-wc-stripe.php index 0fce570c40..1e2037d0d4 100644 --- a/includes/class-wc-stripe.php +++ b/includes/class-wc-stripe.php @@ -865,8 +865,7 @@ public function initialize_status_page() { /** * Toggle payment methods that should be enabled/disabled, e.g. unreleased, - * BNPLs when other official plugins are active, - * cards when the Optimized Checkout is enabled, etc. + * BNPLs when other official plugins are active, etc. * * @return void */ @@ -877,7 +876,6 @@ public function maybe_toggle_payment_methods() { } $payment_method_ids_to_disable = []; - $payment_method_ids_to_enable = []; $enabled_payment_methods = $gateway->get_upe_enabled_payment_method_ids(); // Check for BNPLs that should be deactivated. @@ -892,22 +890,10 @@ public function maybe_toggle_payment_methods() { $this->maybe_deactivate_amazon_pay( $enabled_payment_methods ) ); - // Check if cards should be activated. - // TODO: Remove this once card is not a requirement for the Optimized Checkout. - if ( $gateway->is_oc_enabled() - && ! in_array( WC_Stripe_Payment_Methods::CARD, $enabled_payment_methods, true ) ) { - $payment_method_ids_to_enable[] = WC_Stripe_Payment_Methods::CARD; - } - - if ( [] === $payment_method_ids_to_disable && [] === $payment_method_ids_to_enable ) { + if ( [] === $payment_method_ids_to_disable ) { return; } - $enabled_payment_methods = array_merge( - $enabled_payment_methods, - $payment_method_ids_to_enable - ); - $gateway->update_enabled_payment_methods( array_diff( $enabled_payment_methods, $payment_method_ids_to_disable ) ); From 6dd474bb2af88f6db3c6a7889b843993a9d633f7 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:10:58 -0300 Subject: [PATCH 02/17] Backend changes --- .../payment-methods/class-wc-stripe-upe-payment-gateway.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 11d0f2b29e..0602634c37 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -629,6 +629,12 @@ public function get_upe_enabled_payment_method_ids( $force_refresh = false ) { * @return string[] */ public function get_upe_enabled_at_checkout_payment_method_ids( $order_id = null ) { + // If the Optimized Checkout is enabled, we need to return just the card payment method. + // All payment methods are rendered inside of it. + if ( $this->oc_enabled ) { + return [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ]; + } + $is_automatic_capture_enabled = $this->is_automatic_capture_enabled(); $available_method_ids = []; $account_domestic_currency = WC_Stripe::get_instance()->account->get_account_default_currency(); From bfa1738e0a2d68b0b8c705e76d5421ef1789ff7a Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:19:50 -0300 Subject: [PATCH 03/17] Backend changes --- .../class-wc-stripe-upe-payment-method.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index 0cf3e6e979..21b67d217f 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -175,7 +175,9 @@ public function get_id() { * @return bool */ public function is_enabled() { - return 'yes' === $this->enabled; + return 'yes' === $this->enabled + // When OC is enabled, we use the card payment container to render all the methods. + || ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD === $this->stripe_id ); } /** @@ -185,8 +187,8 @@ public function is_enabled() { */ public function is_available() { // When OC is enabled, we use the card payment container to render all the methods. - if ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD !== $this->stripe_id ) { - return false; + if ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD === $this->stripe_id ) { + return true; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From 074f9fbb4de3b8777e774cd529409cca8b869221 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:20:59 -0300 Subject: [PATCH 04/17] Changelog and readme entries --- changelog.txt | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index c6fabe6c62..9f08708c68 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ *** Changelog *** = 9.8.0 - xxxx-xx-xx = +* Fix - Removes the credit card payment method requirement for the Optimized Checkout feature * Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page * Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form * Fix - Checks for the subscription payment method (if it is Stripe) when verifying for the payment method detachment diff --git a/readme.txt b/readme.txt index 03c8be67ba..99a8bbf0d9 100644 --- a/readme.txt +++ b/readme.txt @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o == Changelog == = 9.8.0 - xxxx-xx-xx = +* Fix - Removes the credit card payment method requirement for the Optimized Checkout feature * Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page * Update - Increases the default font size for the Optimized Checkout payment element to match the rest of the checkout form * Fix - Checks for the subscription payment method (if it is Stripe) when verifying for the payment method detachment From 73d97f432a017e29d4ff6bcb79f592fcc6f442a2 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:30:01 -0300 Subject: [PATCH 05/17] Fix tests --- tests/phpunit/WC_Stripe_Test.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/phpunit/WC_Stripe_Test.php b/tests/phpunit/WC_Stripe_Test.php index ae2e45c6c7..1d6daf4443 100644 --- a/tests/phpunit/WC_Stripe_Test.php +++ b/tests/phpunit/WC_Stripe_Test.php @@ -164,12 +164,6 @@ public function provide_test_maybe_toggle_payment_methods() { 'OC enabled' => false, 'update enable payment methods calls' => 1, ], - 'card, OC enabled' => [ - 'active gateways' => [], - 'enabled payment method IDs' => [], - 'OC enabled' => true, - 'update enable payment methods calls' => 1, - ], ]; } } From a93ecb02ba0458e7c170c816b7b59cf1c6b9e082 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:35:45 -0300 Subject: [PATCH 06/17] Fix tests --- tests/phpunit/WC_Stripe_Test.php | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/phpunit/WC_Stripe_Test.php b/tests/phpunit/WC_Stripe_Test.php index 1d6daf4443..e4d072c8d3 100644 --- a/tests/phpunit/WC_Stripe_Test.php +++ b/tests/phpunit/WC_Stripe_Test.php @@ -29,7 +29,6 @@ public function test_constants_defined() { * * @param array $active_gateways The active payment gateways. * @param array $enabled_payment_method_ids The enabled payment method IDs. - * @param bool $oc_enabled Whether the one-click payment methods are enabled. * @param int $update_enable_payment_methods_calls The number of times `update_enabled_payment_methods` should be called. * @return void * @@ -38,7 +37,6 @@ public function test_constants_defined() { public function test_maybe_toggle_payment_methods( $active_gateways, $enabled_payment_method_ids, - $oc_enabled, $update_enable_payment_methods_calls ) { $original_payment_gateways = WC()->payment_gateways->payment_gateways; @@ -50,10 +48,6 @@ public function test_maybe_toggle_payment_methods( ->disableOriginalConstructor() ->getMock(); - $upe_payment_gateway->expects( $this->once() ) - ->method( 'is_oc_enabled' ) - ->willReturn( $oc_enabled ); - $upe_payment_gateway->expects( $this->once() ) ->method( 'get_upe_enabled_payment_method_ids' ) ->willReturn( $enabled_payment_method_ids ); @@ -88,7 +82,6 @@ public function provide_test_maybe_toggle_payment_methods() { 'enabled payment method IDs' => [ WC_Stripe_Payment_Methods::CARD, ], - 'OC enabled' => false, 'update enable payment methods calls' => 0, ], 'affirm' => [ @@ -102,7 +95,6 @@ public function provide_test_maybe_toggle_payment_methods() { WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::AFFIRM, ], - 'OC enabled' => false, 'update enable payment methods calls' => 1, ], 'klarna' => [ @@ -116,7 +108,6 @@ public function provide_test_maybe_toggle_payment_methods() { WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::KLARNA, ], - 'OC enabled' => false, 'update enable payment methods calls' => 1, ], 'klarna and affirm active, but not on Stripe' => [ @@ -133,7 +124,6 @@ public function provide_test_maybe_toggle_payment_methods() { 'enabled payment method IDs' => [ WC_Stripe_Payment_Methods::CARD, ], - 'OC enabled' => false, 'update enable payment methods calls' => 0, ], 'klarna and affirm active in both' => [ @@ -152,7 +142,6 @@ public function provide_test_maybe_toggle_payment_methods() { WC_Stripe_Payment_Methods::AFFIRM, WC_Stripe_Payment_Methods::KLARNA, ], - 'OC enabled' => false, 'update enable payment methods calls' => 1, ], 'amazon pay' => [ @@ -161,7 +150,6 @@ public function provide_test_maybe_toggle_payment_methods() { WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::AMAZON_PAY, ], - 'OC enabled' => false, 'update enable payment methods calls' => 1, ], ]; From 172e0ed8f1f65c19b382d2e3ff5c6612d7d63313 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:49:17 -0300 Subject: [PATCH 07/17] unit test --- .../WC_Stripe_UPE_Payment_Gateway_Test.php | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php index 5cc8b95dcc..a42ff88f40 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php @@ -311,15 +311,6 @@ public function test_get_upe_available_payment_methods( $country, $available_pay $this->assertSame( $available_payment_methods, $this->mock_gateway->get_upe_available_payment_methods(), "Available payment methods are not the same for $country" ); } - public function test_get_upe_enabled_at_checkout_payment_method_ids() { - $available_payment_methods = [ - WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, - WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, - ]; - $this->mock_payment_method_configurations( $available_payment_methods ); - $this->assertSame( $available_payment_methods, $this->mock_gateway->get_upe_enabled_at_checkout_payment_method_ids() ); - } - public function get_upe_available_payment_methods_provider() { return [ [ @@ -385,6 +376,62 @@ public function get_upe_available_payment_methods_provider() { ]; } + /** + * Tests for `get_upe_enabled_at_checkout_payment_method_ids`. + * + * @param array $available_methods The available payment methods. + * @param bool $oc_enabled Whether the OC feature is enabled. + * @param array $expected The expected payment method IDs. + * @return void + * + * @dataProvider provide_test_get_upe_enabled_at_checkout_payment_method_ids + */ + public function test_get_upe_enabled_at_checkout_payment_method_ids( $available_methods, $oc_enabled, $expected ) { + if ( $oc_enabled ) { + OC_Test_Helper::enable_oc(); + } + + $this->mock_payment_method_configurations( $available_methods ); + + $actual = $this->mock_gateway->get_upe_enabled_at_checkout_payment_method_ids(); + + // Clean up. + OC_Test_Helper::disable_oc(); + + $this->assertSame( $expected, $actual ); + } + + /** + * Data provider for `test_get_upe_enabled_at_checkout_payment_method_ids`. + * + * @return array[] + */ + public function provide_test_get_upe_enabled_at_checkout_payment_method_ids() { + return [ + 'Default' => [ + 'available methods' => [ + WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, + ], + 'OC enabled' => false, + 'expected' => [ + WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, + ], + ], + 'OC enabled' => [ + 'available methods (ignored)' => [ + WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, + ], + 'OC enabled' => true, + 'expected' => [ + WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, + ], + ], + ]; + } + /** * CLASSIC CHECKOUT TESTS. */ From e29852a9de8f75ccb962a22eeac4f8d6ad3c1392 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 11 Aug 2025 18:57:18 -0300 Subject: [PATCH 08/17] Fix tests --- .../PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php index a42ff88f40..f17e384e04 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php @@ -387,16 +387,14 @@ public function get_upe_available_payment_methods_provider() { * @dataProvider provide_test_get_upe_enabled_at_checkout_payment_method_ids */ public function test_get_upe_enabled_at_checkout_payment_method_ids( $available_methods, $oc_enabled, $expected ) { - if ( $oc_enabled ) { - OC_Test_Helper::enable_oc(); - } + $this->mock_gateway->oc_enabled = $oc_enabled; $this->mock_payment_method_configurations( $available_methods ); $actual = $this->mock_gateway->get_upe_enabled_at_checkout_payment_method_ids(); // Clean up. - OC_Test_Helper::disable_oc(); + $this->mock_gateway->oc_enabled = false; $this->assertSame( $expected, $actual ); } From 12c5bbaefb3a1c8f57f11685ed905a65ea6108d8 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 11:35:09 -0300 Subject: [PATCH 09/17] Fix shortcode checkout methods display --- .../payment-methods/class-wc-stripe-upe-payment-method.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index 48385db4b9..fa650dfd09 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -187,8 +187,8 @@ public function is_enabled() { */ public function is_available() { // When OC is enabled, we use the card payment container to render all the methods. - if ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD === $this->stripe_id ) { - return true; + if ( $this->oc_enabled ) { + return WC_Stripe_Payment_Methods::CARD === $this->stripe_id; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From 52464b81f059146bf9ae61f77a5eff6bc64c0d40 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 14:57:09 -0300 Subject: [PATCH 10/17] Removing unnecessary condition --- .../payment-methods/class-wc-stripe-upe-payment-method.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index fa650dfd09..b68a9b4c18 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -175,9 +175,7 @@ public function get_id() { * @return bool */ public function is_enabled() { - return 'yes' === $this->enabled - // When OC is enabled, we use the card payment container to render all the methods. - || ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD === $this->stripe_id ); + return 'yes' === $this->enabled; } /** From 4c5faaafd0340dab427aeae1ce0a86c91c930b79 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 15:03:51 -0300 Subject: [PATCH 11/17] Condition is actually necessary --- .../payment-methods/class-wc-stripe-upe-payment-method.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index b68a9b4c18..fa650dfd09 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -175,7 +175,9 @@ public function get_id() { * @return bool */ public function is_enabled() { - return 'yes' === $this->enabled; + return 'yes' === $this->enabled + // When OC is enabled, we use the card payment container to render all the methods. + || ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD === $this->stripe_id ); } /** From d87a91939bcb20c338920d76d279a7e6148599ce Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Wed, 13 Aug 2025 08:52:39 -0300 Subject: [PATCH 12/17] Removing disabledButChecked prop and related code --- .../general-settings-section/payment-method-checkbox.js | 9 +++------ .../settings/general-settings-section/payment-method.js | 3 --- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/client/settings/general-settings-section/payment-method-checkbox.js b/client/settings/general-settings-section/payment-method-checkbox.js index 4fcb6e27c2..1b660ec42a 100644 --- a/client/settings/general-settings-section/payment-method-checkbox.js +++ b/client/settings/general-settings-section/payment-method-checkbox.js @@ -33,7 +33,6 @@ const PaymentMethodCheckbox = ( { label, isAllowingManualCapture, disabled, - disabledButChecked, } ) => { const [ isManualCaptureEnabled ] = useManualCapture(); const [ isConfirmationModalOpen, setIsConfirmationModalOpen ] = useState( @@ -45,12 +44,10 @@ const PaymentMethodCheckbox = ( { ] = useEnabledPaymentMethodIds(); const [ , setIsStripeEnabled ] = useIsStripeEnabled(); const { isUpeEnabled } = useContext( UpeToggleContext ); - const checked = - ! disabled && - ( disabledButChecked || enabledPaymentMethods.includes( id ) ); + const checked = ! disabled && enabledPaymentMethods.includes( id ); const handleCheckboxChange = ( hasBeenChecked ) => { - if ( disabled || disabledButChecked ) { + if ( disabled ) { return; } if ( ! hasBeenChecked ) { @@ -112,7 +109,7 @@ const PaymentMethodCheckbox = ( { label={ { label } } onChange={ handleCheckboxChange } checked={ checked } - disabled={ disabled || disabledButChecked } + disabled={ disabled } /> ) } { isConfirmationModalOpen && ( diff --git a/client/settings/general-settings-section/payment-method.js b/client/settings/general-settings-section/payment-method.js index 98f788e85e..eccb367ac2 100644 --- a/client/settings/general-settings-section/payment-method.js +++ b/client/settings/general-settings-section/payment-method.js @@ -137,8 +137,6 @@ const PaymentMethod = ( { method, data } ) => { // eslint-disable-next-line camelcase wc_stripe_settings_params.has_klarna_gateway_plugin ); - const isDisabledButChecked = false; - return (
{ label={ label } isAllowingManualCapture={ isAllowingManualCapture } disabled={ deprecated || isDisabled } - disabledButChecked={ isDisabledButChecked } /> Date: Wed, 13 Aug 2025 08:56:24 -0300 Subject: [PATCH 13/17] Removing the required for OC pill and related files --- .../__tests__/index.test.js | 40 --------- .../index.js | 87 ------------------- 2 files changed, 127 deletions(-) delete mode 100644 client/components/payment-method-required-for-oc-pill/__tests__/index.test.js delete mode 100644 client/components/payment-method-required-for-oc-pill/index.js diff --git a/client/components/payment-method-required-for-oc-pill/__tests__/index.test.js b/client/components/payment-method-required-for-oc-pill/__tests__/index.test.js deleted file mode 100644 index 7e0ce41e9a..0000000000 --- a/client/components/payment-method-required-for-oc-pill/__tests__/index.test.js +++ /dev/null @@ -1,40 +0,0 @@ -import React from 'react'; -import { screen, render } from '@testing-library/react'; -import PaymentMethodRequiredForOCPill from '..'; -import { PAYMENT_METHOD_CARD } from 'wcstripe/stripe-utils/constants'; -import { useIsOCEnabled } from 'wcstripe/data'; - -jest.mock( 'wcstripe/data', () => ( { - useIsOCEnabled: jest.fn(), -} ) ); - -describe( 'PaymentMethodRequiredForOCPill', () => { - beforeEach( () => { - useIsOCEnabled.mockReturnValue( [ false, jest.fn() ] ); - } ); - - it( 'should render the "Required for the Optimized Checkout Suite" text', () => { - useIsOCEnabled.mockReturnValue( [ true, jest.fn() ] ); - global.wc_stripe_settings_params = { is_oc_enabled: true }; - - render( - - ); - - expect( screen.queryByText( 'Required' ) ).toBeInTheDocument(); - } ); - - it( 'should not render when OC is not active', () => { - const { container } = render( - - ); - - expect( container.firstChild ).toBeNull(); - } ); -} ); diff --git a/client/components/payment-method-required-for-oc-pill/index.js b/client/components/payment-method-required-for-oc-pill/index.js deleted file mode 100644 index 1ba3c6fe66..0000000000 --- a/client/components/payment-method-required-for-oc-pill/index.js +++ /dev/null @@ -1,87 +0,0 @@ -import { __, sprintf } from '@wordpress/i18n'; -import React from 'react'; -import styled from '@emotion/styled'; -import interpolateComponents from 'interpolate-components'; -import { Icon, info } from '@wordpress/icons'; -import Popover from 'wcstripe/components/popover'; -import { PAYMENT_METHOD_CARD } from 'wcstripe/stripe-utils/constants'; -import { useIsOCEnabled } from 'wcstripe/data'; - -const StyledPill = styled.span` - display: inline-flex; - align-items: center; - gap: 4px; - padding: 4px 8px; - border: 1px solid #fcf9e8; - border-radius: 2px; - background-color: #fcf9e8; - color: #674600; - font-size: 12px; - font-weight: 400; - line-height: 16px; - width: fit-content; -`; - -const StyledLink = styled.a` - &:focus, - &:visited { - box-shadow: none; - } -`; - -const IconWrapper = styled.span` - height: 16px; - cursor: pointer; -`; - -const AlertIcon = styled( Icon )` - fill: #674600; -`; - -const IconComponent = ( { children, ...props } ) => ( - - - { children } - -); - -const PaymentMethodRequiredForOCPill = ( { id, label } ) => { - const [ isOCEnabled ] = useIsOCEnabled(); - if ( id === PAYMENT_METHOD_CARD && isOCEnabled ) { - return ( - - { __( 'Required', 'woocommerce-gateway-stripe' ) } - { - // Stop propagation is necessary so it doesn't trigger the tooltip click event. - ev.stopPropagation(); - } } - /> - ), - }, - } ) } - /> - - ); - } - - return null; -}; - -export default PaymentMethodRequiredForOCPill; From 467aef1d7fe58a2682eabde5e260d394f0622e05 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Thu, 14 Aug 2025 10:20:49 -0300 Subject: [PATCH 14/17] Hide OC container when there are no methods available --- client/blocks/upe/upe-element.js | 14 ++++++++++++++ client/stripe-utils/constants.js | 10 ++++++++++ .../class-wc-stripe-payment-methods.php | 12 ++++++++++++ .../class-wc-stripe-upe-payment-gateway.php | 18 ++++++++++-------- .../class-wc-stripe-upe-payment-method.php | 9 ++++++++- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/client/blocks/upe/upe-element.js b/client/blocks/upe/upe-element.js index a75ebb79ce..bb9c841807 100644 --- a/client/blocks/upe/upe-element.js +++ b/client/blocks/upe/upe-element.js @@ -6,6 +6,8 @@ import { PAYMENT_METHOD_AFTERPAY_CLEARPAY, PAYMENT_METHOD_CLEARPAY, PAYMENT_METHOD_BACS, + PAYMENT_METHOD_CARD, + EXPRESS_PAYMENT_METHODS, } from 'wcstripe/stripe-utils/constants'; import { getBlocksConfiguration } from 'wcstripe/blocks/utils'; import Icons from 'wcstripe/payment-method-icons'; @@ -78,6 +80,18 @@ export const upeElement = ( paymentMethod, api, upeConfig ) => { return false; } + const nonExpressPaymentMethods = upeConfig?.enabledPaymentMethods.filter( + ( method ) => ! EXPRESS_PAYMENT_METHODS.includes( method ) + ); + + if ( + paymentMethod === PAYMENT_METHOD_CARD && + getBlocksConfiguration()?.isOCEnabled && + nonExpressPaymentMethods.length === 0 + ) { + return false; + } + return isAvailableInTheCountry && !! api.getStripe(); }, // see .wc-block-checkout__payment-method styles in blocks/style.scss diff --git a/client/stripe-utils/constants.js b/client/stripe-utils/constants.js index 796085f4b8..1b19e75670 100644 --- a/client/stripe-utils/constants.js +++ b/client/stripe-utils/constants.js @@ -132,6 +132,16 @@ export const EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY = 'applePay'; export const EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY = 'googlePay'; export const EXPRESS_PAYMENT_METHOD_SETTING_LINK = 'link'; +/** + * List of express payment methods + */ +export const EXPRESS_PAYMENT_METHODS = [ + EXPRESS_PAYMENT_METHOD_SETTING_AMAZON_PAY, + EXPRESS_PAYMENT_METHOD_SETTING_APPLE_PAY, + EXPRESS_PAYMENT_METHOD_SETTING_GOOGLE_PAY, + EXPRESS_PAYMENT_METHOD_SETTING_LINK, +]; + /** * List of payment methods that are not recurring */ diff --git a/includes/constants/class-wc-stripe-payment-methods.php b/includes/constants/class-wc-stripe-payment-methods.php index 95fcfab6c4..f2b38e83ad 100644 --- a/includes/constants/class-wc-stripe-payment-methods.php +++ b/includes/constants/class-wc-stripe-payment-methods.php @@ -47,6 +47,18 @@ class WC_Stripe_Payment_Methods { const LINK_LABEL = 'Link'; const PAYMENT_REQUEST_LABEL = 'Payment Request'; + /** + * Payment methods that are considered as express payment methods. + * + * @var array + */ + const EXPRESS_PAYMENT_METHODS = [ + self::AMAZON_PAY, + self::GOOGLE_PAY, + self::APPLE_PAY, + self::LINK, + ]; + /** * Payment methods that are considered as voucher payment methods. * diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 8e4e26d814..5f7fd39343 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -593,8 +593,15 @@ public function javascript_params() { * @return array */ private function get_enabled_payment_method_config() { - $settings = []; - $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + $settings = []; + + // If the Optimized Checkout is enabled, we need to return just the card payment method. + // All payment methods are rendered inside of it. + if ( $this->oc_enabled ) { + $enabled_payment_methods = [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ]; + } else { + $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + } foreach ( $enabled_payment_methods as $payment_method_id ) { $payment_method = $this->payment_methods[ $payment_method_id ]; @@ -607,6 +614,7 @@ private function get_enabled_payment_method_config() { 'showSaveOption' => $this->should_upe_payment_method_show_save_option( $payment_method ), 'supportsDeferredIntent' => $payment_method->supports_deferred_intent(), 'countries' => $payment_method->get_available_billing_countries(), + 'enabledPaymentMethods' => $this->get_upe_enabled_payment_method_ids(), // For the Optimized Checkout. ]; } @@ -629,12 +637,6 @@ public function get_upe_enabled_payment_method_ids( $force_refresh = false ) { * @return string[] */ public function get_upe_enabled_at_checkout_payment_method_ids( $order_id = null ) { - // If the Optimized Checkout is enabled, we need to return just the card payment method. - // All payment methods are rendered inside of it. - if ( $this->oc_enabled ) { - return [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ]; - } - $is_automatic_capture_enabled = $this->is_automatic_capture_enabled(); $available_method_ids = []; $account_domestic_currency = WC_Stripe::get_instance()->account->get_account_default_currency(); diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index fa650dfd09..f705f7746f 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -188,7 +188,14 @@ public function is_enabled() { public function is_available() { // When OC is enabled, we use the card payment container to render all the methods. if ( $this->oc_enabled ) { - return WC_Stripe_Payment_Methods::CARD === $this->stripe_id; + $non_express_payment_methods = array_filter( + $this->get_upe_enabled_payment_method_ids(), + function ( $method ) { + return ! in_array( $method, WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS, true ); + } + ); + // Check if there are any non-express payment methods available (to potentially hide the container). + return WC_Stripe_Payment_Methods::CARD === $this->stripe_id && count( $non_express_payment_methods ) > 0; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From 44973f1b3c665604ec5efc22ea380ad0b0b7a714 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Thu, 14 Aug 2025 15:48:52 -0300 Subject: [PATCH 15/17] Fix merge --- includes/constants/class-wc-stripe-payment-methods.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/includes/constants/class-wc-stripe-payment-methods.php b/includes/constants/class-wc-stripe-payment-methods.php index e8cde1ca96..f2b38e83ad 100644 --- a/includes/constants/class-wc-stripe-payment-methods.php +++ b/includes/constants/class-wc-stripe-payment-methods.php @@ -91,13 +91,6 @@ class WC_Stripe_Payment_Methods { self::WECHAT_PAY, ]; - const EXPRESS_PAYMENT_METHODS = [ - self::AMAZON_PAY, - self::APPLE_PAY, - self::GOOGLE_PAY, - self::LINK, - ]; - /** * List of express payment methods labels. Amazon Pay and Link are not included, * as they have their own payment method classes. From a1062e9058e86a5604fb6dc52d5452a2e9c6d974 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Thu, 14 Aug 2025 15:58:30 -0300 Subject: [PATCH 16/17] Fix tests --- .../PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php index 94425cc422..7501b9a9de 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php @@ -429,6 +429,7 @@ public function provide_test_get_upe_enabled_at_checkout_payment_method_ids() { 'OC enabled' => true, 'expected' => [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, + WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, ], ], ]; From 4cdbfacec35c101639de61f620fb49d54639da6e Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 11:12:46 -0300 Subject: [PATCH 17/17] Fix express methods not available --- .../class-wc-stripe-upe-payment-gateway.php | 14 +++++++++----- .../class-wc-stripe-upe-payment-method.php | 9 +-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 6af39d9428..672e7f933c 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -605,12 +605,16 @@ public function javascript_params() { private function get_enabled_payment_method_config() { $settings = []; - // If the Optimized Checkout is enabled, we need to return just the card payment method. - // All payment methods are rendered inside of it. + $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + + // If the Optimized Checkout is enabled, we need to return just the card payment method + express methods. + // All payment methods are rendered inside the card container. if ( $this->oc_enabled ) { - $enabled_payment_methods = [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ]; - } else { - $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + $enabled_express_methods = array_intersect( + $enabled_payment_methods, + WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS + ); + $enabled_payment_methods = array_merge( [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ], $enabled_express_methods ); } foreach ( $enabled_payment_methods as $payment_method_id ) { diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index f705f7746f..fa650dfd09 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -188,14 +188,7 @@ public function is_enabled() { public function is_available() { // When OC is enabled, we use the card payment container to render all the methods. if ( $this->oc_enabled ) { - $non_express_payment_methods = array_filter( - $this->get_upe_enabled_payment_method_ids(), - function ( $method ) { - return ! in_array( $method, WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS, true ); - } - ); - // Check if there are any non-express payment methods available (to potentially hide the container). - return WC_Stripe_Payment_Methods::CARD === $this->stripe_id && count( $non_express_payment_methods ) > 0; + return WC_Stripe_Payment_Methods::CARD === $this->stripe_id; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) {