VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: marcodelpercio on May 05, 2012, 19:57:41 PM

Title: Prices rounding problem on payment plugin development
Post by: marcodelpercio on May 05, 2012, 19:57:41 PM
Hello

I'm developing a Virtuemart 2 payment plugin implementing PayPal Express Checkout.
To implement such payment method I have to specify the following parameters:

For each product in the cart:
      - name
      - amount
      - quantity

Then also
- total amount of all the products
- total amount of shipping cost
- order total

The amount/total parameters passed to PayPal (as requested by their official reference) must have 2 decimal places.

Now I had no problem in catching such pieces of information across $cart object in session or orderDetails and making the whole checkout flow to work.
My problem is that PayPal verifies the totals calculation on its own and in some cases the rounding executed by Virtuemart unfortunately doesn't match the real math and so PayPal (obviously) refuses my parameters.

Check the screenshot in attachment to see a live sample of what I mean.

In that very simple example I have just 2 products in my shopping cart, both with quantity = 1.
Final price of product PM2VDP is 16,57 €
Final price of product R2211 is 1,17 €

Virtuemart reports that the total amount for products in the cart is 17,75 € which is wrong because the correct result should be 17,74 €. Keeping on with that total also the whole order total is wrong of 1 cent.
If I try passing such amounts to PayPal to initialize an Express Checkout flow it obviously gets refused since that's wrong in plain math.
On the other hand if I ignore Virtuemart calculation and pass the real results performing the sum on my own then the amount to pay on PayPal would differ from the amount registered in Virtuemart for that order which is very bad for a payment plugin.

Watching such sample I believe that Virtuemart performs its calculation on unformatted prices with 4 decimal places and then formats (rounding) the final prices or the final amounts/totals obtained. However that's bad since the final users don't even know about the unformatted prices in background. Final users just see the numbers in the cart calculation displayed and, as that picture shows, the calculation is wrong.

What am I missing?



[attachment cleanup by admin]
Title: Re: Prices rounding problem on payment plugin development
Post by: marcodelpercio on May 06, 2012, 00:37:00 AM
Well searching in the forum I've found some other unresolved threads posting about the same problem about my payment plugin development.
As for example:
http://forum.virtuemart.net/index.php?topic=101058.msg334691#msg334691 (http://forum.virtuemart.net/index.php?topic=101058.msg334691#msg334691)
http://forum.virtuemart.net/index.php?topic=101405.msg336631#msg336631 (http://forum.virtuemart.net/index.php?topic=101405.msg336631#msg336631)

It seems like Virtuemart 2 has some rounding issue in general.
I can just confirm such problems on my environment

Virtuemart 2.0.6 stable and Joomla 2.5.4
Title: Re: Prices rounding problem on payment plugin development
Post by: Milbo on May 07, 2012, 00:43:49 AM
Please try the latest svn version.

the problem is not so easy to solve. But the latest svn is now using the selected rounding also doing the internal calculation, but it is not perfect, would be nice when you help us. Just checkout the latest svn and compare the calculationh.php, then you see the new idea.
Title: Re: Prices rounding problem on payment plugin development
Post by: marcodelpercio on May 07, 2012, 11:51:46 AM
Thank you for replying Milbo

I've just checked out the svn version and I'll try to have a look at it.
Title: Re: Prices rounding problem on payment plugin development
Post by: marcodelpercio on May 07, 2012, 12:19:10 PM
As you suggested I was comparing svn calculationh.php with current 2.0.6 stable version however in both functions

getCheckoutPrices()  that performs the actual cart sum calculation product by product
and
getProductPrices()    that performs calculation of the various price details for a single product

I cannot see any noticeable difference apart from the new VatTax rule handling.
Rather the function getCheckoutPrices() is totally identical between svn and 2.0.6 stable. (At least for the moment)

Could you please point me to the right direction?
Title: Re: Prices rounding problem on payment plugin development
Post by: Milbo on May 07, 2012, 12:27:15 PM
Look at the internal price rounding function. It also takes now the used configuration.
Title: Re: Prices rounding problem on payment plugin development
Post by: sunburst01 on June 13, 2012, 14:10:38 PM
Hi,

Has there been any progression on this issue?

thanks,

Title: Re: Prices rounding problem on payment plugin development
Post by: 911websiterepair on June 13, 2012, 14:43:12 PM
today we released a paypalpro module for vm2,   the next update due around July 10th will include express checkout options
https://www.joomlacache.com/index.php/subscriptions/new/32.html
Title: Re: Prices rounding problem on payment plugin development
Post by: marcodelpercio on June 13, 2012, 14:52:25 PM
That's what I wanted to implement too, however with current Virtuemart 2 version it happens frequently that SetExpressCheckout raises error since the unformatted prices in internal data structures are rounded wrongly and the simple sum of the various items amounts gives incoherent results.

Actually you may implement ExpressCheckout only without defining items prices (i.e. including only order total), however unless they fix Virtuemart rounding issues you cannot override prices in the core.

Title: Re: Prices rounding problem on payment plugin development
Post by: sunburst01 on June 13, 2012, 15:41:54 PM
Quote from: geekhead on June 13, 2012, 14:43:12 PM
today we released a paypalpro module for vm2,   the next update due around July 10th will include express checkout options
https://www.joomlacache.com/index.php/subscriptions/new/32.html

Hi Geekhead,

I would be interested in purchasing your extension. However, i'm not so keen on any VM core hack method so wondered if this is all handled from your own extension?

thanks,

Title: Re: Prices rounding problem on payment plugin development
Post by: 911websiterepair on June 13, 2012, 18:00:56 PM
VM core hack method

not sure what your referring too,   this is not a hack,   our ppp module installs with the normal joomla installer, ours is not a hack
Title: Re: Prices rounding problem on payment plugin development
Post by: sunburst01 on June 13, 2012, 18:10:31 PM
Thanks Geekhead.

Will look into purchasing later but want to know what is the difference between your version and the one that comes with VM2?

Should i perhaps, ask this question at JoomlaCache forum instead? :)