News:

Looking for documentation? Take a look on our wiki

Main Menu

Prices rounding problem on payment plugin development

Started by marcodelpercio, May 05, 2012, 19:57:41 PM

Previous topic - Next topic

marcodelpercio

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]

marcodelpercio

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=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

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

marcodelpercio

Thank you for replying Milbo

I've just checked out the svn version and I'll try to have a look at it.

marcodelpercio

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?

Milbo

Look at the internal price rounding function. It also takes now the used configuration.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sunburst01

Hi,

Has there been any progression on this issue?

thanks,


911websiterepair

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
joomla components, modules and extensions @ http://www.madeforjoomla.com
joomla development, customizations and repair speshitpillts, http://www.911websiterepair.com

Virtuemart 2.0 PayPalPro Module
Virtuemart 2.0 Fedex Shipping Module
Virtuemart 2.0 Express Order Module
Virtuemart 2.0 Authorize.net SIM payment module
http://www.virtuemartmailordermanager.com

marcodelpercio

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.


sunburst01

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,


911websiterepair

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
joomla components, modules and extensions @ http://www.madeforjoomla.com
joomla development, customizations and repair speshitpillts, http://www.911websiterepair.com

Virtuemart 2.0 PayPalPro Module
Virtuemart 2.0 Fedex Shipping Module
Virtuemart 2.0 Express Order Module
Virtuemart 2.0 Authorize.net SIM payment module
http://www.virtuemartmailordermanager.com

sunburst01

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? :)