Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Location
    Phoenix, AZ
    Posts
    69
    Plugin Contributions
    0

    Default [Done v1.3.9] 1.3.8 Tax/Special Price Calculations Problems and PayPal Errors

    Hello all,

    While troubleshooting a PayPal issue where orders are charged at PayPal but don't show up in Zen, I ran across the following bug: items on special reduced by a percentage do not total correctly when quantities greater than one of those items are ordered.

    Steps to reproduce:

    1. Create a product that costs $1.69
    2. Put the item on special for 25% off (any special or sale where the percentage discount results in fractions of a cent will work)
    3. Turn on all file logging in paypalwpp and paypaldp
    4. Order 12 (or some other qty > 1) of the item and pay using paypaldp
    5. Check the first PayPal log file created. It will say that the order total does not match the line item totals, so it is not including the line item detail. (The same occurs for tax calculations in the PayPal transaction, but we'll get to that later.)
    6. Wait a few minutes and check your ipn log file you will notice that PayPal has returned a transaction type of web_accept rather than cart. (This is proper behavior on PayPal's part because Zen has not provided cart information, therefore the payment is a "web_accept"). It is easy to tell the transactions apart because "cart" transactions have cart detail on the PayPal site (and in the confirmation email), and "web_accept" transactions do not.

    There are a few results from this bug:

    1. The invoice in the admin section does not calculate correctly for the order. The total(ex) column calculates the total using the fractions of a cent whereas the Total(inc) does not.
    2. Zen does not always handle web_accept transaction types correctly and occasionally misses the order (I *think* Zen misses the order if the customer doesn't return, i.e. is not accepting redirects). For further discussion see: http://www.zen-cart.com/forum/showthread.php?t=95246

    Fixing the calculated price of the specials is easy. Edit [FONT=Courier New]zen_get_products_special_price()[/FONT] in functions_prices.php to round the price before it returns it. I've attached a modified version of the function that appears to work well.

    The other issue is with the totaling that occurs in PayPal transactions. The change to functions_prices.php fixed the web_accept problem for out of state orders, but not not for orders that included sales tax. The problem appears to be that PayPal and Zen calculate taxes differently. In the PayPal API, they state that you can pass the tax for each individual item if you wish, but the tax on each item multiplied by the quantity (repeated for each line) has to add up to the total tax. Our store sells many items that are less than $1, so just about every tax calculation results in fractions of a cent. After Zen rounded the number to pass to PayPal, the tax would no longer total correctly. For example: given a tax rate of 8.3%, an item value of $0.89, and a quantity of 12, Zen tells PayPal that the total tax is $0.89. Then in the cart detail Zen calculates the tax on each item at $0.07. The "sanity check" in the Zen code fails because (12 * 0.07 != 0.89), so Zen does not pass the cart detail. There appears to be some questions (http://www.zen-cart.com/forum/showthread.php?t=96174) about how Sales tax should be calculated, so I sidestepped the issue by not including the tax for each line item. It is optional, per the API (https://www.paypal.com/en_US/ebook/P...scheckout.html ), and appears to be more trouble than it's worth. This fix is not quite as elegant because there appears to be quite a bit of copying and pasting going in the Zen PayPal code. The line-item tax is calculated and checked in paypal_functions.php, paypalwpp.php, and paypaldp.php. (My apologies to the core developers, there were so many lines to comment out that I didn't enclose them with //TICK: like I did with functions_prices.php.) Also, while poking around in the PayPal code, I noticed there are numerous places where rounding is hard-coded at 2 decimal places. I don't know if that will affect people using non-US currency or not, but I thought I would mention it. I've included patched PayPal files as well. See the warning below.

    NOTE: All of these files have about 6 hours of solid testing against the PayPal sandbox site. They should be considered "experimental" and used at your own risk. The changes to paypal_functions.php are untested (we don't use IPN), but should work as the code is identical to the other files. That being said, the changes are benign enough that I am going to push them up to my production store.

    If anyone tries these out and has problems, please let me know and I'll do my best to respond with a fix.

    Thanks!
    Last edited by Tick; 9 Jul 2008 at 05:45 AM.
    Generations Crafting (Our Zen-Cart storefront)
    "
    And that's just it, Doc - my mind has always been my Achilles' heel!" -- The Tick

  2. #2
    Join Date
    Jun 2007
    Location
    Phoenix, AZ
    Posts
    69
    Plugin Contributions
    0

    Default Re: Tax/Special Price Calculations Problems and PayPal Errors

    Crap. Why is it you notice things like this after you've submitted your post. DO NOT USE THE functions_prices.php FILE IN MY LAST POST. I missed a very important line. (It gives away products for free.) Use this instead (one edit made to line 69).
    Attached Files Attached Files
    Generations Crafting (Our Zen-Cart storefront)
    "
    And that's just it, Doc - my mind has always been my Achilles' heel!" -- The Tick

 

 

Similar Threads

  1. coupons and incorrect tax calculations
    By jdubs in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 8 Jun 2009, 07:38 PM
  2. Invoice Tax and discount calculations
    By crazycucumber in forum General Questions
    Replies: 2
    Last Post: 1 Feb 2009, 12:05 PM
  3. problems with Display price with VAT/TAX and Ex VAT/TAX Mod
    By rerbe in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 14 Jan 2009, 04:52 PM
  4. MZMT and tax calculations?
    By brain21 in forum Built-in Shipping and Payment Modules
    Replies: 2
    Last Post: 9 Oct 2006, 11:29 PM
  5. coupons and wrong tax calculations?
    By etoile03 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 10
    Last Post: 29 Sep 2006, 05:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR