Closed (fixed)
Project:
QuickPay payment gateway
Version:
7.x-1.4
Component:
quickpay core
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
12 Nov 2012 at 13:28 UTC
Updated:
30 May 2013 at 19:51 UTC
I've had problems when customers pay a non-integer amount, say DKK 50,70. When the payment is registered and processed using the function unwire_amount, only the integer amount (DKK 50) is returned.
So I have changed this function:
public static function unwire_amount($amount, $currency_info) {
if (!is_array($currency_info)) {
$currency_info = Quickpay::currency_info($currency_info);
}
return (function_exists('bcdiv') ?
bcdiv($amount, $currency_info['multiplier']) :
$amount / $currency_info['multiplier']);
}
to:
public static function unwire_amount($amount, $currency_info) {
if (!is_array($currency_info)) {
$currency_info = Quickpay::currency_info($currency_info);
}
return $amount / $currency_info['multiplier'];
}
I am not sure about the idea of using the bcdiv function. But it does cause a problem so I suggest to remove it.
Am I missing something here?
Comments
Comment #1
xen commentedSomething is definitely wrong here.
Bcdiv is "arbitrary precision" division, or in more plain English, a division function that can deal with numbers of any size (and, more importantly for us, any precision).
The reason for using it, is that we can work around floating point rounding errors. Errors which PHP have a nasty habit of hiding from view, until they stick out and bit your arse further down the line.
However, I have an idea as to what could be going wrong here. As the bcdiv doesn't get a precision parameter, it relies on the default, which might be zero in your case (see http://dk.php.net/manual/en/function.bcscale.php for instance).
Do you have the possibility of testing if it works if you use
bcdiv($amount, $currency_info['multiplier'], log10($currency_info['multiplier']))instead of the current bcdiv statement?Comment #2
bjaxelsen commentedThanks .... adding the precision parameter to bcdiv solves the problem :-)
Comment #3
xen commentedGreat, the change is already in the dev version, it'll be part of the next version. Thanks for the report.
Comment #4
xen commented