I noticed in testing that the amount sent through was sometimes 3499 or 2499 etc these are cents values.
the actual amount displayed and recorded on drupal for these values was $35.00 or $25.00, but the cents value was sent to securepay.

The problem seems to be the amount value passed to the function: _uc_securepayau_charge($order, $amount, $data);
has a very large precision ie 34.9999 or something like that, so I believe by rounding these and then changing it to cents should work.

There is a function called: function uc_price($price_info, $context, $options = array()) in uc_store/includes/uc_price.inc, that we could use, however on my test I could not get it to work correctly even after telling it to give me a precision of 2 I still got a precision of 6, not sure why this was the case... more testing needed.

Anyway to solve my issue I simply used number_format where the amount is calculated, this rounded it for me and solved my problem, i am sure that round() would do the same, I just chose number_format hoping it would be a little more accurate than round see comments on round() on php.net
so I change line: 153 on uc_securepayau.module in the 6.x-1.x-dev version -

'amount' => (int)(number_format($amount,2)*100), // amount takes a value in cents

Let me know your thoughts...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dsobon’s picture

Priority: Normal » Major
FileSize
644 bytes

Patch included.

I can confirm the problem occurs (if the uc amount is 0.9999), and the recommended change resolves the problem.

Now I wonder how long it will take to merge this patch.

dsobon’s picture

Unfortunately for amounts larger than 999.99, number_format() uses "," as a thousands separator by default.

Updated patch.