From bd021aee8cb2230cb32462085dac4f8a6d895957 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 12:05:45 -0300 Subject: [PATCH 01/20] Moving OC card method logic to the new single method class --- client/stripe-utils/constants.js | 1 + includes/class-wc-stripe.php | 1 + .../class-wc-stripe-payment-methods.php | 1 + .../class-wc-stripe-upe-payment-gateway.php | 10 +- .../class-wc-stripe-upe-payment-method-cc.php | 31 ------ ...ss-wc-stripe-upe-payment-method-single.php | 96 +++++++++++++++++++ .../class-wc-stripe-upe-payment-method.php | 8 +- 7 files changed, 111 insertions(+), 37 deletions(-) create mode 100644 includes/payment-methods/class-wc-stripe-upe-payment-method-single.php diff --git a/client/stripe-utils/constants.js b/client/stripe-utils/constants.js index 796085f4b8..0feac3c2da 100644 --- a/client/stripe-utils/constants.js +++ b/client/stripe-utils/constants.js @@ -79,6 +79,7 @@ export function getPaymentMethodsConstants() { cashapp: PAYMENT_METHOD_STRIPE_CASHAPP, acss_debit: PAYMENT_METHOD_STRIPE_ACSS, bacs_debit: PAYMENT_METHOD_STRIPE_BACS_DEBIT, + single: PAYMENT_METHOD_STRIPE_CARD, // Default payment method for Optimized Checkout }; } diff --git a/includes/class-wc-stripe.php b/includes/class-wc-stripe.php index 1e2037d0d4..904f71f552 100644 --- a/includes/class-wc-stripe.php +++ b/includes/class-wc-stripe.php @@ -182,6 +182,7 @@ public function init() { require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-wechat-pay.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-acss.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php'; + require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; diff --git a/includes/constants/class-wc-stripe-payment-methods.php b/includes/constants/class-wc-stripe-payment-methods.php index 95fcfab6c4..0c5392ef40 100644 --- a/includes/constants/class-wc-stripe-payment-methods.php +++ b/includes/constants/class-wc-stripe-payment-methods.php @@ -33,6 +33,7 @@ class WC_Stripe_Payment_Methods { const SEPA_DEBIT = 'sepa_debit'; const SOFORT = 'sofort'; const WECHAT_PAY = 'wechat_pay'; + const SINGLE = 'single'; // This is a special case for the Optimized Checkout // Express method constants const AMAZON_PAY = 'amazon_pay'; 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 0602634c37..90f188e176 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -181,7 +181,13 @@ public function __construct() { $this->oc_enabled = WC_Stripe_Feature_Flags::is_oc_available() && 'yes' === $this->get_option( 'optimized_checkout_element' ); $this->payment_methods = []; - foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) { + $upe_available_methods = self::UPE_AVAILABLE_METHODS; + + if ( $this->oc_enabled ) { + $upe_available_methods[] = WC_Stripe_UPE_Payment_Method_Single::class; + } + + foreach ( $upe_available_methods as $payment_method_class ) { /** Show Sofort if it's already enabled. Hide from the new merchants and keep it for the old ones who are already using this gateway, until we remove it completely. * Stripe is deprecating Sofort https://support.stripe.com/questions/sofort-is-being-deprecated-as-a-standalone-payment-method. */ @@ -632,7 +638,7 @@ 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 ]; + return [ WC_Stripe_UPE_Payment_Method_Single::STRIPE_ID ]; } $is_automatic_capture_enabled = $this->is_automatic_capture_enabled(); diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php index f1fd13df72..8cf68c925a 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-cc.php @@ -47,11 +47,6 @@ public function get_title( $payment_details = false ) { return $this->get_card_wallet_type_title( $wallet_type ); } - // Optimized checkout - if ( $this->oc_enabled ) { - return $this->get_optimized_checkout_title( $payment_details ); - } - // Default return parent::get_title(); } @@ -117,10 +112,6 @@ public function requires_automatic_capture() { * @return string */ public function get_testing_instructions( $show_optimized_checkout_instruction = false ) { - if ( $this->oc_enabled && ! $show_optimized_checkout_instruction ) { - return WC_Stripe_UPE_Payment_Gateway::get_testing_instructions_for_optimized_checkout(); - } - return sprintf( /* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */ esc_html__( '%1$sTest mode:%2$s use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ), @@ -149,26 +140,4 @@ private function get_card_wallet_type_title( $express_payment_type ) { return $payment_method_title . WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix(); } - - /** - * Returns the title for the optimized checkout. - * - * @param stdClass|array|bool $payment_details Optional payment details from charge object. - * @return string - */ - private function get_optimized_checkout_title( $payment_details = false ) { - if ( $payment_details ) { // Setting title for the order details page / thank you page. - $payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type ); - - // Avoid potential recursion by checking instance type. This fixes the title on pay for order confirmation page. - return $payment_method instanceof self ? parent::get_title() : $payment_method->get_title(); - } - - // Block checkout and pay for order (checkout) page. - if ( ( has_block( 'woocommerce/checkout' ) || ! empty( $_GET['pay_for_order'] ) ) && ! is_wc_endpoint_url( 'order-received' ) ) { // phpcs:ignore WordPress.Security.NonceVerification - return 'Stripe'; - } - - return parent::get_title(); - } } diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php new file mode 100644 index 0000000000..d644ca3fc7 --- /dev/null +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php @@ -0,0 +1,96 @@ +stripe_id = self::STRIPE_ID; + $this->is_reusable = true; + $this->supports[] = 'subscriptions'; + $this->supports[] = 'tokenization'; + } + + /** + * Returns payment method title + * + * @param stdClass|array|bool $payment_details Optional payment details from charge object. + * + * @return string + */ + public function get_title( $payment_details = false ) { + if ( $payment_details ) { // Setting title for the order details page / thank you page. + $payment_method = WC_Stripe_UPE_Payment_Gateway::get_payment_method_instance( $payment_details->type ); + + // Avoid potential recursion by checking instance type. This fixes the title on pay for order confirmation page. + return $payment_method instanceof self ? parent::get_title() : $payment_method->get_title(); + } + + // Block checkout and pay for order (checkout) page. + if ( ( has_block( 'woocommerce/checkout' ) || ! empty( $_GET['pay_for_order'] ) ) && ! is_wc_endpoint_url( 'order-received' ) ) { // phpcs:ignore WordPress.Security.NonceVerification + return 'Stripe'; + } + + return parent::get_title(); + } + + /** + * Returns string representing payment method type + * to query to retrieve saved payment methods from Stripe. + */ + public function get_retrievable_type() { + return $this->get_id(); + } + + /** + * Returns boolean dependent on whether capability + * for site account is enabled for payment method. + * + * @return bool + */ + public function is_capability_active() { + return true; + } + + /** + * The Credit Card method allows automatic capture. + * + * @inheritDoc + */ + public function requires_automatic_capture() { + return false; + } + + /** + * Returns testing credentials to be printed at checkout in test mode. + * + * @param bool $show_optimized_checkout_instruction Whether this is being called through the Optimized Checkout instructions method. Used to avoid an infinite loop call. + * @return string + */ + public function get_testing_instructions( $show_optimized_checkout_instruction = false ) { + if ( ! $show_optimized_checkout_instruction ) { + return WC_Stripe_UPE_Payment_Gateway::get_testing_instructions_for_optimized_checkout(); + } + + return sprintf( + /* translators: 1) HTML strong open tag 2) HTML strong closing tag 3) HTML anchor open tag 2) HTML anchor closing tag */ + esc_html__( '%1$sTest mode:%2$s use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed %3$shere%4$s.', 'woocommerce-gateway-stripe' ), + '', + '', + '', + '' + ); + } +} 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..9233b9c882 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -176,8 +176,8 @@ public function get_id() { */ 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 ); + // When OC is enabled, we use the single payment container to render all the methods. + || ( $this->oc_enabled && WC_Stripe_Payment_Methods::SINGLE === $this->stripe_id ); } /** @@ -186,9 +186,9 @@ public function is_enabled() { * @return bool */ public function is_available() { - // When OC is enabled, we use the card payment container to render all the methods. + // When OC is enabled, we use the single payment container to render all the methods. if ( $this->oc_enabled ) { - return WC_Stripe_Payment_Methods::CARD === $this->stripe_id; + return WC_Stripe_Payment_Methods::SINGLE === $this->stripe_id; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From 0fd565e74be0875819b11f7ec9c20dcd47863cd5 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 15:09:54 -0300 Subject: [PATCH 02/20] Fix shortcode container label --- client/classic/upe/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/classic/upe/index.js b/client/classic/upe/index.js index 0c2ee9bb60..cfe4c8fb24 100644 --- a/client/classic/upe/index.js +++ b/client/classic/upe/index.js @@ -315,9 +315,9 @@ jQuery( function ( $ ) { // Change the payment method container title when the Optimized Checkout is enabled if ( getStripeServerData()?.isOCEnabled && - $( 'input#payment_method_stripe' ).is( ':checked' ) + $( 'input#payment_method_stripe_single' ).is( ':checked' ) ) { - $( 'label[for=payment_method_stripe]' ).text( 'Stripe' ); + $( 'label[for=payment_method_stripe_single]' ).text( 'Stripe' ); } maybeClearBlikCodeValidation(); From d51e2597b17573e004f558041ef6e0e19aa86bac Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 15:34:45 -0300 Subject: [PATCH 03/20] Moving some methods --- ...ss-wc-stripe-upe-payment-method-single.php | 22 ++++++++++++++++++- .../class-wc-stripe-upe-payment-method.php | 6 ++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php index d644ca3fc7..513c1ebe95 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php @@ -46,9 +46,29 @@ public function get_title( $payment_details = false ) { return parent::get_title(); } + /** + * Returns true if the UPE method is enabled. + * + * @inheritDoc + */ + public function is_enabled() { + return true; + } + + /** + * Returns true if the UPE method is available. + * + * @inheritDoc + */ + public function is_available() { + return true; + } + /** * Returns string representing payment method type * to query to retrieve saved payment methods from Stripe. + * + * @inheritDoc */ public function get_retrievable_type() { return $this->get_id(); @@ -58,7 +78,7 @@ public function get_retrievable_type() { * Returns boolean dependent on whether capability * for site account is enabled for payment method. * - * @return bool + * @inheritDoc */ public function is_capability_active() { return true; 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 9233b9c882..9539faa50f 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 single payment container to render all the methods. - || ( $this->oc_enabled && WC_Stripe_Payment_Methods::SINGLE === $this->stripe_id ); + return 'yes' === $this->enabled; } /** @@ -188,7 +186,7 @@ public function is_enabled() { public function is_available() { // When OC is enabled, we use the single payment container to render all the methods. if ( $this->oc_enabled ) { - return WC_Stripe_Payment_Methods::SINGLE === $this->stripe_id; + return false; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From d51586239dd6e15ee326a5cddc2d16a12807caca Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 15:52:43 -0300 Subject: [PATCH 04/20] Additional fixes --- .../class-wc-stripe-upe-payment-method-single.php | 9 --------- .../class-wc-stripe-upe-payment-method.php | 6 +++++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php index 513c1ebe95..41720277ed 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php @@ -46,15 +46,6 @@ public function get_title( $payment_details = false ) { return parent::get_title(); } - /** - * Returns true if the UPE method is enabled. - * - * @inheritDoc - */ - public function is_enabled() { - return true; - } - /** * Returns true if the UPE method is available. * 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 9539faa50f..83c94fd97c 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -175,6 +175,10 @@ public function get_id() { * @return bool */ public function is_enabled() { + if ( $this->oc_enabled && has_block( 'woocommerce/checkout' ) ) { + return true; + } + return 'yes' === $this->enabled; } @@ -186,7 +190,7 @@ public function is_enabled() { public function is_available() { // When OC is enabled, we use the single payment container to render all the methods. if ( $this->oc_enabled ) { - return false; + return has_block( 'woocommerce/checkout' ); } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From bbf9f22942bbcba5e877bd560e54c991ac75e191 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 15:58:44 -0300 Subject: [PATCH 05/20] Fix add payment method title --- .../class-wc-stripe-upe-payment-method-single.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php index 41720277ed..d5ba8dfdfe 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php @@ -18,6 +18,7 @@ class WC_Stripe_UPE_Payment_Method_Single extends WC_Stripe_UPE_Payment_Method { public function __construct() { parent::__construct(); $this->stripe_id = self::STRIPE_ID; + $this->title = 'Stripe'; $this->is_reusable = true; $this->supports[] = 'subscriptions'; $this->supports[] = 'tokenization'; From db7a42475cdfc8c6090de1f02230729a2a6d5a13 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 16:18:57 -0300 Subject: [PATCH 06/20] Adding specific frontend constant to avoid confusion --- client/stripe-utils/constants.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/stripe-utils/constants.js b/client/stripe-utils/constants.js index 0feac3c2da..6ff090830e 100644 --- a/client/stripe-utils/constants.js +++ b/client/stripe-utils/constants.js @@ -54,6 +54,7 @@ export const PAYMENT_METHOD_STRIPE_CASHAPP = 'stripe_cashapp'; export const PAYMENT_METHOD_STRIPE_ACSS = 'stripe_acss_debit'; export const PAYMENT_METHOD_STRIPE_BACS_DEBIT = 'stripe_bacs_debit'; export const PAYMENT_METHOD_STRIPE_BECS = 'stripe_au_becs_debit'; +export const PAYMENT_METHOD_STRIPE_SINGLE = 'stripe'; export function getPaymentMethodsConstants() { return { @@ -79,7 +80,7 @@ export function getPaymentMethodsConstants() { cashapp: PAYMENT_METHOD_STRIPE_CASHAPP, acss_debit: PAYMENT_METHOD_STRIPE_ACSS, bacs_debit: PAYMENT_METHOD_STRIPE_BACS_DEBIT, - single: PAYMENT_METHOD_STRIPE_CARD, // Default payment method for Optimized Checkout + single: PAYMENT_METHOD_STRIPE_SINGLE, // Default payment method for Optimized Checkout }; } From cc480cea8caec8fbf52f67aec95dd30a88ab3e5c Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 16:21:18 -0300 Subject: [PATCH 07/20] Renaming class to OC --- includes/class-wc-stripe.php | 2 +- .../payment-methods/class-wc-stripe-upe-payment-gateway.php | 4 ++-- ...d-single.php => class-wc-stripe-upe-payment-method-oc.php} | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) rename includes/payment-methods/{class-wc-stripe-upe-payment-method-single.php => class-wc-stripe-upe-payment-method-oc.php} (96%) diff --git a/includes/class-wc-stripe.php b/includes/class-wc-stripe.php index 904f71f552..83d78da484 100644 --- a/includes/class-wc-stripe.php +++ b/includes/class-wc-stripe.php @@ -182,7 +182,7 @@ public function init() { require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-wechat-pay.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-acss.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-amazon-pay.php'; - require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php'; + require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-bancontact.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-sofort.php'; require_once WC_STRIPE_PLUGIN_PATH . '/includes/payment-methods/class-wc-gateway-stripe-giropay.php'; 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 90f188e176..2ffea8e370 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -184,7 +184,7 @@ public function __construct() { $upe_available_methods = self::UPE_AVAILABLE_METHODS; if ( $this->oc_enabled ) { - $upe_available_methods[] = WC_Stripe_UPE_Payment_Method_Single::class; + $upe_available_methods[] = WC_Stripe_UPE_Payment_Method_OC::class; } foreach ( $upe_available_methods as $payment_method_class ) { @@ -638,7 +638,7 @@ 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_Single::STRIPE_ID ]; + return [ WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID ]; } $is_automatic_capture_enabled = $this->is_automatic_capture_enabled(); diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php similarity index 96% rename from includes/payment-methods/class-wc-stripe-upe-payment-method-single.php rename to includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index d5ba8dfdfe..ddc714858c 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-single.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -4,9 +4,9 @@ } /** - * Class WC_Stripe_UPE_Payment_Method_Single + * Class WC_Stripe_UPE_Payment_Method_OC */ -class WC_Stripe_UPE_Payment_Method_Single extends WC_Stripe_UPE_Payment_Method { +class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { const STRIPE_ID = WC_Stripe_Payment_Methods::SINGLE; From 35c4062b4e7db76a0f79519417cf52c44d3aa64e Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Tue, 12 Aug 2025 16:21:51 -0300 Subject: [PATCH 08/20] Improving docs --- .../payment-methods/class-wc-stripe-upe-payment-method-oc.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index ddc714858c..7942497567 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -5,6 +5,8 @@ /** * Class WC_Stripe_UPE_Payment_Method_OC + * + * This class represents the Stripe UPE payment method for the Optimized Checkout (OC) flow. */ class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { From 683e94e97944cea00ec6aaeacfb0ef8a35c3115b Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Wed, 13 Aug 2025 09:36:36 -0300 Subject: [PATCH 09/20] Renaming Single to OC --- client/stripe-utils/constants.js | 4 ++-- includes/constants/class-wc-stripe-payment-methods.php | 2 +- .../payment-methods/class-wc-stripe-upe-payment-method-oc.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/stripe-utils/constants.js b/client/stripe-utils/constants.js index 6ff090830e..5b4bce356c 100644 --- a/client/stripe-utils/constants.js +++ b/client/stripe-utils/constants.js @@ -54,7 +54,7 @@ export const PAYMENT_METHOD_STRIPE_CASHAPP = 'stripe_cashapp'; export const PAYMENT_METHOD_STRIPE_ACSS = 'stripe_acss_debit'; export const PAYMENT_METHOD_STRIPE_BACS_DEBIT = 'stripe_bacs_debit'; export const PAYMENT_METHOD_STRIPE_BECS = 'stripe_au_becs_debit'; -export const PAYMENT_METHOD_STRIPE_SINGLE = 'stripe'; +export const PAYMENT_METHOD_STRIPE_OC = 'stripe'; export function getPaymentMethodsConstants() { return { @@ -80,7 +80,7 @@ export function getPaymentMethodsConstants() { cashapp: PAYMENT_METHOD_STRIPE_CASHAPP, acss_debit: PAYMENT_METHOD_STRIPE_ACSS, bacs_debit: PAYMENT_METHOD_STRIPE_BACS_DEBIT, - single: PAYMENT_METHOD_STRIPE_SINGLE, // Default payment method for Optimized Checkout + oc: PAYMENT_METHOD_STRIPE_OC, // Default payment method for Optimized Checkout }; } diff --git a/includes/constants/class-wc-stripe-payment-methods.php b/includes/constants/class-wc-stripe-payment-methods.php index 0c5392ef40..7a0956a090 100644 --- a/includes/constants/class-wc-stripe-payment-methods.php +++ b/includes/constants/class-wc-stripe-payment-methods.php @@ -33,7 +33,7 @@ class WC_Stripe_Payment_Methods { const SEPA_DEBIT = 'sepa_debit'; const SOFORT = 'sofort'; const WECHAT_PAY = 'wechat_pay'; - const SINGLE = 'single'; // This is a special case for the Optimized Checkout + const OC = 'oc'; // This is a special case for the Optimized Checkout // Express method constants const AMAZON_PAY = 'amazon_pay'; diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index 7942497567..299e9ad502 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -10,7 +10,7 @@ */ class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { - const STRIPE_ID = WC_Stripe_Payment_Methods::SINGLE; + const STRIPE_ID = WC_Stripe_Payment_Methods::OC; const LPM_GATEWAY_CLASS = WC_Gateway_Stripe::class; From f4ddf11454b2f509e9bbb422d6ef4f146aa6fc66 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Wed, 13 Aug 2025 10:46:51 -0300 Subject: [PATCH 10/20] Fix tests --- .../WC_Stripe_UPE_Payment_Gateway_Test.php | 3 +- .../WC_Stripe_UPE_Payment_Method_CC_Test.php | 59 +------------------ 2 files changed, 5 insertions(+), 57 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 f17e384e04..9a523f3121 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php @@ -4,6 +4,7 @@ use Automattic\WooCommerce\Enums\OrderStatus; use Exception; +use WC_Stripe_UPE_Payment_Method_OC; use WooCommerce\Stripe\Tests\Helpers\OC_Test_Helper; use WC_Stripe_Database_Cache; use WC_Stripe_Payment_Method_Configurations; @@ -424,7 +425,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_OC::STRIPE_ID, ], ], ]; diff --git a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_CC_Test.php b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_CC_Test.php index 1e3b0e1464..33680afe11 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_CC_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_CC_Test.php @@ -17,18 +17,13 @@ class WC_Stripe_UPE_Payment_Method_CC_Test extends WP_UnitTestCase { * Tests for `get_title`. * * @param array|bool $payment_details Payment details. - * @param bool $optimized_checkout_setting Optimized Checkout flag. * @param array $query_params Query parameters. * @param string $expected Expected title. * @return void * * @dataProvider provide_test_get_title */ - public function test_get_title( $payment_details, $optimized_checkout_setting, $query_params, $expected ) { - if ( $optimized_checkout_setting ) { - OC_Test_Helper::enable_oc(); - } - + public function test_get_title( $payment_details, $query_params, $expected ) { if ( is_array( $payment_details ) ) { $payment_details = json_decode( wp_json_encode( $payment_details ) ); } @@ -39,9 +34,6 @@ public function test_get_title( $payment_details, $optimized_checkout_setting, $ $payment_method = new WC_Stripe_UPE_Payment_Method_CC(); $actual = $payment_method->get_title( $payment_details ); - // Clean up. - OC_Test_Helper::disable_oc(); - $this->assertEquals( $expected, $actual ); } @@ -52,22 +44,6 @@ public function test_get_title( $payment_details, $optimized_checkout_setting, $ */ public function provide_test_get_title() { return [ - 'optimized checkout, with payment details' => [ - 'payment details' => [ - 'type' => WC_Stripe_Payment_Methods::ALIPAY, - ], - 'optimized checkout flag' => true, - 'query params' => [], - 'expected' => 'Alipay', - ], - 'optimized checkout, block checkout page / pay for order' => [ - 'payment details' => false, - 'optimized checkout flag' => true, - 'query params' => [ - 'pay_for_order' => 'true', - ], - 'expected' => 'Stripe', - ], 'Google Pay' => [ 'payment details' => [ 'card' => [ @@ -76,13 +52,11 @@ public function provide_test_get_title() { ], ], ], - 'optimized checkout flag' => false, 'query params' => [], 'expected' => 'Google Pay (Stripe)', ], 'default, hardcoded' => [ 'payment details' => false, - 'optimized checkout flag' => false, 'query params' => [], 'expected' => 'Credit / Debit Card', ], @@ -92,41 +66,14 @@ public function provide_test_get_title() { /** * Test for `get_testing_instructions`. * - * @param bool $optimized_checkout_setting Optimized Checkout setting. - * @param string $expected Expected instructions. * @return void - * - * @dataProvider provide_test_get_testing_instructions */ - public function test_get_testing_instructions( $optimized_checkout_setting, $expected ) { - if ( $optimized_checkout_setting ) { - OC_Test_Helper::enable_oc(); - } + public function test_get_testing_instructions() { + $expected = 'Test mode: use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed here.'; $payment_method = new WC_Stripe_UPE_Payment_Method_CC(); $actual = $payment_method->get_testing_instructions(); - // Clean up - OC_Test_Helper::disable_oc(); - $this->assertEquals( $expected, $actual ); } - - /** - * Provider for `get_testing_instructions`. - * - * @return array - */ - public function provide_test_get_testing_instructions() { - return [ - 'Optimized Checkout enabled' => [ - 'optimized checkout setting' => true, - 'expected' => '', - ], - 'Optimized Checkout disabled' => [ - 'optimized checkout setting' => false, - 'expected' => 'Test mode: use the test VISA card 4242424242424242 with any expiry date and CVC. Other payment methods may redirect to a Stripe test page to authorize payment. More test card numbers are listed here.', - ], - ]; - } } From ba19a5efd636ddb7fdcff5ec92e9d2253b5832f6 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Wed, 13 Aug 2025 17:30:52 -0300 Subject: [PATCH 11/20] Unit test --- .../class-wc-stripe-upe-payment-method-oc.php | 2 +- .../WC_Stripe_UPE_Payment_Method_OC_Test.php | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_OC_Test.php diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index 299e9ad502..371298032a 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -65,7 +65,7 @@ public function is_available() { * @inheritDoc */ public function get_retrievable_type() { - return $this->get_id(); + return WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID; } /** diff --git a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_OC_Test.php b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_OC_Test.php new file mode 100644 index 0000000000..052b4c822c --- /dev/null +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Method_OC_Test.php @@ -0,0 +1,103 @@ +assertSame( 'Stripe', $payment_method->title ); + $this->assertContains( 'subscriptions', $payment_method->supports ); + $this->assertContains( 'tokenization', $payment_method->supports ); + } + + /** + * Tests for `get_title` method. + * + * @return void + * + * @dataProvider provide_test_get_title + */ + public function test_get_title( $payment_details, $query_params, $expected ) { + if ( is_array( $payment_details ) ) { + $payment_details = json_decode( wp_json_encode( $payment_details ) ); + } + if ( ! empty( $query_params ) ) { + $_GET = array_merge( $_GET, $query_params ); + } + + $payment_method = new WC_Stripe_UPE_Payment_Method_OC(); + $actual = $payment_method->get_title( $payment_details ); + + $this->assertEquals( $expected, $actual ); + } + + /** + * Data provider for `test_get_title`. + * + * @return array + */ + public function provide_test_get_title() { + return [ + 'with payment details' => [ + 'payment details' => [ + 'type' => WC_Stripe_Payment_Methods::ALIPAY, + ], + 'query params' => [], + 'expected' => 'Alipay', + ], + 'block checkout page / pay for order' => [ + 'payment details' => false, + 'query params' => [ + 'pay_for_order' => 'true', + ], + 'expected' => 'Stripe', + ], + 'default, hardcoded' => [ + 'payment details' => false, + 'query params' => [], + 'expected' => 'Stripe', + ], + ]; + } + + /** + * Tests for `is_available`, `get_retrievable_type`, `is_capability_active`, and `requires_automatic_capture` methods. + * @return void + */ + public function test_feature_methods() { + $payment_method = new WC_Stripe_UPE_Payment_Method_OC(); + + $this->assertTrue( $payment_method->is_available() ); + $this->assertEquals( WC_Stripe_Payment_Methods::CARD, $payment_method->get_retrievable_type() ); + $this->assertTrue( $payment_method->is_capability_active() ); + $this->assertFalse( $payment_method->requires_automatic_capture() ); + } + + /** + * Test for `get_testing_instructions`. + * + * @return void + */ + public function test_get_testing_instructions() { + $expected = ''; + + $payment_method = new WC_Stripe_UPE_Payment_Method_OC(); + $actual = $payment_method->get_testing_instructions(); + + $this->assertEquals( $expected, $actual ); + } +} From 1e7c5c03bc2c069a9e19cd8e2e6e5206252e877f Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Wed, 13 Aug 2025 17:34:24 -0300 Subject: [PATCH 12/20] Changelog and readme entries --- changelog.txt | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/changelog.txt b/changelog.txt index 8a05c07469..13a2818300 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,7 @@ *** Changelog *** = 9.8.0 - xxxx-xx-xx = +* Dev - Moves all the Optimized Checkout feature code of the card payment method class to a new, specific class * 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 diff --git a/readme.txt b/readme.txt index 19acc4b0a5..b9cb2a4a3d 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 = +* Dev - Moves all the Optimized Checkout feature code of the card payment method class to a new, specific class * 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 From e1b568db3bcb83218f5623f04b33acd5dd6a0312 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 16:19:23 -0300 Subject: [PATCH 13/20] Removing unnecessary import --- .../PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php | 2 -- 1 file changed, 2 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 bd0eec79e3..0b80295acd 100644 --- a/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php +++ b/tests/phpunit/PaymentMethods/WC_Stripe_UPE_Payment_Gateway_Test.php @@ -4,10 +4,8 @@ use Automattic\WooCommerce\Enums\OrderStatus; use Exception; -use WC_Stripe_UPE_Payment_Method_OC; use WooCommerce\Stripe\Tests\Helpers\OC_Test_Helper; use WC_Stripe_Database_Cache; -use WC_Stripe_Payment_Method_Configurations; use WooCommerce\Stripe\Tests\Helpers\PMC_Test_Helper; use WooCommerce\Stripe\Tests\Helpers\UPE_Test_Helper; use WC_Data_Exception; From b8dcaca8239d80194c8d04d0f7da2c75e2470731 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 17:08:03 -0300 Subject: [PATCH 14/20] Fix payment method unavailable --- .../class-wc-stripe-upe-payment-gateway.php | 5 ++++- .../class-wc-stripe-upe-payment-method-oc.php | 1 + .../class-wc-stripe-upe-payment-method.php | 8 +++----- 3 files changed, 8 insertions(+), 6 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 4c9a30e14e..1938b678db 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -612,6 +612,7 @@ private function get_enabled_payment_method_config() { $settings = []; $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + $enabled_payment_method_ids_for_oc = []; // For the Optimized Checkout. // If the Optimized Checkout is enabled, we need to return just the OC payment method + express methods. // All payment methods are rendered inside the OC container. @@ -621,6 +622,8 @@ private function get_enabled_payment_method_config() { WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS ); $enabled_payment_methods = array_merge( [ WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID ], $enabled_express_methods ); + + $enabled_payment_method_ids_for_oc = $this->get_upe_enabled_payment_method_ids(); } foreach ( $enabled_payment_methods as $payment_method_id ) { @@ -634,7 +637,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. + 'enabledPaymentMethods' => $enabled_payment_method_ids_for_oc, ]; } diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index 371298032a..f8267289ff 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -19,6 +19,7 @@ class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { */ public function __construct() { parent::__construct(); + $this->id = WC_Gateway_Stripe::ID . '_' . WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID; // Force the ID to be the same as the main payment method (card). $this->stripe_id = self::STRIPE_ID; $this->title = 'Stripe'; $this->is_reusable = true; 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 6af977e59c..c095f749ac 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -188,13 +188,11 @@ public function is_enabled() { * @return bool */ public function is_available() { - // When OC is enabled, we use the single payment container to render all the methods. + // When OC is enabled, we use the OC payment container to render all the methods. if ( $this->oc_enabled ) { - $non_express_payment_methods = array_filter( + $non_express_payment_methods = array_diff( $this->get_upe_enabled_payment_method_ids(), - function ( $method ) { - return ! in_array( $method, WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS, true ); - } + WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS ); // Check if there are any non-express payment methods available (to potentially hide the container). return has_block( 'woocommerce/checkout' ) && count( $non_express_payment_methods ) > 0; From eb23e8341985b4f404e9219358b974fb92e767e7 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 17:35:42 -0300 Subject: [PATCH 15/20] Fix payment method unavailable --- .../class-wc-stripe-upe-payment-gateway.php | 16 +++++++++------- .../class-wc-stripe-upe-payment-method-oc.php | 4 ++++ 2 files changed, 13 insertions(+), 7 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 1938b678db..091fbff542 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -611,19 +611,18 @@ public function javascript_params() { private function get_enabled_payment_method_config() { $settings = []; - $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); - $enabled_payment_method_ids_for_oc = []; // For the Optimized Checkout. + $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); + $enabled_method_ids_for_oc = []; // For the Optimized Checkout only. // If the Optimized Checkout is enabled, we need to return just the OC payment method + express methods. // All payment methods are rendered inside the OC container. if ( $this->oc_enabled ) { - $enabled_express_methods = array_intersect( + $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_OC::STRIPE_ID ], $enabled_express_methods ); - - $enabled_payment_method_ids_for_oc = $this->get_upe_enabled_payment_method_ids(); + $enabled_payment_methods = array_merge( [ WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID ], $enabled_express_methods ); + $enabled_method_ids_for_oc = $this->get_upe_enabled_payment_method_ids(); } foreach ( $enabled_payment_methods as $payment_method_id ) { @@ -637,8 +636,11 @@ 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' => $enabled_payment_method_ids_for_oc, ]; + + if ( $this->oc_enabled && WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID === $payment_method_id ) { + $settings[ $payment_method_id ]['enabledPaymentMethods'] = $enabled_method_ids_for_oc; + } } return $settings; diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index f8267289ff..1fbec72db4 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -19,6 +19,10 @@ class WC_Stripe_UPE_Payment_Method_OC extends WC_Stripe_UPE_Payment_Method { */ public function __construct() { parent::__construct(); + $main_settings = WC_Stripe_Helper::get_stripe_settings(); + $is_stripe_enabled = ! empty( $main_settings['enabled'] ) && 'yes' === $main_settings['enabled']; + + $this->enabled = $is_stripe_enabled && $this->oc_enabled ? 'yes' : 'no'; $this->id = WC_Gateway_Stripe::ID . '_' . WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID; // Force the ID to be the same as the main payment method (card). $this->stripe_id = self::STRIPE_ID; $this->title = 'Stripe'; From c0b0db3ca6cdf75e2ad9cb89f8c7a60ac4b194e8 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 17:50:59 -0300 Subject: [PATCH 16/20] Fix method ID --- .../payment-methods/class-wc-stripe-upe-payment-method-oc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php index 1fbec72db4..5f2a3bc52d 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-oc.php @@ -23,7 +23,7 @@ public function __construct() { $is_stripe_enabled = ! empty( $main_settings['enabled'] ) && 'yes' === $main_settings['enabled']; $this->enabled = $is_stripe_enabled && $this->oc_enabled ? 'yes' : 'no'; - $this->id = WC_Gateway_Stripe::ID . '_' . WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID; // Force the ID to be the same as the main payment method (card). + $this->id = WC_Gateway_Stripe::ID; // Force the ID to be the same as the main payment gateway. $this->stripe_id = self::STRIPE_ID; $this->title = 'Stripe'; $this->is_reusable = true; From 738b9e04a57bd1820d6a164716ee67bfecd70fd9 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 17:57:16 -0300 Subject: [PATCH 17/20] Removing unnecessary changes --- .../class-wc-stripe-upe-payment-gateway.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 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 091fbff542..4c9a30e14e 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -611,18 +611,16 @@ public function javascript_params() { private function get_enabled_payment_method_config() { $settings = []; - $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); - $enabled_method_ids_for_oc = []; // For the Optimized Checkout only. + $enabled_payment_methods = $this->get_upe_enabled_at_checkout_payment_method_ids(); // If the Optimized Checkout is enabled, we need to return just the OC payment method + express methods. // All payment methods are rendered inside the OC container. if ( $this->oc_enabled ) { - $enabled_express_methods = array_intersect( + $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_OC::STRIPE_ID ], $enabled_express_methods ); - $enabled_method_ids_for_oc = $this->get_upe_enabled_payment_method_ids(); + $enabled_payment_methods = array_merge( [ WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID ], $enabled_express_methods ); } foreach ( $enabled_payment_methods as $payment_method_id ) { @@ -636,11 +634,8 @@ 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. ]; - - if ( $this->oc_enabled && WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID === $payment_method_id ) { - $settings[ $payment_method_id ]['enabledPaymentMethods'] = $enabled_method_ids_for_oc; - } } return $settings; From 816722242789ba6525c16dc1734822ed22bfb0fa Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 18:07:31 -0300 Subject: [PATCH 18/20] Revert unnecessary changes --- client/classic/upe/index.js | 4 ++-- .../class-wc-stripe-upe-payment-gateway.php | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/client/classic/upe/index.js b/client/classic/upe/index.js index cfe4c8fb24..0c2ee9bb60 100644 --- a/client/classic/upe/index.js +++ b/client/classic/upe/index.js @@ -315,9 +315,9 @@ jQuery( function ( $ ) { // Change the payment method container title when the Optimized Checkout is enabled if ( getStripeServerData()?.isOCEnabled && - $( 'input#payment_method_stripe_single' ).is( ':checked' ) + $( 'input#payment_method_stripe' ).is( ':checked' ) ) { - $( 'label[for=payment_method_stripe_single]' ).text( 'Stripe' ); + $( 'label[for=payment_method_stripe]' ).text( 'Stripe' ); } maybeClearBlikCodeValidation(); 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 4c9a30e14e..c35a7a4e05 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -181,13 +181,7 @@ public function __construct() { $this->oc_enabled = WC_Stripe_Feature_Flags::is_oc_available() && 'yes' === $this->get_option( 'optimized_checkout_element' ); $this->payment_methods = []; - $upe_available_methods = self::UPE_AVAILABLE_METHODS; - - if ( $this->oc_enabled ) { - $upe_available_methods[] = WC_Stripe_UPE_Payment_Method_OC::class; - } - - foreach ( $upe_available_methods as $payment_method_class ) { + foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) { /** Show Sofort if it's already enabled. Hide from the new merchants and keep it for the old ones who are already using this gateway, until we remove it completely. * Stripe is deprecating Sofort https://support.stripe.com/questions/sofort-is-being-deprecated-as-a-standalone-payment-method. */ From a492833bdd72ccd4bbb0dbfbfc55ccfb1a6c9781 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 18:26:36 -0300 Subject: [PATCH 19/20] Simplifying logic --- .../class-wc-stripe-upe-payment-gateway.php | 5 ++++- .../class-wc-stripe-upe-payment-method.php | 15 ++++----------- 2 files changed, 8 insertions(+), 12 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 c35a7a4e05..206b773616 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -618,7 +618,10 @@ private function get_enabled_payment_method_config() { } foreach ( $enabled_payment_methods as $payment_method_id ) { - $payment_method = $this->payment_methods[ $payment_method_id ]; + // For the Optimized Checkout, we use the OC payment method class. + $payment_method = $this->oc_enabled && WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID === $payment_method_id + ? new WC_Stripe_UPE_Payment_Method_OC() + : $this->payment_methods[ $payment_method_id ]; $settings[ $payment_method_id ] = [ 'isReusable' => $payment_method->is_reusable(), 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 c095f749ac..d29859b915 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -175,11 +175,9 @@ public function get_id() { * @return bool */ public function is_enabled() { - if ( $this->oc_enabled && has_block( 'woocommerce/checkout' ) ) { - return true; - } - - return 'yes' === $this->enabled; + return 'yes' === $this->enabled + // When OC is enabled, we use the OC payment container to render all the methods. + || ( $this->oc_enabled && WC_Stripe_Payment_Methods::OC === $this->stripe_id ); } /** @@ -190,12 +188,7 @@ public function is_enabled() { public function is_available() { // When OC is enabled, we use the OC payment container to render all the methods. if ( $this->oc_enabled ) { - $non_express_payment_methods = array_diff( - $this->get_upe_enabled_payment_method_ids(), - WC_Stripe_Payment_Methods::EXPRESS_PAYMENT_METHODS - ); - // Check if there are any non-express payment methods available (to potentially hide the container). - return has_block( 'woocommerce/checkout' ) && count( $non_express_payment_methods ) > 0; + return WC_Stripe_Payment_Methods::OC === $this->stripe_id; } if ( is_add_payment_method_page() && ! $this->is_reusable() ) { From d72583063b10a1bd0fbae98d7469ded4c8c0eb68 Mon Sep 17 00:00:00 2001 From: Wesley Rosa Date: Mon, 18 Aug 2025 18:41:43 -0300 Subject: [PATCH 20/20] Simplifying logic --- includes/constants/class-wc-stripe-payment-methods.php | 2 +- .../payment-methods/class-wc-stripe-upe-payment-gateway.php | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/includes/constants/class-wc-stripe-payment-methods.php b/includes/constants/class-wc-stripe-payment-methods.php index f879dfd1ca..a42936405a 100644 --- a/includes/constants/class-wc-stripe-payment-methods.php +++ b/includes/constants/class-wc-stripe-payment-methods.php @@ -33,7 +33,7 @@ class WC_Stripe_Payment_Methods { const SEPA_DEBIT = 'sepa_debit'; const SOFORT = 'sofort'; const WECHAT_PAY = 'wechat_pay'; - const OC = 'oc'; // This is a special case for the Optimized Checkout + const OC = 'card'; // This is a special case for the Optimized Checkout // Express method constants const AMAZON_PAY = 'amazon_pay'; 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 206b773616..c35a7a4e05 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -618,10 +618,7 @@ private function get_enabled_payment_method_config() { } foreach ( $enabled_payment_methods as $payment_method_id ) { - // For the Optimized Checkout, we use the OC payment method class. - $payment_method = $this->oc_enabled && WC_Stripe_UPE_Payment_Method_OC::STRIPE_ID === $payment_method_id - ? new WC_Stripe_UPE_Payment_Method_OC() - : $this->payment_methods[ $payment_method_id ]; + $payment_method = $this->payment_methods[ $payment_method_id ]; $settings[ $payment_method_id ] = [ 'isReusable' => $payment_method->is_reusable(),