Skip to content

Commit

Permalink
Merge release/2.8.4 into trunk (#2696) (#2747)
Browse files Browse the repository at this point in the history
* Moved Stripe connection tests to methods that query currencies, making MC work, but only with the default currency until Stripe is connected.
* Update changelogs, add tests for 2696.
* Fix logic error in get_cached_currencies.
* Additional test for Multi-Currency.
  • Loading branch information
naman03malhotra authored Aug 17, 2021
1 parent 06c8288 commit 8c6b569
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** WooCommerce Payments Changelog ***

= 2.8.4 - 2021-xx-xx =
* Fix - Fix database connection error on account cache clear.
* Fix - Fix fatal error logged when updating analytics data when account is not connected to Stripe.
* Fix - Multi-Currency Compatibility fatal error with Subscriptions when account is not connected to Stripe.

= 2.8.3 - 2021-08-10 =
* Fix - Fix for payment request buttons when the new payment methods gateway is enabled.

Expand Down
29 changes: 7 additions & 22 deletions includes/multi-currency/MultiCurrency.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,6 @@ public function __construct( WC_Payments_API_Client $payments_api_client, WC_Pay
* @return void
*/
public function init() {
if ( ! $this->payments_account->is_stripe_connected() ) {
return;
}

$store_currency_updated = $this->check_store_currency_for_change();

// If the store currency has been updated, clear the cache to make sure we fetch fresh rates from the server.
Expand Down Expand Up @@ -248,10 +244,6 @@ public function init() {
* @return void
*/
public function init_rest_api() {
if ( ! $this->payments_account->is_stripe_connected() ) {
return;
}

$api_controller = new RestController( \WC_Payments::create_api_client() );
$api_controller->register_routes();
}
Expand All @@ -262,10 +254,6 @@ public function init_rest_api() {
* @return void
*/
public function init_widgets() {
if ( ! $this->payments_account->is_stripe_connected() ) {
return;
}

$this->currency_switcher_widget = new CurrencySwitcherWidget( $this, $this->compatibility );
register_widget( $this->currency_switcher_widget );
}
Expand Down Expand Up @@ -334,8 +322,8 @@ public function get_cached_currencies() {
return $cache_data;
}

// If connection to server cannot be established, return expired data or null.
if ( ! $this->payments_api_client->is_server_connected() ) {
// If connection to server cannot be established, or if Stripe is not connected, return expired data or null.
if ( ! $this->payments_api_client->is_server_connected() || ! $this->payments_account->is_stripe_connected() ) {
return $cache_data ?? null;
}

Expand Down Expand Up @@ -594,10 +582,6 @@ public function update_selected_currency( string $currency_code ) {
* @return void
*/
public function update_selected_currency_by_url() {
if ( ! $this->payments_account->is_stripe_connected() ) {
return;
}

if ( ! isset( $_GET['currency'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
return;
}
Expand All @@ -611,10 +595,6 @@ public function update_selected_currency_by_url() {
* @return void
*/
public function update_selected_currency_by_geolocation() {
if ( ! $this->payments_account->is_stripe_connected() ) {
return;
}

// We only want to automatically set the currency if it's already not set.
if ( $this->is_using_auto_currency_switching() && ! $this->get_stored_currency_code() ) {
$currency = $this->geolocation->get_currency_by_customer_location();
Expand Down Expand Up @@ -964,6 +944,11 @@ private function remove_currency_settings( $currency ) {
* @return array Array with the available currencies' codes.
*/
private function get_account_available_currencies(): array {
// If Stripe is not connected, return an empty array. This prevents using MC without being connected to Stripe.
if ( ! $this->payments_account->is_stripe_connected() ) {
return [];
}

$wc_currencies = array_keys( get_woocommerce_currencies() );
$account_currencies = $wc_currencies;

Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ Please note that our support for the checkout block is still experimental and th

== Changelog ==

= 2.8.4 - 2021-xx-xx =
* Fix - Align table items according to design correctly.
* Fix - Fix database connection error on account cache clear.
* Fix - Fix fatal error logged when updating analytics data when account is not connected to Stripe.

= 2.8.3 - 2021-08-10 =
* Fix - Fix for payment request buttons when the new payment methods gateway is enabled.

Expand Down
22 changes: 21 additions & 1 deletion tests/unit/multi-currency/test-class-multi-currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ public function test_get_selected_currency_returns_currency_from_user() {
$this->assertSame( 'GBP', $this->multi_currency->get_selected_currency()->get_code() );
}

public function test_get_selected_currency_returns_default_currency_with_no_stripe_account() {
$this->init_multi_currency( null, false );
$this->assertSame( get_woocommerce_currency(), $this->multi_currency->get_selected_currency()->get_code() );
}

public function test_update_selected_currency_does_not_set_invalid_session_currency() {
$this->multi_currency->update_selected_currency( 'UNSUPPORTED_CURRENCY' );

Expand Down Expand Up @@ -620,7 +625,6 @@ public function test_get_cached_currencies_handles_api_exception() {

// Assert that the cache was correctly set with the error expiration time.
$this->assertEquals( time() + MINUTE_IN_SECONDS, get_option( self::CURRENCY_RETRIEVAL_ERROR_OPTION ) );

}

public function test_storefront_integration_init_with_compatible_themes() {
Expand Down Expand Up @@ -702,6 +706,22 @@ public function test_add_order_meta_on_refund() {
$this->assertEquals( '0.724', $refund->get_meta( '_wcpay_multi_currency_stripe_exchange_rate', true ) );
}

public function test_get_cached_currencies_with_no_stripe_connection() {
$this->init_multi_currency( null, false );
$this->assertEquals(
$this->mock_cached_currencies,
$this->multi_currency->get_cached_currencies()
);
}

public function test_get_available_currencies_returns_store_currency_with_no_stripe_connection() {
$expected = [
'USD' => new WCPay\MultiCurrency\Currency( 'USD', 1 ),
];
$this->init_multi_currency( null, false );
$this->assertEquals( $expected, $this->multi_currency->get_available_currencies() );
}

public function get_price_provider() {
return [
[ '5.2499', '0.00', 5.2499 ],
Expand Down

0 comments on commit 8c6b569

Please sign in to comment.