TaxCloud Example Code Ready for osCommerce 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.

osCommerce is a popular Open Source online shop e-commerce solution that is powered by a dedicated, strong, and ever growing community, and is released under the GNU General Public License.

The standard osCommerce software implements tax calculations by defining tax rates for a geographical zone. The tax is either calculated based on the merchant’s address or the customer’s shipping address. To set this up for the entire US you would have to create a zone for each zip+4 code in the country for each tax class. This would be difficult and hard to maintain. Implementing the TaxCloud module makes tax lookups easy.

This module was developed using v2.3.1 of osCommerce. Installing the module for this version of the software is as easy as extracting the files from the TaxCloud zip file over the existing osCommerce installation. The code for other versions of the software will be similar but you may instead have to edit the PHP files directly to include the TaxCloud code.

** Update – version 1.4 now includes support for Exemption Certificates! **

The TaxCloud sample module is available on GitHub.

Installation

1. Ensure that SOAP is enabled (php_curl and php_soap in php.ini)

2. Back up your current osCommerce installation.

Quick Install

If you are using v2.3.1 of osCommerce you can do a quick install:

– Install TaxCloud module by unzipping the TaxCloud zip file into the oscommerce catalog directory ($OSCOMMERCE_INSTALL_DIR/catalog), overwriting existing files.

Manual Install

Older versions of osCommerce may have slightly different file structures so the code changes need to be made manually in this case. Steps for manual installation:

1. Unzip the TaxCloud zip file into a temporary directory. Copy the TaxCloud folder into the $OSCOMMERCE_INSTALL_DIR/catalog/admin/ext/modules/ directory of your osCommerce installation.

2. Modify the $OSCOMMERCE_INSTALL_DIR/catalog/includes/classes/order.php file to include the TaxCloud classes:

require("admin/ext/modules/TaxCloud/func.taxcloud.php");

class order {

...

3. Edit $OSCOMMERCE_INSTALL_DIR/catalog/includes/classes/order.php::cart() function to call TaxCloud (line 339):

// only call TaxCloud at checkout_confirmation.php page
$pos = strpos($_SERVER[PHP_SELF], FILENAME_CHECKOUT_CONFIRMATION);
if($pos == true) {

    // ************ TaxCloud Begin ************
    $err = Array ();

    $_customer = array ('id' => $customer_id, 'address' => array ('S' => array ('address' => $shipping_address['entry_street_address'],'city' => $shipping_address['entry_city'], 'state' =>     $shipping_address['zone_name'],'zipcode' => $shipping_address['entry_postcode'])));

    $countryCode = $shipping_address['countries_id'];

    if ($countryCode == 223) { //US

        $tax = lookupTax ( $cart->get_products (), $_customer, $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 {

        $display_error = true;
        $err_msg = '';
        foreach ( $err as $msg ) {

            $err_msg .= $msg;
            // If TaxCloud is not enabled, the function will return this message. In this case don't display the taxes
           if ($msg == 'TAXCLOUD_NOT_ENABLED') {
                $display_error = false;

           }

      }
      if ($display_error) {

        $this->info['tax'] = 0.01;
        $this->info['tax_groups'] = array("Tax lookup ".$err_msg => 0.01);
        $this->info['err_msg'] = $err_msg;

     }

  }

}  //***************** TaxCloud End ***************

//Below is the existing code from osCommerce
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'];

}

4. Set osCommerce to not display prices with tax (tax will be on a separate line in the total). Go to Admin > Configuration > My Store and set “Display Prices with Tax” to false.

5. Modify $OSCOMMERCE_INSTALL_DIR/catalog/checkout_process.php to confirm the order during checkout:

$errMsg = array();
global $customer_id;
$result = func_authorized_with_capture_taxcloud($customer_id, $insert_id, $errMsg);
if ($result > 0) {

    //successfully captured

} else {

    //an error occurred
    die(print_r($errMsg, true));

}

6. Modify the order confirmation page to display any errors that occur. ($OSCOMMERCE_INSTALL_DIR/catalog/checkout_confirmation.php line 296):

if (!isset($order->info['err_msg'])) { // <-- New line added

     echo tep_draw_button(IMAGE_BUTTON_CONFIRM_ORDER, 'check', null, 'primary'); // < -- existing code

}

Tax Calculation

To use the TaxCloud service you will need to configure your installation with your merchant information from TaxCloud.net.  First you must visit TaxCloud and register a merchant account.  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) into your osCommerce administration panel  In the Admin console go to Admin > Locations/Taxes > TaxCloud Settings. Enter your TaxCloud ID and Key as well as your USPS ID. You will also need to enter the street address and 5 digit zip code of your store location.

TaxCloud also requires that each product in the catalog have a TIC ID assigned. This is the tax code that allows TaxCloud to calculate the correct tax rate based on the type of product. More information on TICs can be found in the developer documentation. osCommerce has the concept of a Tax Class which can be assigned to a product. You will use Tax Classes to contain the TIC IDs and assign them to products.

To create a new Tax Class go to Admin > Locations/Taxes > Tax Classes > New Tax Class. Put the TIC ID in the Tax Class Title field and enter a description into the Tax Class Description.

To associate a product with a Tax Class go to Admin > Catalog > Categories/Products, double-clock on a category > click on Edit and assign the appropriate TIC_ID to the product from the Tax Class drop-down.

For example, if your are selling computer equipment in your store you could create a Tax Class with the TIC_ID of 30100 and assign this Tax Class to all the products in your catalog that qualify as computer equipment.

Your store is now set up to use TaxCloud!

27 Responses to TaxCloud Example Code Ready for osCommerce Developers

