From 56c11110b9067b30496d4ccb7bd3358d2758f607 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Apr 2021 15:23:07 +1200 Subject: [PATCH 1/3] dev/core#2493 Stop attempting to format money in the processor class We've said this is wrong before but it has survived until now because it seemed scarier to change it. However, now the reverse seems true. The value in amount should always be machine friendly and there are no known processors that expect locale specific formatting. On the other hand the format() function is intended to prepare money for DISPLAY which is not what is going on here --- CRM/Core/Payment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 74892574f8de..491ad8939b42 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1174,7 +1174,7 @@ protected function getCurrency($params = []) { * @throws \CRM_Core_Exception */ protected function getAmount($params = []) { - return CRM_Utils_Money::format($params['amount'], NULL, NULL, TRUE); + return $params['amount']; } /** From 2ae78644145a1a2f4256e151cfc5d5878eca9ec5 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 15 Apr 2021 11:34:44 +1000 Subject: [PATCH 2/3] Add in deprecated warning if amount is not numeric and use filter var to return appropriate amount in that case otherwise just return amount --- CRM/Core/Payment.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 491ad8939b42..86ea55a019fc 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1174,6 +1174,10 @@ protected function getCurrency($params = []) { * @throws \CRM_Core_Exception */ protected function getAmount($params = []) { + if (!CRM_Utils_Rule::numeric($params['amount'])) { + CRM_Core_Error::deprecatedWarning('Passing Amount value that is not numeric is deprecated please report this in gitlab'); + return filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); + } return $params['amount']; } From 6c990cc907aea7e7a9eac0134e1ed9ef1800f086 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 16 Apr 2021 08:01:23 +1000 Subject: [PATCH 3/3] REF Ensure that getAmount includes 0s in decimal places up to 2 places --- CRM/Core/Payment.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CRM/Core/Payment.php b/CRM/Core/Payment.php index 86ea55a019fc..3d694b7d5460 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1176,9 +1176,9 @@ protected function getCurrency($params = []) { protected function getAmount($params = []) { if (!CRM_Utils_Rule::numeric($params['amount'])) { CRM_Core_Error::deprecatedWarning('Passing Amount value that is not numeric is deprecated please report this in gitlab'); - return filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); + return CRM_Utils_Money::formatLocaleNumericRoundedByPrecision(filter_var($params['amount'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION), 2); } - return $params['amount']; + return CRM_Utils_Money::formatLocaleNumericRoundedByPrecision($params['amount'], 2); } /**