From 55302076bec5bbe2ecf2801f46691b8787542809 Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Wed, 18 Sep 2024 14:46:11 +0200 Subject: [PATCH 1/2] refs #47995 use precision according to an order currency --- paypal.php | 15 ++++++++++++--- services/Order/RefundAmountCalculator.php | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/paypal.php b/paypal.php index 3a53cc5a..f9180274 100755 --- a/paypal.php +++ b/paypal.php @@ -2325,12 +2325,21 @@ public function getPartnerInfo() return $response; } - public static function getPrecision() + public static function getPrecision($currency = null) { if (version_compare(_PS_VERSION_, '1.7.7', '<')) { return _PS_PRICE_DISPLAY_PRECISION_; } else { - return Context::getContext()->getComputingPrecision(); + if ($currency instanceof Currency && Validate::isLoadedObject($currency)) { + $context = Context::getContext()->cloneContext(); + $context->currency = $currency; + $precision = $context->getComputingPrecision(); + unset($context); + + return $precision; + } else { + return Context::getContext()->getComputingPrecision(); + } } } @@ -2348,7 +2357,7 @@ public static function getDecimal($isoCurrency = null) $isoCurrency = $paypal->getPaymentCurrencyIso(); } - $precision = self::getPrecision(); + $precision = self::getPrecision(new Currency(Currency::getIdByIsoCode($isoCurrency))); if (in_array($isoCurrency, $currency_wt_decimal) || ($precision == 0)) { return (int) 0; diff --git a/services/Order/RefundAmountCalculator.php b/services/Order/RefundAmountCalculator.php index 1862af29..ab6b9734 100644 --- a/services/Order/RefundAmountCalculator.php +++ b/services/Order/RefundAmountCalculator.php @@ -50,7 +50,7 @@ public function calculate($params) } foreach ($params['productList'] as $product) { - $amount += \Tools::ps_round($product['amount'], PayPal::getPrecision()); + $amount += (float) $product['amount']; } if (false == empty($params['partialRefundShippingCost'])) { From c83de7c19f4aabc49036415dbfe4cfd482ed327f Mon Sep 17 00:00:00 2001 From: bogdan202 Date: Wed, 18 Sep 2024 14:47:06 +0200 Subject: [PATCH 2/2] phpcs --- services/Order/RefundAmountCalculator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/services/Order/RefundAmountCalculator.php b/services/Order/RefundAmountCalculator.php index ab6b9734..bfc15613 100644 --- a/services/Order/RefundAmountCalculator.php +++ b/services/Order/RefundAmountCalculator.php @@ -32,7 +32,6 @@ } use Order; -use PayPal; class RefundAmountCalculator {