VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => PayPal / PayPal Pro VM 1.1 => Topic started by: piperpilot on December 08, 2010, 17:30:31 PM

Title: Fix for Invalid Tax Calculations
Post by: piperpilot on December 08, 2010, 17:30:31 PM
I dug in and did some debugging.  It turns out that even with the new subtraction method of calculating tax, the value that is being sent to paypal for zero tax ends up looking something like this:

5.3290705182E-15

Obviously a very small number.  I'm not sure WHY this is happening for a zero, but it is actually a relatively easy fix.  You need to put it in two places.  The file you need to edit is:

/administrator/components/com_virtuemart/classes/payment/ps_paypal_api.php

First search for this line:


$taxamt = $amt - $shippingamt - $order_totals['item_total'];


In my file it is around line #1526

Put the following immediately after that line:

                if ($taxamt < 0.01){
                        $taxamt = 0.00;
                }


Next, search for this line:

$taxamt = $amt - $order_totals['item_total'] - $shippingamt;

You'll find it AROUND line# 1640

And again, put this code right after it:

                if ($taxamt < 0.01){
                        $taxamt = 0.00;
                }


Saver your file and you shouldn't get that tax problem again.  Now there might be precision issues.  I haven't run into that, but if anyone does, let me know and I'll add a string formatting function in there to take care of that.

Hopefully the devs can pick this up and make sure it gets put in the next release.

Now to tackle the problem of why on express checkout the customer can't choose to pay with a credit card instead of paypal account.

PiperPilot
Title: Re: Fix for Invalid Tax Calculations
Post by: sardaukar on December 25, 2010, 17:53:48 PM
Thank u very much.

This fix works perfect. : )
Title: Re: Fix for Invalid Tax Calculations
Post by: ibarreto on January 02, 2011, 09:53:20 AM
I love you man!
Title: Re: Fix for Invalid Tax Calculations
Post by: klattr1 on January 24, 2011, 01:12:21 AM
thanks!
fix it for me too
Title: Re: Fix for Invalid Tax Calculations
Post by: BoulderDev on March 15, 2011, 01:58:34 AM
HELP!
???

I tried inserting the additional code just as you had written and it came back with this error:

Parse error: syntax error, unexpected T_STRING in /administrator/components/com_virtuemart/classes/payment/ps_paypal_api.php on line 1533

Suggestions? I'm stumped. I've tried taking out spaces, putting in brackets, nothing seems to work. I don't want to use the legacy paypal - the api is such a nice component. Thanks in advance for your guidance.
Title: Re: Fix for Invalid Tax Calculations
Post by: zanardi on March 15, 2011, 11:26:02 AM
@BoulderDev:
you should start again with the original ps_paypal_api.php and be sure to insert the fix correctly. I guess that the fact that many other people were able to use it means that it is good; a syntax error can only come a copy/paste error.
Title: Re: Fix for Invalid Tax Calculations
Post by: Stonedfury on August 23, 2011, 22:02:26 PM
Well that removed the tax error but now my form will not submit the card info. It redirects to paypal site. I was hoping to do all the processing with their form on one page. I think I am missing something.
Title: Re: Fix for Invalid Tax Calculations
Post by: Gerto on August 26, 2011, 12:03:42 PM
It's a bit sad that this bug is still there :(
Makes me wonder about the reliability for this module for accepting payments.

I'm not an expert, but this seems like a regular problem when calculating with float numbers.
I was able to replicate this with this simple test:
$a=79.9;
$b=70;
$c=9.9;
$d=$a-$b-$c;
                        echo $d; //5.3290705182008E-15


Hoping this will get fixed in next release so that I don't have to do this manually every time :(
Title: Re: Fix for Invalid Tax Calculations
Post by: jstratos on September 29, 2011, 02:51:59 AM
Thanks Piperpilot - the fix on this was perfect.

What I found strange was, that I had two identical templates and versions of Joomla. One worked with no tax error issues, the other had issues.  The only difference was the process I had to go through in their PayPal accounts to obtain the API signature.  The API acquired from PayPal on one, doing it by the book, had no tax errors. The API acquired a bit differently for the other did have the tax error. For that one, I had to apply for a certificate first, then delete the certificate and apply for the signature. That was the only way I could get the username, password AND signature. That person had an older PayPal account. Not sure if this helps at all.
Title: Re: Fix for Invalid Tax Calculations
Post by: stinga on September 29, 2011, 10:06:21 AM
Gerto,
What you have posted is nothing to do with VM, that is a PHP issue. So you can't call that a bug in VM.
If you showed code from VM then it could be a bug and a fix can be created.
Title: Re: Fix for Invalid Tax Calculations
Post by: BodgeIT on October 18, 2011, 18:18:47 PM
Thanks for posting...Just saved my bacon!
Title: Re: Fix for Invalid Tax Calculations
Post by: mieren on May 02, 2012, 23:19:06 PM
What a big help! This fixed my issue! Thanks a ton. Big Fat VM Karma to you!
Title: Re: Fix for Invalid Tax Calculations
Post by: Courtland on June 08, 2012, 19:17:21 PM
Um yea your awesome, fixed all my problems and now i'm gonna take an early lunch!