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 50c1c59c26..40df744c59 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -127,8 +127,19 @@ public function __construct() { 'add_payment_method', ]; + $enabled_payment_methods = $this->get_upe_enabled_payment_method_ids(); + $is_sofort_enabled = in_array( 'sofort', $enabled_payment_methods, true ); + $this->payment_methods = []; 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. + */ + if ( WC_Stripe_UPE_Payment_Method_Sofort::class === $payment_method_class && ! $is_sofort_enabled ) { + continue; + } + $payment_method = new $payment_method_class(); $this->payment_methods[ $payment_method->get_id() ] = $payment_method; } @@ -160,7 +171,7 @@ public function __construct() { // When feature flags are enabled, title shows the count of enabled payment methods in settings page only. if ( WC_Stripe_Feature_Flags::is_upe_checkout_enabled() && WC_Stripe_Feature_Flags::is_upe_preview_enabled() && isset( $_GET['page'] ) && 'wc-settings' === $_GET['page'] ) { - $enabled_payment_methods_count = count( $this->get_upe_enabled_payment_method_ids() ); + $enabled_payment_methods_count = count( $enabled_payment_methods ); $this->title = $enabled_payment_methods_count ? /* translators: $1. Count of enabled payment methods. */ sprintf( _n( '%d payment method', '%d payment methods', $enabled_payment_methods_count, 'woocommerce-gateway-stripe' ), $enabled_payment_methods_count ) diff --git a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php index ca7d45fb6f..1223975e61 100644 --- a/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php +++ b/tests/phpunit/admin/test-class-wc-rest-stripe-settings-controller.php @@ -290,13 +290,7 @@ public function test_get_settings_returns_available_payment_method_ids() { ); $response = $this->rest_get_settings(); - $expected_method_ids = WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS; - $expected_method_ids = array_map( - function ( $method_class ) { - return $method_class::STRIPE_ID; - }, - $expected_method_ids - ); + $expected_method_ids = array_keys( $this->get_gateway()->payment_methods ); $available_method_ids = $response->get_data()['available_payment_method_ids']; @@ -323,19 +317,11 @@ public function test_get_settings_returns_ordered_payment_method_ids() { ); $response = $this->rest_get_settings(); - $expected_method_ids = WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS; - $expected_method_ids = array_map( - function ( $method_class ) { - return $method_class::STRIPE_ID; - }, - $expected_method_ids - ); - $expected_method_ids = array_filter( - $expected_method_ids, - function ( $method_id ) { - return 'link' !== $method_id; - } - ); + $expected_methods = $this->get_gateway()->payment_methods; + + unset( $expected_methods['link'] ); + + $expected_method_ids = array_keys( $expected_methods ); $ordered_method_ids = $response->get_data()['ordered_payment_method_ids']; diff --git a/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php b/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php index f9793f4548..bd683a4045 100644 --- a/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php +++ b/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php @@ -235,7 +235,6 @@ public function get_upe_available_payment_methods_provider() { WC_Stripe_UPE_Payment_Method_Oxxo::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID, WC_Stripe_UPE_Payment_Method_P24::STRIPE_ID, - WC_Stripe_UPE_Payment_Method_Sofort::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID, ], ], @@ -251,7 +250,6 @@ public function get_upe_available_payment_methods_provider() { WC_Stripe_UPE_Payment_Method_Oxxo::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID, WC_Stripe_UPE_Payment_Method_P24::STRIPE_ID, - WC_Stripe_UPE_Payment_Method_Sofort::STRIPE_ID, ], ], ];