Post by Univest » Thu Jan 26, 2012 12:38 am

Hello Everyone

I have just discovered a problem with the paypals total amount and opencarts total amount which are diffrent at
checkout. It seems that paypal calculates the amount based on 2 decimals and OC calculates based on 4 decimals.
I have read a few topic about this but there is no solution for this for opencart 1.5.1.3.
can anybody out there please provide a solution to this. Im sure all the poeple using paypal are affected by this but there
is no solution or discussion about this major problem.


thank you in advance

Newbie

Posts

Joined
Fri May 13, 2011 1:18 am

Post by OpenCart Addons » Thu Jan 26, 2012 2:51 am

Hey Univest,

This problem only seems to occur when using a coupon in my shop. I believe it has to do with the rounding of the coupon discount calculation.

In catalog / model / total / coupon.php
Find:

Code: Select all

$total_data[] = array(
					'code'       => 'coupon',
        			'title'      => sprintf($this->language->get('text_coupon'), $this->session->data['coupon']),
	    			'text'       => $this->currency->format(-$discount_total),
        			'value'      => -$discount_total,
					'sort_order' => $this->config->get('coupon_sort_order')
      			);
Add Before:

Code: Select all

$discount_total = round($discount_total, $this->currency->getDecimalPlace());
This should now round to the proper decimal points both before it gets displayed, added to the total, and before it gets sent to PayPal.

Regards,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by Univest » Thu Jan 26, 2012 3:30 am

Thank you so much Joel, you are always helping out

Im not sure if the code you gave will solve the issue since I dont have any coupon.
the problem is that when customers add products to cart and checkout with paypal the amount that is in the opencart is diffrent from paypals amount with a few pennies. when I enter prices excluding vat with 4 decimals in admin this happens. this is due to paypals calculation is based on 2 decimal rounding. Its a true headache and hope to find a solution to this.

thank you in advance joel,

Newbie

Posts

Joined
Fri May 13, 2011 1:18 am

Post by OpenCart Addons » Thu Jan 26, 2012 4:58 am

In your admin panel, go to:
System / Localisation / Currencies /
Is your "Decimal Places" set to 2?

Other than that, I don't think there's any way to solve this. If your currency requires 4 decimal places, then it might be something you're stuck with, as like you said, PayPal only uses 2.

Regards,
Joel.

Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by Univest » Thu Jan 26, 2012 8:28 am

thank you joel for the reply

problem is that I have British currency pounds and its actually 2 decimals pounds and pens like 9.99.
to be able to set prices in the admin to achieve prices like 9.99 or 11.99 it would not be possible with 2 decimals.
2decimal.jpg

2decimal.jpg (5.23 KiB) Viewed 23479 times

and when I have 4 decimals and I can achieve 9.99 price type then even the cart calculates wrong it is showing total 19.97
4decimal.jpg

4decimal.jpg (9.9 KiB) Viewed 23479 times

then for example i add 3 x9.99 to the cart and 2.99 shipping as below and the OC cart and paypal have diffrent amounts.
occart.jpg

occart.jpg (50.98 KiB) Viewed 23479 times


Im kind of totally confused how to fix this really. why does it need to be like this and what are all the poeple using paypal and OC have solved this? Any help would be appriciated. thank you

Newbie

Posts

Joined
Fri May 13, 2011 1:18 am

Post by OpenCart Addons » Thu Jan 26, 2012 10:21 pm

Do you have any custom modifications installed?

You shouldn't have any problems with using 2 decimal points in your store. The default GBP setup has 2 decimal points and prices of x.99 show up no problem.

I also just tried it out on one of my testing installations and have no problem display a price of 99.99 using 2 decimal points.

Joel.

Attachments

occart.jpg

occart.jpg (14.22 KiB) Viewed 23471 times


Canada's Leading Expert In OpenCart Development & Certified OpenCart Development Partner Image


User avatar
Active Member

Posts

Joined
Thu Nov 24, 2011 10:51 am
Location - Canada

Post by Qphoria » Thu Jan 26, 2012 11:55 pm

It's the calculation conversion order.

Opencart calculates the product prices based on the values entered into the db and then converts the total to the current currency

But, paypal only knows about the post-converted prices and stupidly does its own math.

So for example if you have 2 currencies on your site and your default is USD and you have these exchange rates:
USD 1.000000
GBP 0.637532

OpenCart does the math based on the default currency:
Product 1: 19.99
Product 2: 27.99
Product 3: 32.49

Subtotal: 80.47


Since GBP is selected, it converts the values after
Product 1: (19.99 * 0.637532) = 12.74
Product 2: (27.99 * 0.637532) = 17.84
Product 3: (32.49 * 0.637532) = 20.71

Subtotal: (80.47 * 0.637532) = 51.30


Paypal only knows about the post-convert prices obviously, and they try to do their own math, which is stupid really. They should be informational only but paypal like to be difficult.

So paypal does its own math:
12.74 + 17.84 + 20.71 which equals 51.29 which is 1 cent less.

OpenCart is doing it right based on a multicurrency store. Paypal is assuming a simpler cart with simple calculations and its 2001 way of thinking is causing the issue. If paypal would just take the itemized values as informational, and allow passing the "Total" as the billable value.. all the paypal issues would be instantly solved.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Univest » Fri Jan 27, 2012 12:13 am

Thank you Joel and Qphoria for your extensive inputs and explanations.

I guess the only way out of this problem is to send a single amount to paypal and not let it calculate its stupid ways.
Can you guys please provide the code to change this so I can only send 1 single amount to paypal. I have studied the methods but cant figure it out really. got OC 1.5.1.3 with modifies theme.

