TaxCloud Example Code Ready for Zen Cart Developers.

TaxCloud is a free, easy-to-use sales tax calculation and remittance service for retailers. It’s the only service created to comply with the Streamlined Sales and Use Tax Agreement (SSUTA) at a scale to support all internet merchants.

Zen Cart e-commerce is free, user-friendly, open-source shopping cart software. It is available from http://www.zen-cart.com/.

TaxCloud is now available for use with Zen Cart as a “Module”. It was developed using v1.3.9 of Zen Cart. To install this module you merely have to extract the zip file into the Zen Cart installation directory and configure it through the Zen Cart admin application. The zip file contains a readme file which provides further instructions.

The files for the module can be downloaded here:

https://github.com/taxcloud/ZenCart

Configuration:


1. Enable SOAP on PHP (extensions php_curl and php_soap)

2. Install TaxCloud module php files from the zip file above. (Note – the Zen Cart installation process prompts you to rename your “admin” folder. The TaxCloud zip file includes some files which must be copied into your renamed “admin” folder.)

3. Turn off Zen Cart tax calculation.

Admin > Configuration > My Store > Set “Display Prices with Tax” to false.

4. Create a TaxCloud account.  For more instructions go to TaxCloud.  Once you set up your merchant account and verify your URL, TaxCloud will issue you an API ID and an API Key.  You will need to enter this information (copy and paste) in your Zen Cart administration panel

Admin > Locations/Taxes > TaxCloud Setting

5. Set up TIC_IDs. To accurately calculate tax amount, TaxCloud requires each product to be identified with a TIC_ID, or Tax Identification Category. To accomplish this in Zen Cart we create tax classes and assign them to products.  (We are working on an automation component for this so you will not need to enter anything manually).

To create a new Tax Class:

Admin > Locations/Taxes > Tax Classes > New Tax Class. Put the TIC ID in the in “Tax Class Title” field, and TIC description of your choice in the “Tax Class Description” (you can obtain TIC_ID/Description from TIC_ID/Descriptions from TaxCloud).

To associate a product with a Tax Class:

Admin > Catalog > Categories/Products > Dbl click on a category > Click on Edit > Assign the appropriate TIC_ID to the product from the Tax Class drop down.


This solution can also be applied manually if you would like to edit the files directly.

Manual instructions:

1. Modify order process – /includes/classes/order.php:

Add:

require DIR_WS_MODULES.'TaxCloud/func.taxcloud.php';

Add TaxCloud code. On line 544, add the following block of code to call TaxCloud:

/*******************************
* START TaxCloud
*******************************/
if (TAXCLOUD_ENABLE=='true') {
    //calculate the sub_total the same way as Zen Cart does above (line 511) so that the subtotal is displayed
    //on checkout_payment.php
    foreach($this->products as $k=>$v){
        $this->info['subtotal'] += ($v['final_price'] * $v['qty']) + $v['onetime_charges'];
    }

    if($_GET['main_page'] == FILENAME_CHECKOUT_PAYMENT || $_GET['main_page'] == FILENAME_CHECKOUT_CONFIRMATION) {
        // ************ TaxCloud Begin ************
        $err = Array ();
        $tax = lookupTax ( $this->products, $this->delivery, $err, $this->info['shipping_cost'] );
        if (sizeof ( $err ) == 0 && is_array ( $tax )) {
            $this->info['tax'] = $tax['tax'];
            $taxname = $tax['name'] . ' ' . round ($tax['rate'], 3) . '%';
            $this->info['tax_groups'] = array ($taxname => $tax['tax']);
        } else {
            $err_msg = '';
            foreach ( $err as $msg ) {
                $err_msg .= $msg;
            }
            $this->info['tax'] = 0;
            $this->info['tax_groups'] = array("Tax lookup ".$err_msg => 0);
            $this->info['err_msg'] = $err_msg;
            global $messageStack;
            $messageStack->add_session('checkout', $err_msg, 'error');
        }
    }
} // END TAXCLOUD_ENABLED

// Update the final total to include tax if not already tax-inc
if (DISPLAY_PRICE_WITH_TAX == 'true') {
    $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
} else {
    $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
}

2. Install the rest of the files from the TaxClass  zip file into the corresponding folders.

That’s all there is to it!  Now your zen cart can calculate accurate local sales tax for any address in the U.S. —- for free.

