I come up with this following an issue where I was finding a 1c rounding issue in paypal.

Issue with paypal is that either of the current options (single and itemized), both send the tax and shipping elements individually. Because those are rounded before sending them to paypal, and paypal does the addition, it is prone to have a 1c difference depending on the rounding.

I worked out a patch in which I am adding an option to the paypal module that really sends the order total on a single line, including both tax and shipping.

The latest patch is a different solution that pre-rounds values so that the total shows properly on paypal. This, however, move the 1p difference to the order subtotal line item on paypal, see screenshots.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hanoii’s picture

Status: Active » Needs review
FileSize
2.92 KB
hanoii’s picture

Issue summary: View changes
Related issues: +#479784: Order rounding
longwave’s picture

Do you know where the 1c rounding is being introduced - do you have the line items and totals that caused the issue? It seems better to fix this at the source and provide accurate data rather than a workaround.

hanoii’s picture

well, I can provide you the exact figures, however, I believe there's not much a fix here.

Total in ubercart are caculated properly, they are done using all of the decimals of all calculations, which takes us to an old issue in 6.x queue which I think we both participated.

So if there the calculation si fine, the issue with paypal is that we have to send each figure round to 2dp points. Sending the items separately and have paypal do the math will allow to this 1p difference. So as I see it, there's not an issue in the core, but rather an issue in the integration or the implementation with paypal.

Unless we do a change in ubercart to do calculations rounded to two decimal points everywhere, which is a huge change, I believe this is a good enough workaround with paypal.

This should not affect if you don't have tax or your numbers are already 2dp rounded on itselves.

longwave’s picture

Shouldn't we just change the $shipping and $tax calculations to pre-round their amounts, so there is no further rounding needed when we do $order->order_total - $shipping - $tax?

hanoii’s picture

the issue is only because the rounded amounts are sent to paypal and paypal does the addition.

do you mean round(total) - round(shipping) - round(tax)?

That might actually be a good idea, the subtotal will the one that might be slightly different, but at least the total will be the same. But what about when you do the itemized order? I guess there there's not much to do. I could work out a different patch if this approach is better for you.

hanoii’s picture

I tried what you suggested, here is the attached patch.

It's a simpler patch, but you end up with the 1dp difference on the subtotal instead of the total. It's a preferred solution than the current one, but my previous approach at least prevents any difference to be seen on the paypal screen.

I am eager to have either solution accepted to the code so I can feel relaxed about updating modules in the future, but I still think the previous approach was better ,at least it adds one new option so you keep different possibilities. Maybe I can combina the two solutions in one patch, as with my previous patch the itemized option was still there with the issue. We are actually putting the first solution in production as we feel is best, but prefer not to have a modified version of ubercart.

I am attaching two images as well to show the difference.

hanoii’s picture

FileSize
11.32 KB
hanoii’s picture

What's needed to follow up on this?

longwave’s picture

I honestly don't know which approach to go with on this. I was hoping someone else would run into this issue, try one or both of the patches, and make a comment, but I guess not :(

hanoii’s picture

The first one is harmful harmless, as it will work the same on current setup, however, if/when people face this issue, they have a option that at least will work.

longwave’s picture

I think you mean harmless? :)

hanoii’s picture

Of course :), corrected above in #11

markdc’s picture

I'm testing patch 1. Seems to be working well. The single line item in PayPal is actually better for my client's case, as they are based in Germany and sell worldwide, and don't want people seeing the German VAT included in PayPal. Not to mention the annoying 1c difference is now gone, which was a headache for bookkeeping and giving our tax office more work. Thank you!!!!