Virtuemart, Authorize.net and QuickBooks

Joomla and VirtueMart provide an easy to use and feature rich combination of content management and eCommerce. A lot of my clients who use VirtueMart were asking me about Quickbooks integration so that they could easily track online purchases. Authorize.net has provided Quickbooks export for a while but the existing Authorize.net Payment module for VirtueMart did not pass itemized order information. To meet the increasing demand for this functionality I decided to modify the existing payment module to pass the required information.

Please note that Intuit is depreciating IIF and XML file import into QuickBooks in favor of using the XML Web Connector. Exporting the IFF file from Authorize.net and import into QuickBooks is no longer recommended. This code snippet is still useful for passing itemized order details.

Using Authorize.net Advanced Integration Method (AIM) we can pass the itemized order information by using the "x_line_item" field. The allowed information includes:

  • Item ID - String - 31 characters
  • Item Name - String - 31 characters
  • Item Description - String - 255 characters
  • Item Quantity - Integer - positive
  • Item Price - Decimal - 2 decimal places
  • Item Taxable - Boolean - Y or N

The existing Authorize.net payment module is located in:

/adminstrator/components/com_virtuemart/classes/payment/ps_authorize.php

At around line 400 you can find the code:

  1. // strip off trailing ampersand
  2. $poststring = substr($poststring, 0, -1);

Adding the following PHP code in front of that line adds the desired functionality.

  1. // GB Edit Begin - Add itemized list of products in order
  2.  
  3. // Get the cart products
  4. $cart = $_SESSION['cart'];
  5. $cart_ids ="";
  6.  
  7. for($i = 0; $i < $cart["idx"]; $i++) {
  8.   // get the product IDs for a query
  9.   $cart_ids.=$cart[$i]["product_id"].",";
  10.   // make an easy method of getting the quantity by product ID
  11.   $cart_qty[$cart[$i]["product_id"]]=$cart[$i]["quantity"];
  12. };
  13.  
  14. if (strlen($cart_ids)>1) $cart_ids = substr($cart_ids, 0, -1);
  15.  
  16. // set the database query
  17. $dbit = new ps_DB;
  18. $qt= "SELECT #__{vm}_product.product_id AS p_id,
  19.          #__{vm}_product.product_name AS p_name,
  20.          #__{vm}_product.product_sku AS p_sku,
  21.          #__{vm}_product_price.product_price AS p_price,
  22.          #__{vm}_tax_rate.tax_rate AS p_tax_rate
  23.      FROM #__{vm}_product
  24.      LEFT OUTER JOIN #__{vm}_product_price ON
  25.          (#__{vm}_product.product_id = #__{vm}_product_price.product_id)
  26.      LEFT OUTER JOIN #__{vm}_tax_rate ON
  27.          (#__{vm}_product.product_tax_id = #__{vm}_tax_rate.tax_rate_id)
  28.      WHERE #__{vm}_product.product_id IN (".$cart_ids.") LIMIT 30";
  29. $dbit->query($qt);
  30.  
  31. // output text string
  32. $line_items= "";
  33. $line_count=1;
  34. // iterate through results and build api text
  35. while($dbit->next_record()) {
  36.   if ($dbit->f("p_tax_rate")>0) {
  37.     $taxable="Y";
  38.   } else {
  39.     $taxable="N";
  40.   };
  41.   $line_items .= "x_line_item=" .
  42.     urlencode(
  43.       $line_count . '<|>' .
  44.       substr($dbit->f("p_sku"), 0, 31) . '<|>' .
  45.       substr($dbit->f("p_name"), 0, 255) . '<|>' .
  46.       $cart_qty[$dbit->f("p_id")] . '<|>' .
  47.       round($dbit->f("p_price"),2) .'<|>' . $taxable
  48.     ) . "&";
  49.     $line_count++;
  50. };
  51.  
  52. // append the outupt string to the main post string
  53.   $poststring .= $line_items;
  54.  
  55. // GB Edit End - Add itemized list of products in order
  56. // original code below
  57.  
  58. // strip off trailing ampersand
  59. $poststring = substr($poststring, 0, -1);

When I get some free time I hope to add this contribution to the VirtueMart project. As far as I can tell this it the only cost effective method of linking Joomla and Quickbooks. I looked at porting a great Quickbooks export module made for Zen Cart but it would involve extensive work. By using Authorize.net we can archive the same results with minimal effort. Hopefully this will help some folk out there.

Add your comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  d888     .d8888b.    .d8888b.    .d8888b.    .d8888b.  
d8888 d88P Y88b d88P Y88b d88P Y88b d88P Y88b
888 888 888 888 888 Y88b. d88P 888
888 Y88b. d888 Y88b. d888 "Y88888" 888d888b.
888 "Y888P888 "Y888P888 .d8P""Y8b. 888P "Y88b
888 888 888 888 888 888 888
888 Y88b d88P Y88b d88P Y88b d88P Y88b d88P
8888888 "Y8888P" "Y8888P" "Y8888P" "Y8888P"