Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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! :)
Comment | File | Size | Author |
---|---|---|---|
#11 | 8145887-10-adding_scale_to_bcmul.patch | 800 bytes | Anonymous (not verified) |
#5 | ogone_2064443_5.patch | 856 bytes | Xano |
#3 | 2064443-2-currencies-sent-to-ogone-have-decimals.patch | 844 bytes | askibinski |
#1 | 2064443-1-currencies-sent-to-ogone-have-decimals.patch | 902 bytes | askibinski |
Comments
Comment #1
askibinski CreditAttribution: askibinski commentedHere is a patch with above code.
I stumbled upon this myself today. Kinda major because ogone does not accept any payments now otherwise.
Comment #3
askibinski CreditAttribution: askibinski commentedThis one should work.
Comment #4
askibinski CreditAttribution: askibinski commentedstatus change...
Comment #5
XanoThis 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.
Comment #6
XanoBump. Can someone review the patch?
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedDid the job for me
Comment #8
XanoThanks for your help!
Comment #10
Anonymous (not verified) CreditAttribution: Anonymous commentedhmm, apparently i'havent tested thoroughly, i've still got the decimals.. scaling the bcmul should do the job
Comment #11
Anonymous (not verified) CreditAttribution: Anonymous commentedComment #12
XanoThis 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 thebcmul()
withpow()
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?
Comment #13
XanoBump.
Comment #14
XanoBump.
Comment #15
XanoClosing due to lack of response. If this problem persists, please open a new issue.