News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Fix for Invalid Tax Calculations

Started by piperpilot, December 08, 2010, 17:30:31 PM

Previous topic - Next topic

piperpilot

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

sardaukar

Thank u very much.

This fix works perfect. : )

ibarreto


klattr1


BoulderDev

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.

zanardi

@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.
--
Francesco (zanardi)
http://extensions.gibilogic.com
@gibilogic on Twitter

Stonedfury

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.
No such thing as a stupid question, only a stupid answer. I won't ask if I know the answer or found it using the search as you suggested.

Gerto

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 :(

jstratos

#8
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.

stinga

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.
Stinga.
614869 products in 747 categories with 15749 products in 1 category.
                                             Document Complete   Fully Loaded
                Load Time First Byte Start Render   Time      Requests      Time      Requests
First View     2.470s     0.635s     1.276s          2.470s       31            2.470s      31
Repeat View  1.064s     0.561s     1.100s          1.064s       4             1.221s       4

BodgeIT

Thanks for posting...Just saved my bacon!

mieren

What a big help! This fixed my issue! Thanks a ton. Big Fat VM Karma to you!

Courtland

Um yea your awesome, fixed all my problems and now i'm gonna take an early lunch!