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:
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
Adding the following PHP code in front of that line adds the desired functionality.
// GB Edit Begin - Add itemized list of products in order
// Get the cart products
$cart = $_SESSION['cart'];
$cart_ids ="";
for($i = 0; $i < $cart["idx"]; $i++) {
// get the product IDs for a query
$cart_ids.=$cart[$i]["product_id"].",";
// make an easy method of getting the quantity by product ID
$cart_qty[$cart[$i]["product_id"]]=$cart[$i]["quantity"];
};
if (strlen($cart_ids)>1) $cart_ids = substr($cart_ids, 0, -1);
// set the database query
$dbit = new ps_DB;
$qt= "SELECT #__{vm}_product.product_id AS p_id,
#__{vm}_product.product_name AS p_name,
#__{vm}_product.product_sku AS p_sku,
#__{vm}_product_price.product_price AS p_price,
#__{vm}_tax_rate.tax_rate AS p_tax_rate
FROM #__{vm}_product
LEFT OUTER JOIN #__{vm}_product_price ON
(#__{vm}_product.product_id = #__{vm}_product_price.product_id)
LEFT OUTER JOIN #__{vm}_tax_rate ON
(#__{vm}_product.product_tax_id = #__{vm}_tax_rate.tax_rate_id)
WHERE #__{vm}_product.product_id IN (".$cart_ids.") LIMIT 30";
$dbit->query($qt);
// output text string
$line_items= "";
$line_count=1;
// iterate through results and build api text
while($dbit->next_record()) {
if ($dbit->f("p_tax_rate")>0) {
$taxable="Y";
} else {
$taxable="N";
};
$line_items .= "x_line_item=" .
urlencode(
$line_count . '<|>' .
substr($dbit->f("p_sku"), 0, 31) . '<|>' .
substr($dbit->f("p_name"), 0, 255) . '<|>' .
$cart_qty[$dbit->f("p_id")] . '<|>' .
round($dbit->f("p_price"),2) .'<|>' . $taxable
) . "&";
$line_count++;
};
// append the outupt string to the main post string
$poststring .= $line_items;
// GB Edit End - Add itemized list of products in order
// original code below
// strip off trailing ampersand
$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.