thank you in advance

Newbie

Posts

Joined
Fri May 13, 2011 1:18 am

Post by Qphoria » Fri Feb 17, 2012 3:47 am

Ok I've run into this with my Paypal Pro Hosted mod and think I have a fix.

Basically, I can run the same post-conversion math that paypal does and compare it to the pre-conversion math that opencart does. If they are off by that last cent, I can fudge the paypal total so that paypal sees the same amount that opencart sees. Seems to be working fine in the other module so we'll see how it goes here.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by markman-b » Fri Feb 17, 2012 5:37 pm

Please let me know when the fix is available. Will it be a vqmod?

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by markman-b » Fri Feb 17, 2012 5:56 pm

Opencart calculates the product prices based on the values entered into the db and then converts the total to the current currency
There's only 1 currency in my database: €. And even in this case there a problems with roundings. (when using PayPal Standard)

In this topic you''ll find my explanation, for what causes this rounding problem.
http://forum.opencart.com/viewtopic.php?f=20&t=40181

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by markman-b » Mon Feb 20, 2012 11:00 pm

Is this topic also doomed to run into nothing, just like all other discussions regarding the paypal rounding problems?
How long do we need to wait for something finally realizes that we need a fix for this?

Topic 1
http://forum.opencart.com/viewtopic.php ... ng#p207148

Topic 2
http://forum.opencart.com/viewtopic.php?f=113&t=40181

Topic 3
http://forum.opencart.com/viewtopic.php?f=115&t=37837

I'm in the same boat.
Client called today, and told me that the system is adding up totals incorrectly. She's not happy, and I'm getting flak for recommending an e-commerce system that doesn't work.

Yes, it's just out by 1c; but that's a big deal where accounting is involved. It adds up, and makes it impossible to reconcile orders against client payments. Every other e-commerce system I work with handles it fine, and at the moment I'm extremely *NOT* a happy bunny. Looks like I'm going to have to recode the this system to work consistently.

Regards,
Peter Connolly
Last edited by markman-b on Mon Feb 20, 2012 11:59 pm, edited 2 times in total.

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by Univest » Mon Feb 20, 2012 11:42 pm

Hi Guys

Q has worked hard to fix this issue in his paypal pro hosted extension and I can confirm that it works great. I dont know if he has implemented it in the paypal standard but he has solved this issue.

Please confirm Q if you have implemented this fix elsewhere too?

thank you

Newbie

Posts

Joined
Fri May 13, 2011 1:18 am

Post by markman-b » Tue Feb 21, 2012 12:00 am

Thanx Univest ;)

Only a message from Q that it still has his attention would be nice.

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by Qphoria » Tue Feb 21, 2012 7:41 am

Q doesn't work weekends.

I have the fix and will fix it in the SVN version of paypal standard for 1.5.2 and will throw up a patched version on the forum when ready.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by markman-b » Tue Feb 21, 2012 10:21 pm

Q doesn't work weekends.
That's a good discipline ;)

I'll wait patiently for the fix.

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by Qphoria » Wed Feb 22, 2012 11:50 pm

Here's more information on the "1 cent" issue:
http://forum.opencart.com/viewtopic.php ... 30#p254430

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by markman-b » Thu Feb 23, 2012 12:22 am

Thanx for link. But be aware that the differences (caused by a different calculation method between Open Cart and PayPal), not always are restricted to 1 cent. The difference is related to the number of products in the shopping cart. The more products, the higher the difference.

The differences in order totals are causing some other negative side effects. The amounts on the OC invoices, which are being sent to customers, differ from amounts they have paid, etc.

What is wise? To contact other webshop developers, to find out how they deal with this issue?

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm

Post by dizarter » Thu Feb 23, 2012 12:33 am

Maybe Q wasn't clear enough when he explained "pre-conversion" here http://forum.opencart.com/viewtopic.php ... 38#p254430

What he actually meant is "pre-rounding" math. OpenCart uses more decimal places when calculating percentage, and then rounds to 2 decimal places (or whatever is set in decimal places for your chosen currency - 2 is default for US dollar), so the difference is restricted to 2nd decimal place and can never exceed more then (+/-)1 on that place.

On the other side, PP requires 2 decimal places values.

Example

9.984 is rounded down to 9.98

If you add it twice using 3 decimal places (how OC does it internally)

9.984
9.984 +
---------
19.968 (19.97 when OC rounds it to 2 decimals)

Now, values PP receives are rounded to 2 decimals, thus

9.98
9.98 +
-------
19.96 (here it is, PP value is down by 1, cutomer receives .01 discount)

Example 2

9.987 is rounded up to 9.99

If you add it twice using 3 decimal places (how OC does it internally)

9.987
9.987 +
---------
19.974 (19.97 when OC rounds it to 2 decimals)

Values PP receives are rounded to 2 decimals, thus

9.99
9.99 +
-------
19.98 (PP value is up by 1, cutomer pays .01 more)

There is no bug at all, this is how math calculation works everywhere :)
Last edited by dizarter on Thu Feb 23, 2012 12:55 am, edited 4 times in total.

New member

Posts

Joined
Tue Oct 11, 2011 7:33 am

Post by markman-b » Thu Feb 23, 2012 12:41 am

Maybe he was, but I'm Dutch. Technical topics (like this one) are sometimes difficult to understand, when English is not your first language ;)

Thanx for making it more clear to me.

OC version 1.5.4.1


Active Member

Posts

Joined
Wed Aug 24, 2011 7:13 pm
Who is online

Users browsing this forum: No registered users and 36 guests