From 87f2c4f3e734484e539b5328fa871ababfc10d48 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 12 Apr 2021 15:23:07 +1200 Subject: [PATCH 1/2] 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 8064029670ca..8a2b58fe384c 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1164,7 +1164,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 9b41cfc801c970293cf2a1a7bff0ff4390219423 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 15 Apr 2021 11:34:44 +1000 Subject: [PATCH 2/2] 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 8a2b58fe384c..e19da90c3a5e 100644 --- a/CRM/Core/Payment.php +++ b/CRM/Core/Payment.php @@ -1164,6 +1164,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']; }