Skip to content

Commit

Permalink
Hide Sofort from the settings page when it's disabled and UPE is enab…
Browse files Browse the repository at this point in the history
…led (#2873)

* Hide sofort on the settings page when disabled for UPE

* Adjust tests not to expect Sofort in the available payment methods
  • Loading branch information
a-danae authored Feb 13, 2024
1 parent dc88174 commit f7f7e12
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
13 changes: 12 additions & 1 deletion includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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'];

Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
Expand All @@ -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,
],
],
];
Expand Down

0 comments on commit f7f7e12

Please sign in to comment.