From 8b2da266fb50b3ec3e2549e3b14f8bae6a5bc87d Mon Sep 17 00:00:00 2001 From: deepakpathania Date: Tue, 24 Dec 2024 17:17:14 +0530 Subject: [PATCH] Address review comments --- includes/class-wc-payments-order-service.php | 3 --- includes/multi-currency/MultiCurrency.php | 4 +++- ...wc-payments-webhook-processing-service.php | 24 +++++++++++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/includes/class-wc-payments-order-service.php b/includes/class-wc-payments-order-service.php index b57acf5e23c..eb74cde866f 100644 --- a/includes/class-wc-payments-order-service.php +++ b/includes/class-wc-payments-order-service.php @@ -1930,9 +1930,6 @@ private function complete_order_processing( $order, $intent_status = null ) { private function get_order_amount( $order ) { $multi_currency_instance = WC_Payments_Multi_Currency(); $order_price = $order->get_total(); - if ( ! $order_price ) { - return $order_price; - } $formatted_price = $multi_currency_instance->get_backend_formatted_wc_price( $order_price, [ 'currency' => $order->get_currency() ] ); return WC_Payments_Explicit_Price_Formatter::get_explicit_price( $formatted_price, $order ); diff --git a/includes/multi-currency/MultiCurrency.php b/includes/multi-currency/MultiCurrency.php index 1db73f1e322..c177d253978 100644 --- a/includes/multi-currency/MultiCurrency.php +++ b/includes/multi-currency/MultiCurrency.php @@ -17,6 +17,7 @@ use WCPay\MultiCurrency\Logger; use WCPay\MultiCurrency\Notes\NoteMultiCurrencyAvailable; use WCPay\MultiCurrency\Utils; +use WC_Payments_Features; defined( 'ABSPATH' ) || exit; @@ -1335,7 +1336,8 @@ public function is_initialized(): bool { * @return string The formatted amount. */ public function get_backend_formatted_wc_price( float $amount, array $args = [] ): string { - if ( ! self::has_additional_currencies_enabled() ) { + // Return early if MC isn't enabled or merchant has a single currency. + if ( ! self::has_additional_currencies_enabled() || ! WC_Payments_Features::is_customer_multi_currency_enabled() ) { return wc_price( $amount, $args ); } diff --git a/tests/unit/test-class-wc-payments-webhook-processing-service.php b/tests/unit/test-class-wc-payments-webhook-processing-service.php index 2acb5c318ad..e628c533848 100644 --- a/tests/unit/test-class-wc-payments-webhook-processing-service.php +++ b/tests/unit/test-class-wc-payments-webhook-processing-service.php @@ -652,6 +652,10 @@ public function test_payment_intent_successful_and_completes_order() { ->expects( $this->exactly( 2 ) ) ->method( 'save' ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->exactly( 2 ) ) ->method( 'has_status' ) @@ -747,6 +751,10 @@ public function test_payment_intent_successful_and_completes_order_without_inten ->expects( $this->exactly( 2 ) ) ->method( 'save' ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->exactly( 2 ) ) ->method( 'has_status' ) @@ -939,6 +947,10 @@ public function test_payment_intent_successful_and_send_card_reader_receipt() { ) ->willReturn( false ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->once() ) ->method( 'payment_complete' ); @@ -1040,6 +1052,10 @@ public function test_payment_intent_successful_and_save_mandate() { [ '_intention_status', $intent_status ] ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->exactly( 2 ) ) ->method( 'save' ); @@ -1123,6 +1139,10 @@ public function test_payment_intent_fails_and_fails_order() { ->with( '_payment_method_id' ) ->willReturn( 'pm_123123123123123' ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->exactly( 3 ) ) ->method( 'has_status' ) @@ -1190,6 +1210,10 @@ public function test_payment_intent_without_charges_fails_and_fails_order() { ->with( '_payment_method_id' ) ->willReturn( 'pm_123123123123123' ); + $this->mock_order + ->method( 'get_total' ) + ->willReturn( 15.00 ); + $this->mock_order ->expects( $this->exactly( 3 ) ) ->method( 'has_status' )