Author Topic: Fix for Invalid Tax Calculations  (Read 11304 times)

piperpilot

  • Beginner
  • *
  • Posts: 44
Fix for Invalid Tax Calculations
« 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:

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

In my file it is around line #1526

Put the following immediately after that line:
Code: [Select]
                if ($taxamt < 0.01){
                        $taxamt = 0.00;
                }

Next, search for this line:

Code: [Select]
$taxamt = $amt - $order_totals['item_total'] - $shippingamt;
You'll find it AROUND line# 1640

And again, put this code right after it:
Code: [Select]
                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

  • Beginner
  • *
  • Posts: 1
Re: Fix for Invalid Tax Calculations
« Reply #1 on: December 25, 2010, 17:53:48 pm »
Thank u very much.

This fix works perfect. : )

ibarreto

  • Beginner
  • *
  • Posts: 11
Re: Fix for Invalid Tax Calculations
« Reply #2 on: January 02, 2011, 09:53:20 am »
I love you man!

klattr1

  • Jr. Member
  • **
  • Posts: 80
Re: Fix for Invalid Tax Calculations
« Reply #3 on: January 24, 2011, 01:12:21 am »
thanks!
fix it for me too

BoulderDev

  • Beginner
  • *
  • Posts: 1
Re: Fix for Invalid Tax Calculations
« Reply #4 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.

zanardi

  • Contributing Developer
  • Full Member
  • *
  • Posts: 878
    • GiBiLogic
Re: Fix for Invalid Tax Calculations
« Reply #5 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.
--
Francesco (zanardi)
http://extensions.gibilogic.com
@gibilogic on Twitter

Stonedfury

  • Jr. Member
  • **
  • Posts: 266
    • Stonedfury
  • Skype Name: Stonedfury
  • VirtueMart Version: 2.0.24
Re: Fix for Invalid Tax Calculations
« Reply #6 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.
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

  • Beginner
  • *
  • Posts: 13
Re: Fix for Invalid Tax Calculations
« Reply #7 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:
Code: [Select]
$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

  • Beginner
  • *
  • Posts: 42
Re: Fix for Invalid Tax Calculations
« Reply #8 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.

stinga

  • Contributing Developer
  • Full Member
  • *
  • Posts: 872
    • Squangle ltd
Re: Fix for Invalid Tax Calculations
« Reply #9 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.
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

  • Beginner
  • *
  • Posts: 2
Re: Fix for Invalid Tax Calculations
« Reply #10 on: October 18, 2011, 18:18:47 pm »
Thanks for posting...Just saved my bacon!

mieren

  • Beginner
  • *
  • Posts: 13
Re: Fix for Invalid Tax Calculations
« Reply #11 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!

Courtland

  • Beginner
  • *
  • Posts: 20
Re: Fix for Invalid Tax Calculations
« Reply #12 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!