Jump to content

PS 1.3.1 PayPal 1.6 Order being flagged as "Payment Error" - php equality test fails even when values are equal


Recommended Posts

After a 1.2.5 upgrade to 1.3.1, over the last couple of days we've started seeing "Payment Errors" for some PayPal purchases.

After looking at the code to find out when a "Payment Error" is flagged, I can see that classes/PaymentModule.php sets the order to this status if the amount paid via paypal is different to the amount of the cart.

The code that sets this is:

if ($order->total_paid != $order->total_paid_real )
   $id_order_state = _PS_OS_ERROR_;



After debugging this piece of code I'm seeing this equality test FAIL even when the values are equal. For example, here is the output from a print on the variables when the if test fails:

"Error 8 - total paid: ".$order->total_paid." - Paid Real ".$order->total_paid_real." Cart order total - ".$cart->getOrderTotal(true, 3)

Error 8 - total paid: 5.7 - Paid Real 5.7 Cart order total - 5.7



Now this problem ONLY occurs when the values being compared is an even 10 cents, for example 3.10, 5.70 etc. If the cart value is 3.11 or 5.72, this problem will NOT occur.

To work around this issue I changed this if statement to the following and it works now:

if ( number_format($order->total_paid,2) != number_format($order->total_paid_real,2) )



Now, I'm no PHP expert by any stretch of the imagination, but the existing equality check should work IMHO. Any thoughts on why this single IF statement has caused me so much grief?

Link to comment
Share on other sites

@ Marksull

Well mate i have try`t your code cause i also have the payment errors with paypal but if i replace the code with yours and i do a test and buy something and pay with paypal then all is fine but the store is not updated with order information.The order does not exist after done the payment.
Any idea ??

ysco..

Link to comment
Share on other sites

  • 4 months later...
×
×
  • Create New...