Skip to content

Commit

Permalink
Merge release/8.0.1 into trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
oaratovskyi committed Jul 31, 2024
2 parents b2714a4 + d360aca commit 35d5f90
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 93 deletions.
3 changes: 3 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
*** WooPayments Changelog ***

= 8.0.1 - 2024-07-31 =
* Fix - Reverts changes related to Direct Checkout that broke the PayPal extension.

= 8.0.0 - 2024-07-31 =
* Add - Add ECE support for multiple product types.
* Add - Add ECE support for WooCommerce Deposits.
Expand Down
6 changes: 1 addition & 5 deletions includes/class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,6 @@ public function needs_https_setup() {
* @return bool Whether the gateway is enabled and ready to accept payments.
*/
public function is_available() {
if ( ! $this->payment_method ) {
return false;
}

$processing_payment_method = $this->payment_methods[ $this->payment_method->get_id() ];
if ( ! $processing_payment_method->is_enabled_at_checkout( $this->get_account_country() ) ) {
return false;
Expand Down Expand Up @@ -908,7 +904,7 @@ public function is_available_for_current_currency() {
$supported_currencies = $this->account->get_account_customer_supported_currencies();
$current_currency = strtolower( get_woocommerce_currency() );

if ( is_null( $supported_currencies ) || ( is_array( $supported_currencies ) && count( $supported_currencies ) === 0 ) ) {
if ( count( $supported_currencies ) === 0 ) {
// If we don't have info related to the supported currencies
// of the country, we won't disable the gateway.
return true;
Expand Down
13 changes: 0 additions & 13 deletions includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,6 @@ public static function is_payment_overview_widget_ui_enabled(): bool {
* @return bool True if Direct Checkout is enabled, false otherwise.
*/
public static function is_woopay_direct_checkout_enabled() {
// If WooPayments is not enabled then disable Direct checkout.
// TODO: Change to WC()->payment_gateways->get_available_payment_gateways() once issue with WC Subscriptions is sorted out.
$wc_payment_gateways = WC_Payment_Gateways::instance();
$wc_payment_gateways->init();
$enabled_gateways = $wc_payment_gateways->payment_gateways();

// Only used for tests.
$enabled_gateways = apply_filters( 'woocommerce_payments_enabled_gateways_for_woopay', $enabled_gateways );

if ( ! isset( $enabled_gateways['woocommerce_payments'] ) || ! $enabled_gateways['woocommerce_payments']->is_available() ) {
return false;
}

$account_cache = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY, true );
$is_direct_checkout_eligible = is_array( $account_cache ) && ( $account_cache['platform_direct_checkout_eligible'] ?? false );
$is_direct_checkout_flag_enabled = '1' === get_option( self::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woocommerce-payments",
"version": "8.0.0",
"version": "8.0.1",
"main": "webpack.config.js",
"author": "Automattic",
"license": "GPL-3.0-or-later",
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: woocommerce payments, apple pay, credit card, google pay, payment, payment
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 7.3
Stable tag: 8.0.0
Stable tag: 8.0.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -94,6 +94,10 @@ Please note that our support for the checkout block is still experimental and th

== Changelog ==

= 8.0.1 - 2024-07-31 =
* Fix - Reverts changes related to Direct Checkout that broke the PayPal extension.


= 8.0.0 - 2024-07-31 =
* Add - Add ECE support for multiple product types.
* Add - Add ECE support for WooCommerce Deposits.
Expand Down
70 changes: 0 additions & 70 deletions tests/unit/test-class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ function ( $key ) {

// Restore the cache service in the main class.
WC_Payments::set_database_cache( $this->_cache );

remove_all_filters( 'woocommerce_payments_enabled_gateways_for_woopay' );

parent::tear_down();
}

Expand Down Expand Up @@ -184,57 +181,33 @@ public function test_are_payments_enabled_returns_false_when_flag_not_set() {
}

public function test_is_woopay_enabled_returns_true() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
$this->assertTrue( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_if_only_woopayments_is_enabled() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

// We are disabling only DC for now. We should disable WooPay if WooPayments is disabled though.
// Leaving this test case so we can catch that later.
public function test_is_woopay_enabled_returns_true_if_woopayments_is_disabled_and_woopay_is_enabled() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'disable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
$this->assertTrue( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_when_express_checkout_flag_is_false() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '0' );
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_when_platform_checkout_flag_is_false() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'no' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_when_ineligible() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => false ] );
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_when_woopayments_is_disabled() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'disable_woopayments' ] );
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_express_checkout_enabled_returns_true() {
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
Expand All @@ -254,7 +227,6 @@ public function test_is_woopay_express_checkout_enabled_returns_false_when_woopa
}

public function test_is_woopay_direct_checkout_enabled_returns_true() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn(
Expand All @@ -263,17 +235,10 @@ public function test_is_woopay_direct_checkout_enabled_returns_true() {
'platform_direct_checkout_eligible' => true,
]
);
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->assertTrue( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
}

public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopayments_is_disabled() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'disable_woopayments' ] );
$this->assertFalse( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
}

public function test_is_woopay_direct_checkout_enabled_returns_false_when_flag_is_false() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '0' );
$this->mock_cache->method( 'get' )->willReturn(
Expand All @@ -286,7 +251,6 @@ public function test_is_woopay_direct_checkout_enabled_returns_false_when_flag_i
}

public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopay_eligible_is_false() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn(
Expand All @@ -299,7 +263,6 @@ public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopay
}

public function test_is_woopay_direct_checkout_enabled_returns_true_when_first_party_auth_is_disabled() {
add_filter( 'woocommerce_payments_enabled_gateways_for_woopay', [ $this, 'enable_woopayments' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_FIRST_PARTY_AUTH_FLAG_NAME, '0' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
Expand All @@ -309,7 +272,6 @@ public function test_is_woopay_direct_checkout_enabled_returns_true_when_first_p
'platform_direct_checkout_eligible' => true,
]
);
WC_Payments::get_gateway()->update_option( 'platform_checkout', 'yes' );
$this->assertTrue( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
}

Expand All @@ -323,38 +285,6 @@ public function test_is_frt_review_feature_active_returns_false_when_flag_is_not
$this->assertFalse( WC_Payments_Features::is_frt_review_feature_active() );
}

public function enable_woopayments( $gateways ) {
return array_map(
function ( $gateway ) {
if ( is_a( $gateway, 'WC_Payment_Gateway' ) && 'woocommerce_payments' === $gateway->id ) {
// Simple class to replace the WC_Payment_Gateway_WCPay instance. With this the `is_available` method will return `true` enabling the payment gateway.
return new class() extends WC_Payment_Gateway_WCPay {
public function __construct() {
}

public function is_available() {
return true;
}
};
}
return $gateway;
},
$gateways
);
}

public function disable_woopayments( $gateways ) {
return array_filter(
$gateways,
function ( $gateway ) {
if ( is_object( $gateway ) && 'woocommerce_payments' === $gateway->id ) {
return false;
}
return true;
}
);
}

private function setup_enabled_flags( array $enabled_flags ) {
foreach ( array_keys( self::FLAG_OPTION_NAME_TO_FRONTEND_KEY_MAPPING ) as $flag ) {
add_filter(
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* WC tested up to: 9.1.2
* Requires at least: 6.0
* Requires PHP: 7.3
* Version: 8.0.0
* Version: 8.0.1
* Requires Plugins: woocommerce
*
* @package WooCommerce\Payments
Expand Down

0 comments on commit 35d5f90

Please sign in to comment.