19 Responses to TaxCloud Example Code Ready for Zen Cart Developers.

  1. DivaVocals says:

    Am I supposed to be able to see how the taxes are calculated on your demo site?? If so, they do not appear to be calculating correctly for the test order I just tried to create.

    • davefedtax says:

      Hello. The demo site should be calculating the taxes correctly. They will appear on the checkout confirmation page. One thing to keep in mind is that the shipping address needs to be in a SSUTA state or the taxes will not be calculated. SSUTA (TaxCloud) states can be found at http://taxcloud.net/myrate/.

      If you are having issues with the test server you can also try it out here, which is another generic test site.

  2. DivaVocals says:

    One last question: When will you be submitting your module to the Zen Cart contributions?? Will you be providing support for this on the Zen Cart forum as well..

    • davefedtax says:

      We are currently working on an updated version of the module which will be published to the Zen Cart contributions forum within the next week. We will be providing support for the module on the forum as well as here on this blog. Thanks.

  3. Supersnow says:

    Well not sure but your demo site just hangs on the payment page when you click to confirm then after about 5 minutes goes to a blank page. Plus would like to see this show the taxes on the payment page as people enter their credit card details on this page and want to know how much they are paying in total. Plus I think this is required by the merchant systems if I do recall correctly.

    Plus we have the customer tax exempt module on our site. Does the tax cloud work with this i.e. not charge taxes to those that have a sellers permit. Thanks

    • davefedtax says:

      Hi, thanks for the questions. We are having some performance issues on our test server so I updated the link to point to our secondary test server which is much faster. I’m sorry it was slow for your testing.

      You are correct, the tax amount should be showing on the Payment Information page. This will be included in the next release.

      The TaxCloud implementation replaces the standard Zen Cart tax calculation functionality. Modules which work with the standard tax functionality will not work with TaxCloud unless they are written to do so, so the existing exempt module would not work with TaxCloud. We are working on a full implementation of exemption certificates for a future release. This works differently from other modules in that we store all the certificate information on the TaxCloud servers so it is secure and it only needs to be entered once. The merchants will not have to worry about securing sensitive tax payer identification data. We also require much more information to process a valid exemption request, such as a list of states the certificate is valid for, the purchaser’s business type, etc…

      Please stay tuned to this blog for future release announcements or contact us if you would like to be informed when this functionality becomes available.

  4. Diana Kraft says:

    I have been trying to implement this module into my zencart and it causes me to get a blank page when I try to checkout. As far as I can tell, this is a problem with /includes/classes/order.php. Is there a fix for this coming soon?

    • davefedtax says:

      Hi, I’m sorry to hear that you are having problems. Usually if you are seeing a blank order page it is because TaxCloud is not configured correctly on your site. The merchant account information needs to be available in taxCloudConfig.php, which is located in the TaxCloud module directory.

      There should be an error appearing in the web server log or in the Zen Cart logs which would help us track down the cause of the problem.

      The latest version of the integration (v1.2) has been published on this blog post, but the older version should work as well.

      • Diana Kraft says:

        I did have the merchant account information in there like I was supposed to. I checked the debug logs it was making but they were blank and 0 bytes.

  5. Jeff Snelling says:

    I recently downloaded the TaxCloud contribution for Zen Cart and admittedly had some problems getting it set up, but with my signup for the merchant account on TaxCloud, I have to say I have never had a more proactive and better support experience. I immediately got an email from a REAL PERSON thanking me for the signup and letting me know if I had problems to let him (Carl Stefanelli). When I did send Carl an email for help, I almost instantly got help from a very nice guy, Dave Onnen. He worked really hard to solve the problem, which ended up being a difference in webserver technology on my end. Anyway, my problems have been solved and I’m getting sales tax info for Washington State like clockwork. Many thanks to Carl and Dave.

    Cheers,
    Jeff

  6. Ryan Sarrett says:

    I already have a custom order.php and was wondering where within the order.php file I should add the taxcloud order.php code for a manual update?

    • davefedtax says:

      Hello Ryan,

      Thanks for the question. You will need to find the standard tax calculation code in order.php (around line 506). We put an “if” condition around the existing code so the TaxCloud tax calculation can be turned on and off. Please review the code below. The section with the heading “Calculate taxes for this product” is the Zen Cart tax implementation. The section labeled “Start TaxCloud” is the TaxCloud tax implementation. The code after “// END TAXCLOUD_ENABLED” is part of the existing code.

            global $TAXCLOUD_ENABLE; 
      
            // add onetime charges here
            //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])
      
            /*********************************************
             * Calculate taxes for this product
             *********************************************/
            if (TAXCLOUD_ENABLE!='true') { 
      	      $shown_price = (zen_add_tax($this->products[$index]['final_price'] * $this->products[$index]['qty'], $this->products[$index]['tax']))
      	      + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
      	      $this->info['subtotal'] += $shown_price;
      	      $this->notify('NOTIFIY_ORDER_CART_SUBTOTAL_CALCULATE', array('shown_price'=>$shown_price));
      	      // find product's tax rate and description
      	      $products_tax = $this->products[$index]['tax'];
      	      $products_tax_description = $this->products[$index]['tax_description'];
      
      	      if (DISPLAY_PRICE_WITH_TAX == 'true') {
      		// calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)
      		$tax_add = $shown_price - ($shown_price / (($products_tax currencies[$this->info['currency']]['decimal_places']);
      		$tax_add = ($products_tax/100) * $shown_price;
      	      }
      	      $this->info['tax'] += $tax_add;
      	      foreach ($taxRates as $taxDescription=>$taxRate)
      	      {
      		$taxAdd = zen_calculate_tax($this->products[$index]['final_price']*$this->products[$index]['qty'], $taxRate)
      			+  zen_calculate_tax($this->products[$index]['onetime_charges'], $taxRate);
      		if (isset($this->info['tax_groups'][$taxDescription]))
      		{
      		  $this->info['tax_groups'][$taxDescription] += $taxAdd;
      		} else
      		{
      		  $this->info['tax_groups'][$taxDescription] = $taxAdd;
      		}
      	      } 
      	} //END if TAXCLOUD_ENABLE
            /*********************************************
             * END: Calculate taxes for this product
             *********************************************/
            $index++;
          }
          
         /*******************************
           * START TaxCloud
           *******************************/
            if (TAXCLOUD_ENABLE=='true') {
          	//calculate the sub_total the same way as Zen Cart does above (line 511) so that the subtotal is displayed
          	//on checkout_payment.php
         	foreach($this->products as $k=>$v){
      		$this->info['subtotal'] += ($v['final_price'] * $v['qty']) + $v['onetime_charges']; 
      	}
          
         	 // only call TaxCloud at checkout_confirmation.php page to take coupon into account as well. There's no harm in 
          	// calling in at checkout_payment.php page as in Zen Cart original design, but all the tax calculation will be 
          	// void anyway if a coupon is specified at checkout_confirmation.php    
          	if($_GET['main_page'] == FILENAME_CHECKOUT_PAYMENT || $_GET['main_page'] == FILENAME_CHECKOUT_CONFIRMATION) {      
      	    // ************ TaxCloud Begin ************	        	
      	    
      	    
          		$err = Array ();	  			        	
      	  	$tax = func_taxcloud_lookup_tax( $this->products, $this->delivery, $err, $this->info['shipping_cost'] );	
      
      	  	if (sizeof ( $err ) == 0 && is_array ( $tax )) {  	  		
        	  		$this->info['tax'] = $tax['tax'];
      			$taxname = $tax['name'];
      			$this->info['tax_groups'] = array ($taxname => $tax['tax']);
      	  	} else {
      			$err_msg = '';
      			foreach ( $err as $msg ) {
      	  	  		$err_msg .= $msg;
      			}		   	
      			$this->info['tax'] = 0;
      			$this->info['tax_groups'] = array("Tax lookup ".$err_msg => 0);
      			$this->info['err_msg'] = $err_msg;			
      			global $messageStack;
      			$messageStack->add_session('checkout', $err_msg, 'error');
      	  	}
      	   
          	}           
          } // END TAXCLOUD_ENABLED
      
          // Update the final total to include tax if not already tax-inc
          if (DISPLAY_PRICE_WITH_TAX == 'true') {
            $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
          } else {
            $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
          }
  7. Jeremy says:

    I have a problem with this module When I go to check out I get the following error:
    Error encountered while verifying address System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. at FedTax.TaxCloud.VerifyAddress(String uspsUserID, String address1, String address2, String city, String state, String zip5, String zip4) in C:\Work\FedTax\dev\src\FedTaxWebsrv\FedTaxWebsrv\TaxCloud.asmx.cs:line 982 --- End of inner exception stack trace ---

    Any assistance would be greatly appreciated.

    • Jeremy says:

      Guess I should specify, I’m using Zen Cart 1.3.9h on GoDaddy within a subdirectory of my main site.

    • davefedtax says:

      Hi Jeremy. This error usually means that you don’t have your store’s street address and zip set up within the TaxCloud settings in the Zen Cart administration console. Let me know if you have questions on how to set this up. Thanks.

      • Jeremy says:

        Hi Dave,
        Thanks for the quick reply. I do have my address setup in the settings page. Any ideas why the site wouldn’t be pulling this up?

  8. Ann says:

    Hi

    I have uploaded all the taxcloud files but I do not see the TaxCloud Setting in the dropdown of Admin > Locations/Taxes > TaxCloud Setting.

    Please help. Thanks in advance.

  9. anup says:

    I am not a computer geek. I want to make sure if we install and configure this software, will the software automatically configure all the tax rates for different US and Canada states?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: