Hi!

When the amount is sent to Ogone it contains 2 decimals.
Ogone fails to process and gives the following error:
amount too long or not numeric: length 6 MAX:15

E.g. for 100 euro: 100,00 is sent, but it should be 10000

Problem is located in the redirectData function where amount is rounded.

function redirectData(Payment $payment) {
    ....
    $data = array(
      'AMOUNT' => currency_load($payment->currency_code)->roundAmount($payment->totalAmount(TRUE)),
      'PSPID' => $payment->method->controller_data['pspid'],
...
}

In the development version before issue 1955396 the amount was multiplied by 100.
The following change should also work for currencies with more than 2 decimals!

 ...
$currency = currency_load($payment->currency_code);    
$data = array(
   'AMOUNT' => $currency->roundAmount($payment->totalAmount(TRUE)) / $currency->getRoundingStep(),
...

Hope this helps! :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

askibinski’s picture

Priority: Normal » Major
Status: Active » Needs review
FileSize
902 bytes

Here is a patch with above code.

I stumbled upon this myself today. Kinda major because ogone does not accept any payments now otherwise.

Status: Needs review » Needs work

The last submitted patch, 2064443-1-currencies-sent-to-ogone-have-decimals.patch, failed testing.

askibinski’s picture

This one should work.

askibinski’s picture

Status: Needs work » Needs review

status change...

Xano’s picture

FileSize
856 bytes
+++ b/ogone/includes/OgonePaymentMethodController.inc
@@ -484,8 +484,9 @@ class OgonePaymentMethodController extends PaymentMethodController {
+      'AMOUNT' => $currency->roundAmount($payment->totalAmount(TRUE)) / $currency->getRoundingStep(),

This is a float division. Seeing as we use Currency anyway, we might as well use BC Math for this too. Also, the rounding step is configurable and as such cannot be used to 'move the comma'.

The patch uses the calculated number of decimals to find out how much to 'move the comma' and uses BC Math to perform the actual calculation.

Xano’s picture

Bump. Can someone review the patch?

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Did the job for me

Xano’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your help!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs review

hmm, apparently i'havent tested thoroughly, i've still got the decimals.. scaling the bcmul should do the job

Anonymous’s picture

Xano’s picture

Status: Needs review » Needs work

This is not a fix to the original problem. Provided the currency is configured correctly, $currency->roundAmount() should make sure there are not too many decimals, and the bcmul() with pow() should simply move the comma.

Can you make sure the number of subunits is correctly set for the currency you are using and can you paste the expected and actual values here?

Xano’s picture

Bump.

Xano’s picture

Bump.

Xano’s picture

Status: Needs work » Closed (fixed)

Closing due to lack of response. If this problem persists, please open a new issue.