Skip to content

Commit

Permalink
Merge pull request #364 from 202ecommerce/bugfix/47995-incorrect-prec…
Browse files Browse the repository at this point in the history
…ision

Bugfix/47995 incorrect precision
  • Loading branch information
bogdan202 authored Sep 27, 2024
2 parents 0771af6 + c83de7c commit 9cb3deb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
15 changes: 12 additions & 3 deletions paypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -2322,12 +2322,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();
}
}
}

Expand All @@ -2345,7 +2354,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;
Expand Down
3 changes: 1 addition & 2 deletions services/Order/RefundAmountCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
}

use Order;
use PayPal;

class RefundAmountCalculator
{
Expand All @@ -50,7 +49,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'])) {
Expand Down

0 comments on commit 9cb3deb

Please sign in to comment.