AbanteCart Community

Shopping Cart Operations => Support => Topic started by: kolynet on October 07, 2016, 01:00:50 PM

Title: paypal express error, amount not equal
Post by: kolynet on October 07, 2016, 01:00:50 PM
dear developers,

github .com/abantecart/abantecart-src/issues/685

i have this issue. only when i add multiple items in euro for example and the cart vs paypal differ by 0,01.
sometimes it works sometimes its not ,depending on the rounding.
is there any manual workaround?

thank you !
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 07, 2016, 02:36:17 PM
Which Paypal extension are you using?
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 07, 2016, 04:08:38 PM
latest 1.2.8 stock paypel express extension.
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 02:44:06 AM
If you charge shipping, Paypal charges VAT to sub-total and shipping separately and then adds the 2  together. This causes rounding errors like you experience.  If you google this problem, lots of examples.

Do you have to have Paypal calculate VAT?  VAT/Tax can be setup in A-cart for both sub-total and shipping and then only the total is passed to Paypal. Personally, I don't let Paypal calculate anything.

Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 04:42:20 AM
I have free shipping on everything, and no TAX on the store.
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 05:04:38 AM
Okay, maybe try putting the tax in the store and take it off Paypal. That way a total is passed to Paypal and your not relying on Paypal for any calculations.

It seems though that the Euro rounding error is not limited to my previous post with sub-total and tax. 

The only other thing I can think of is currency conversion on Paypal side.  I don't know how they do that. As far as I know, Paypal is USD based and has to do conversions.  That could explain the randomness of the error.

If it was me, I would try taxing at store level and passing a total to Paypal. There is also a report for tax in Abantecart to help keep track of tax collected.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 05:47:08 AM
thanks for ur help, however i dont think it has to do anything with the taxation. i have AbanteCart with 0 tax. so no tax zone. paypal dont put any added tax to the totals. I think its some rounding related thing, where it round up by 1 cents sometimes. maybe can you help me via skype? i pm'd you :)
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 05:51:14 AM
P.S: the big isssue:

SUB-TOTAL: $23.65
10% coupon: $2.37 (here come the problem, its actually counted with ($2.365 in the backend)
==============
TOTAL: $21.29.. (this is clearly $21.28) thats why it throw the error. Same happen in all currencies I guess.

I just simply cant find that function which calculateds the full total (like this: sub-total - discounts). If i find it, i can probably fix.

thanks.
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 06:29:26 AM
Take a look at core/lib/cart.php but I don't think that's it.  Took a look at the DB and it looks like it's there. Take a look at xxx_orders for a start(screen shot attached)

Some of the values are carried out beyond 2 places and I bet that's where the error occurs.  AND it will do it in any currency.  There's no reason I can see to carry a price out to 4+ decimal places. Maybe one of the dev team can chime in and give us some insight as to why the decimal places are more than 2.  Maybe in some currencies there are more than 2 places.

BTW, it's a simple fix.  Just change the values in the db.  I've come across this elsewhere.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 06:50:00 AM
ahha, yeah i found it to be 4 decimal in my db.. will change and see if it helps! thanks
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 06:57:52 AM
That's only one place I looked at quickly.  You need to check product prices and any other table that deals with currency and adjust them accordingly too. Otherwise, you will still get an error at some point.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 07:22:03 AM
i modified my database, however the discount is still calculated by 3 decimal for some reason. somehow I should force it to use 2 decimal always.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 07:36:10 AM
product price full: $23.65, when i apply 10% coupon, it shows $2.37. It would work if it calculated with 2.37, but however in the background it counts with -2.365, tahts why paypal throw error. i need to found the variable where it count the full total in the PHP. I guess.
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 07:45:22 AM
Check core/lib/cart.php  You have to look at ALL tables that deal with currency.  Did you change the decimal places in xxx_coupon.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 07:46:56 AM
i have this:

      //Need to round price after discounts and specials
      //round main price to currency decimal_place setting (most common 2, but still...)
      $currency = $this->registry->get('currency')->getCurrency();
      $decimal_place = (int)$currency['decimal_place'];
      $decimal_place = !$decimal_place ? 2 : $decimal_place;
      $price = round($price, $decimal_place);

however it does nothing if I remove the rounding of the price calc.
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 07:49:13 AM
Quote from: kolynet on October 08, 2016, 07:46:56 AM
i have this:

      //Need to round price after discounts and specials
      //round main price to currency decimal_place setting (most common 2, but still...)
      $currency = $this->registry->get('currency')->getCurrency();
      $decimal_place = (int)$currency['decimal_place'];
      $decimal_place = !$decimal_place ? 2 : $decimal_place;
      $price = round($price, $decimal_place);

however it does nothing if I remove the rounding of the price calc.

See above
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 07:59:23 AM
x
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 08:16:08 AM
The DB thing is a logical suggestion as to why your having this problem.  It may be code related, but if nothing else, it will confirm whether the db decimal places is the cause or not.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 08:16:48 AM
x
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 08:35:19 AM
How's your currency setup in Localization?  I bet you have to trim the conversion down to 2 decimal places.  Been on the right track, maybe just the wrong place.  Look at the screen shot. 


========

You might have to change the db xxx_currencies  It is "set" for 2 decimal places,but the value is 15,8.  This makes more sense looking at things a bit closer.


Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 08:43:35 AM
x
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 08:58:29 AM
x
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 09:06:34 AM
That's what I'm saying in the DB.  In xxx_currencies, "value" needs to be 15,2 not 15,8.  This forces 2 decimal places regardless of code.  It might not be the right fix, but it forces an output of 2 decimal places.
Title: Re: paypal express error, amount not equal
Post by: kolynet on October 08, 2016, 10:26:48 AM
x
Title: Re: paypal express error, amount not equal
Post by: digitalt on October 08, 2016, 11:17:21 AM
Look at your math. 83.05 is correct by the formatted total and the displayed total is correct with rounding.

Now, I don't understand what your getting at(http://digitaltradz.digitaltwister.com/Smileys/default/5.gif)  Your example is correct both ways. It is displaying the correct amounts. 

You were looking at why Paypal gets a 3 decimal place number and throws an error.  I have suggested ways to correct it and things to look at.  This is getting away from the original question/topic.
Title: x
Post by: kolynet on October 08, 2016, 12:43:46 PM
x