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 exisiting payment module to pass the required information.

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

  1. Item ID - String - 31 characters
  2. Item Name - String - 31 characters
  3. Item Description - String - 255 characters
  4. Item Quatity - Integer - positive
  5. Item Price - Decimal - 2 decimal places
  6. Item Taxable - Boolean - Y or N

The existing Authorize.net payment module is located in:

<<site-root>>/adminstrator/components/com_virtuemart/classes/payment/ps_authorize.php

At around line 400 you can find the code:

  $poststring = substr($poststring, 0, -1);

Adding the following PHP code infront 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. $line_count . '<|>' .
  43. substr($dbit->f("p_sku"), 0, 31) . '<|>' .
  44. substr($dbit->f("p_name"), 0, 255) . '<|>' .
  45. $cart_qty[$dbit->f("p_id")] . '<|>' .
  46. round($dbit->f("p_price"),2) .'<|>' . $taxable
  47. ) . "&";
  48. $line_count++;
  49. };
  50.  
  51. // append the outupt string to the main post string
  52. $poststring .= $line_items;
  53.  
  54. // GB Edit End - Add itemized list of products in order
  55. // original code below
  56.  
  57. // strip off trailing ampersand
  58. $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 ZenCart but it would involve extensive work. By using Authorize.net we can achive the same results with minimal effort. Hopefully this will help some folk out there.

 
 
© Copyright 2007 Coda Graphic Design, San Francisco, California