Jump to content

[Solved] Rounding Problems (PayPal Warning paid XXX instead of XXX)


Recommended Posts

Hi All,

I have a problem with rounding and PayPal payments.

I have come across a thread where it explains the changes need which were given by tomerg3 but my code is different?

Can anyone advise on the correct code change needed to limit PS to only 2 decimal places when rounding?

The changes that were proposed on the thread were:

In /classes/Cart.php (around line # 570) you will see the following code:

foreach ($products AS $product)
{
   $price = floatval(Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['quantity']));
   $total_price = $price * intval($product['quantity']);
   $order_total += $total_price;
} 



Comment out the $price = … line (add // in front of it) and add the new line below it.

foreach ($products AS $product)
{
   //$price = floatval(Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['quantity']));
   $price = round(floatval(Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['quantity'])),2);
   $total_price = $price * intval($product['quantity']);
   $order_total += $total_price;
} 



But my code in classes/Cart.php is different?:

foreach ($products AS $product)
       {
           if ($this->_taxCalculationMethod == PS_TAX_EXC)
           {
               // Here taxes are computed only once the quantity has been applied to the product price
               $price = Product::getPriceStatic(intval($product['id_product']), false, intval($product['id_product_attribute']), 2, NULL, false, true, $product['cart_quantity'], false, (intval($this->id_customer) ? intval($this->id_customer) : NULL), intval($this->id), (intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL));
               $total_price = $price * intval($product['cart_quantity']);
               if ($withTaxes)
                   $total_price = Tools::ps_round($total_price * (1 + floatval(Tax::getApplicableTax(intval($product['id_tax']), floatval($product['rate']))) / 100), 2);
           }
           else
           {
               $price = Product::getPriceStatic(intval($product['id_product']), $withTaxes, intval($product['id_product_attribute']), 6, NULL, false, true, $product['cart_quantity'], false, (intval($this->id_customer) ? intval($this->id_customer) : NULL), intval($this->id), (intval($this->id_address_delivery) ? intval($this->id_address_delivery) : NULL));
               if (!$withTaxes)
                   $total_price = Tools::ps_round($price * intval($product['cart_quantity']), 2);
               else
                   $total_price = Tools::ps_round($price, 2) * intval($product['cart_quantity']);
           }
           $order_total += $total_price;
       }




Can anyone advise on which code needs to be changed as the incorrect rounding method is causing lots of problems in my shop, with customer and stock control?

Thanks in advance

Link to comment
Share on other sites

I think the tiny difference of calculation will happen in some scenario.
in order to avoid the "Payment error", you can also check at timing order validation.

The idea is check if there is a tiny difference between real paid amount and order amount,
for example is less than a few cents (or less than tiny percentage of order amount),
the just change the real paid amount to the order amount. this should also avoid the Payment Error.

if you would like try this, you can try to make some changes at following line

$paypal->validateOrder($_POST['custom'], _PS_OS_PAYMENT_, floatval($_POST['mc_gross']), $paypal->displayName, $paypal->getL('transaction').$_POST['txn_id']);



in file modules/paypal/validation.php
Hope you can figure it out. Sorry, I have to go offline now

Link to comment
Share on other sites

  • 2 months later...
  • 3 months later...

and the problem still doesnt seem to be solved... i am using 1.4.4.1 and PP module 2.8.2, just had a cx check out, full price was 82.4448, PS rounded this to 82.45, and sent 82.44 to PP, which caused the Paypal warning.

 

What is the issue with just sending what PS figures in the cart?

 

EDIT

I just upgraded to 2.8.5 and STILL an issue...

I went to another site to calculate my taxes for Ontario, and its telling me as well that the amt should be 82.45, so WHY is PS sending PP 82.44????????????????????

I would like that fix of 'if its within X parameters, just make same price" fix, however there wasnt alot of explanation given...

Link to comment
Share on other sites

I think the problem is rounding of number when you send items in detail to Paypal instead of send the total.

One way to fix this is to round the number first before sending to Paypal, so that Paypal will not do the rounding.

 

I have a paid Paypal module, I never hear this issue from my customers. If you would like to have a try at my demo site, please PM me, I can give you back office access.

Link to comment
Share on other sites

That would be great please. My client is getting frustrated, and quite frankly, so am I.

 

EDIT

After further investigation, it seems that a variable called $total_paid_real is getting set, and transferring to the db, this is the amt that is being sent to PP. It is the amt that is off by 1 cent. Does anyone know where that is getting set? So that I can just set it at $total_paid???

Link to comment
Share on other sites

The issue seems to be stemming from the way i require some products to be calculated. For items that are blocks (1, 2, or containers of 10) calculate fine. However items that are individual, that need to be purchased in a QUANTITY are being calculated incorrectly.

 

Therefore the two scenarios are as follows:

 

1. One widget purchased, 9.99 * 1.13 = 11.2887, PS shows 11.29, PP shows 11.29, all is right with the world

2. Widget purchased in quantity of 4, 2.25 (price of ONE widget) * 1.13 = 2.5425 * 4 = 10.17, PS shows correctly, however when info sent to PP, then paypal rounds off to 2.54 * 4 = 10.16, all the demons of the 7th level of hell break out.

 

I will probably have to get my cx to switch the purchasing of individual prods in quantity to purchasing blocks of one product. This will play havoc with the stock levels, but at least that can be managed in the back end, transparent to cx.

Link to comment
Share on other sites

×
×
  • Create New...