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

xen’s picture

Something 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?

bjaxelsen’s picture

Thanks .... adding the precision parameter to bcdiv solves the problem :-)

xen’s picture

Great, the change is already in the dev version, it'll be part of the next version. Thanks for the report.

xen’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.