  1. Russ says:

    Running into the following problem with SOAP. SOAP is enabled and I have the classes setup by the TIC code. Not sure what is going on here. OsCommerce v2.3.1. Maybe a problem with open-ssl? Or is the WSDL_URL incorrect?

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘https://api.taxcloud.net/1.0/TaxCloud.asmx?wsdl’ : Start tag expected, ‘SoapClient(‘https://api.tax…’) #1 /home/{username}/public_html/shop/includes/classes/order.php(12): require_once(‘/home/{username}/…’) #2 /home/{username}/public_html/shop/checkout_shipping.php(44): require(‘/home/{username}/…’) #3 {main} thrown in /home/{username}/public_html/shop/admin/ext/modules/TaxCloud/func.taxcloud.php on line 13

  2. davefedtax says:

    Hello Russ,

    It appears that you have the correct WSDL url. Have you checked to see if curl is enabled as well?

  3. Russ says:

    yes, curl is definitely enabled. I’ve got several other apps running with curl without any problems.

    From my php.ini on my server:
    cURL support – enabled
    cURL Information – libcurl/7.21.0 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Soap Client – enabled
    Soap Server – enabled
    soap.wsdl_cache – 1 – 1
    soap.wsdl_cache_dir – /tmp – /tmp
    soap.wsdl_cache_enabled – 1 – 1
    soap.wsdl_cache_limit – 5 – 5
    soap.wsdl_cache_ttl – 86400 – 86400

  4. Russ says:

    only other thing I can think of is that CSF might be preventing the connection. not sure though.

  5. davefedtax says:

    It could be. We need to have an outgoing http port available to use the web services. The simplest test would be to create a simple page with the following line in it:

    $client = new SoapClient(“https://api.taxcloud.net/1.0/TaxCloud.asmx?wsdl”);

    If that doesn’t work then something isn’t configured correctly.

  6. Russ says:

    Alright, it didn’t work. Gave me a 500 Internal Server Error. Should I recompile Apache?

    • davefedtax says:

      I’m sorry – it is difficult to figure out what the issue is from here. I’m not sure if you need to recompile Apache. The rest of the site seems to be responding correctly. I would keep working on the simple test to get that working.

      • Russ says:

        Let me get this straight, make a simple PHP file with only the following line:

        $client = new SoapClient(“https://api.taxcloud.net/1.0/TaxCloud.asmx?wsdl”);

        And nothing else? I’m new to SOAP. I’ve used nothing but curl up to this point.

  7. davefedtax says:

    Here is a more complete test:

    $client = new SoapClient(“https://api.taxcloud.net/1.0/Taxcloud.asmx?wsdl”);
    print_r($client);

    $params = Array();
    $getTICGroupsResponse = $client->getTICGroups($params);
    print_r($getTICGroupsResponse);

    That should print out the client object and a message about an invalid key.

  8. davefedtax says:

    Sorry, it wouldn’t allow me to post the opening and closing php tags, even if I included the code tags.

    • Russ says:

      This seemed to work okay. Didn’t throw any errors. Although I think I cheated…

      print "Content-type: text/html\n\n";
      $client = new SoapClient("https://api.taxcloud.net/1.0/Taxcloud.asmx?wsdl");
      $result = $client->SomeFunction();
      if (is_soap_fault($result)) {
      trigger_error("SOAP Fault: (faultcode: {$result->faultcode}, faultstring: {$result->faultstring})", E_USER_ERROR);
      }

  9. davefedtax says:

    The only thing I can find searching for that particular error is that it seems to be a problem with certain versions of PHP. Which version are you using?

  10. Russ says:

    For anyone who is reading this the resolution, straight from cPanel’s advice was to recompile Apache with an upgrade to php 5.3 or recompile Apache without curlwrappers.

  11. Jackie says:

    I *think* I just installed this into my osc 2.3.1 store (*think* because the catalog/admin/ext/modules/TaxCloud folder was missing in the package) and getting this error when checking out via paypal express:

    Fatal error: require() [function.require]: Cannot redeclare class address in /home/content/60/9574360/html/shop23/admin/ext/modules/TaxCloud/func.taxcloud.php on line 8

    Any help would be much appreciated!

  12. Tiago says:

    I am having issues when i have an item with lets say a $200 base price with a $100 option. It will only do the tax calculation based on the $200 base price. Would it be possible to get assistance on this?

    • Dave says:

      Hello, you can resolve this issue by modifying the code in ext/modules/TaxCloud/func.taxcloud.php. Near line 184 you should see the following code:

      $cartItem->setPrice($product[‘price’]); // Price of each item

      This should be changed to the following to include the option:

      $cartItem->setPrice($product[‘final_price’]); // Price of each item

  13. Tiago says:

    Have another question. I have some clients that are taxed exempted or resellers. Is it possible to not charge them tax.

    Thanks.

    • Dave says:

      Hello Tiago, the osCommerce integration includes functionality to manage exemption certificates for tax exempt customers. The customer can fill out an exemption form during the checkout process, which will be stored within TaxCloud.

      • Tiago says:

        Dave,

        Where is that located? Is there a setting that has to be first enable?

        Thanks.

      • Dave says:

        It is enabled by default. The link shows up on the checkout_shipping.php page. Make sure you have the latest version of the TaxCloud integration (v1.4).

  14. Tiago says:

    download link is broken

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: