PAYONE-GmbH / magento-1

PAYONE Payment Extension for Magento 1
22 stars 41 forks source link

MAGE-470: Fix aborted Amazon Pay checkouts #407

Closed phoenix-schwarz closed 4 years ago

phoenix-schwarz commented 4 years ago

Under some circumstances, there is the error "Sorry, your transaction with Amazon Pay was not successful. Please try again." thrown, even if the values seem to be identical. After implementing a logging, we figured out, that there seems to be a comparison between a string and a floating point number, which is not safe anyway. See: https://stackoverflow.com/questions/3148937/compare-floats-in-php

To avoid this, the value is converted to a string before writing the value into the session and to convert both values to the same "number_format" value with 4 digits

fjbender commented 4 years ago

Thanks for the contribution! Looks good to me, moved to QA queue.

sprankhub commented 4 years ago

@phoenix-schwarz thanks! Any reason why you do not use the suggested "epsilon technique"?

phoenix-schwarz commented 4 years ago

@phoenix-schwarz thanks! Any reason why you do not use the suggested "epsilon technique"?

Just a personal preference. One value is a string, and one is a float. Comparing strings in that case seems to be more safe for me, but feel free to change it. I thought about using it, but it "feels" more safe for me to NOT do an additional calculation. There is a constant available as well: PHP_FLOAT_EPSILON but requires PHP 7.2.0 - up to you.

fjbender commented 4 years ago

I'd share @phoenix-schwarz preference for the number_format() option, it seems just more compatible to me.

phoenix-schwarz commented 4 years ago

I added another bugfix and the 1 cent difference tolerance modification as well

fjbender commented 4 years ago

Thanks!

The feature toggle for the rounding issues will follow in a separate PR.