Novalnet-AG / contao-isotope-payment-integration-novalnet

Contao Isotope Payment Bundle by Novalnet
0 stars 2 forks source link

Fix orders with amounts greater than 999 only charging 1.00 #4

Closed fritzmg closed 1 year ago

fritzmg commented 1 year ago

Currently there is a critical error in the extension if the total of the payment exceeds 999.99. In that case the customer is only charged 1.00 USD/EUR/etc.

The reason is that number_format is used in order to transform the total number to a maximum of two decimal places. However, PHP's number_format will by default introduce a thousands separator. So for example, if the total amount is 1117

number_format($order->getTotal(), 2)

will result in

'1,117.00'

This then cannot be parsed as a number by PHP anymore and thus it is interpreted as 1 instead when casting to an integer or float by the multiplication operation.

This PR fixes that by using floor($order->getTotal() * 100) instead.

fritzmg commented 1 year ago

@Novalnet-Technic it has been brought to my attention (externally) that this error could not be reproduced on your end. Though I do not see how that can be the case. These are the original code lines:

https://github.com/Novalnet-AG/Contao-isotope-payment-integration-novalnet/blob/a90f037cbe13e2914c983e4586c98a9674645a2c/src/Helper/NovalnetHelper.php#L190-L199

You can see this code in action here, where I have replaced the function calls with static values - e.g. $order->getTotal() returns 1171.0 in my example: https://3v4l.org/YmGEk

As you can see the value of "amount" is int(100) instead of int(117100) - i.e. the customer is only charged 1.00 EURO instead of 1171.00 EURO.