Skip to content

Commit 56e4c27

Browse files
wjrosamalithsen
andauthored
Fix the listing of payment methods on the classic checkout with Optimized Checkout (#4266)
* Fix the listing of payment methods on the classic checkout with Smart Checkout * Adding specific unit test * Fix bad merge * Fix tests * Specific unit tests * Remove group annotation * Changelog and readme entries --------- Co-authored-by: Malith Senaweera <[email protected]>
1 parent 71357a5 commit 56e4c27

File tree

5 files changed

+70
-42
lines changed

5 files changed

+70
-42
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.5.0 - xxxx-xx-xx =
4+
* Fix - Fixes the listing of payment methods on the classic checkout when the Optimized Checkout is enabled.
45
* Fix - Fixes the availability of WeChat Pay when the Optimized Checkout is enabled on the block checkout. Removes it from the classic/shortcode checkout to avoid issues.
56
* Dev - Renames all references to "Smart Checkout" and "Single Payment Element" (and "SPE") to "Optimized Checkout" (and "OC"), following the feature rebranding.
67
* Tweak - Updates the "Smart Checkout" setting name to "Optimized Checkout", and the description accordingly.

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 34 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -179,55 +179,48 @@ public function __construct() {
179179

180180
$main_settings = WC_Stripe_Helper::get_stripe_settings();
181181
$this->oc_enabled = WC_Stripe_Feature_Flags::is_oc_available() && 'yes' === $this->get_option( 'optimized_checkout_element' );
182-
$is_checkout = is_checkout() || has_block( 'woocommerce/checkout' );
183182

184-
if ( $this->oc_enabled && ( $is_checkout || parent::is_valid_pay_for_order_endpoint() || is_add_payment_method_page() ) ) {
185-
$payment_method = new WC_Stripe_UPE_Payment_Method_CC();
186-
$this->payment_methods[ $payment_method->get_id() ] = $payment_method;
187-
} else {
188-
$this->payment_methods = [];
189-
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) {
190-
191-
// Show ACH only if feature is enabled.
192-
if ( WC_Stripe_UPE_Payment_Method_ACH::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_ach_lpm_enabled() ) {
193-
continue;
194-
}
195-
196-
// Show ACSS only if feature is enabled.
197-
if ( WC_Stripe_UPE_Payment_Method_ACSS::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_acss_lpm_enabled() ) {
198-
continue;
199-
}
183+
$this->payment_methods = [];
184+
foreach ( self::UPE_AVAILABLE_METHODS as $payment_method_class ) {
185+
// Show ACH only if feature is enabled.
186+
if ( WC_Stripe_UPE_Payment_Method_ACH::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_ach_lpm_enabled() ) {
187+
continue;
188+
}
200189

201-
// Consider Bacs only if the feature is enabled.
202-
if ( WC_Stripe_UPE_Payment_Method_Bacs_Debit::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
203-
continue;
204-
}
190+
// Show ACSS only if feature is enabled.
191+
if ( WC_Stripe_UPE_Payment_Method_ACSS::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_acss_lpm_enabled() ) {
192+
continue;
193+
}
205194

206-
// Show BECS Debit only if feature is enabled.
207-
if ( WC_Stripe_UPE_Payment_Method_Becs_Debit::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_becs_debit_lpm_enabled() ) {
208-
continue;
209-
}
195+
// Consider Bacs only if the feature is enabled.
196+
if ( WC_Stripe_UPE_Payment_Method_Bacs_Debit::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_bacs_lpm_enabled() ) {
197+
continue;
198+
}
210199

211-
// Show BLIK only if feature is enabled.
212-
if ( WC_Stripe_UPE_Payment_Method_BLIK::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_blik_lpm_enabled() ) {
213-
continue;
214-
}
200+
// Show BECS Debit only if feature is enabled.
201+
if ( WC_Stripe_UPE_Payment_Method_Becs_Debit::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_becs_debit_lpm_enabled() ) {
202+
continue;
203+
}
215204

216-
/** 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.
217-
* Stripe is deprecating Sofort https://support.stripe.com/questions/sofort-is-being-deprecated-as-a-standalone-payment-method.
218-
*/
219-
if ( WC_Stripe_UPE_Payment_Method_Sofort::class === $payment_method_class && ! $is_sofort_enabled ) {
220-
continue;
221-
}
205+
// Show BLIK only if feature is enabled.
206+
if ( WC_Stripe_UPE_Payment_Method_BLIK::class === $payment_method_class && ! WC_Stripe_Feature_Flags::is_blik_lpm_enabled() ) {
207+
continue;
208+
}
222209

223-
// Show giropay only on the orders page to allow refunds. It was deprecated.
224-
if ( WC_Stripe_UPE_Payment_Method_Giropay::class === $payment_method_class && ! $this->is_order_details_page() && ! $this->is_refund_request() ) {
225-
continue;
226-
}
210+
/** 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.
211+
* Stripe is deprecating Sofort https://support.stripe.com/questions/sofort-is-being-deprecated-as-a-standalone-payment-method.
212+
*/
213+
if ( WC_Stripe_UPE_Payment_Method_Sofort::class === $payment_method_class && ! $is_sofort_enabled ) {
214+
continue;
215+
}
227216

228-
$payment_method = new $payment_method_class();
229-
$this->payment_methods[ $payment_method->get_id() ] = $payment_method;
217+
// Show giropay only on the orders page to allow refunds. It was deprecated.
218+
if ( WC_Stripe_UPE_Payment_Method_Giropay::class === $payment_method_class && ! $this->is_order_details_page() && ! $this->is_refund_request() ) {
219+
continue;
230220
}
221+
222+
$payment_method = new $payment_method_class();
223+
$this->payment_methods[ $payment_method->get_id() ] = $payment_method;
231224
}
232225

233226
$this->intent_controller = new WC_Stripe_Intent_Controller();
@@ -1879,7 +1872,6 @@ public function get_stripe_customer_from_order( $order ) {
18791872
* @since 5.6.0
18801873
*/
18811874
public function is_available() {
1882-
18831875
// The main UPE gateway represents the card payment method. So it's only available if the card payment method is enabled and available.
18841876
if ( isset( $this->payment_methods['card'] ) && ( ! $this->payment_methods['card']->is_enabled() || ! $this->payment_methods['card']->is_available() ) ) {
18851877
return false;

includes/payment-methods/class-wc-stripe-upe-payment-method.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public function is_enabled() {
210210
* @return bool
211211
*/
212212
public function is_available() {
213+
// When OC is enabled, we use the card payment container to render all the methods.
214+
if ( $this->oc_enabled && WC_Stripe_Payment_Methods::CARD !== $this->stripe_id ) {
215+
return false;
216+
}
217+
213218
if ( is_add_payment_method_page() && ! $this->is_reusable() ) {
214219
return false;
215220
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.5.0 - xxxx-xx-xx =
114+
* Fix - Fixes the listing of payment methods on the classic checkout when the Optimized Checkout is enabled.
114115
* Fix - Fixes the availability of WeChat Pay when the Optimized Checkout is enabled on the block checkout. Removes it from the classic/shortcode checkout to avoid issues.
115116
* Dev - Renames all references to "Smart Checkout" and "Single Payment Element" (and "SPE") to "Optimized Checkout" (and "OC"), following the feature rebranding.
116117
* Tweak - Updates the "Smart Checkout" setting name to "Optimized Checkout", and the description accordingly.

tests/phpunit/payment-methods/test-class-wc-stripe-upe-payment-method.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,35 @@ public function test_payment_methods_are_reusable_if_cart_contains_subscription(
755755
}
756756
}
757757

758+
/**
759+
* Test that the payment method is available when optimized checkout is enabled.
760+
*
761+
* @return void
762+
*/
763+
public function test_non_card_methods_are_not_available_when_optimized_checkout_is_enabled() {
764+
// Enable optimized checkout.
765+
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
766+
$stripe_settings['single_payment_element'] = 'yes';
767+
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
768+
update_option( WC_Stripe_Feature_Flags::SPE_FEATURE_FLAG_NAME, 'yes' );
769+
770+
$mocked_methods = [
771+
'get_capabilities_response',
772+
'get_woocommerce_currency',
773+
'is_subscription_item_in_cart',
774+
'get_current_order_amount',
775+
'is_inside_currency_limits',
776+
];
777+
778+
// Test for the WeChat payment method.
779+
/** @var WC_Stripe_UPE_Payment_Method_Wechat_Pay $mocked_payment_method */
780+
$mocked_payment_method = $this->getMockBuilder( WC_Stripe_UPE_Payment_Method_Wechat_Pay::class )
781+
->onlyMethods( $mocked_methods )
782+
->getMock();
783+
784+
$this->assertFalse( $mocked_payment_method->is_available() );
785+
}
786+
758787
public function test_payment_methods_support_custom_name_and_description() {
759788
$payment_method_ids = [
760789
WC_Stripe_Payment_Methods::ACH,

0 commit comments

Comments
 (0)