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.
Virtuemart Authorize.net customization
Hi thank you for the awesome tutorial!!! Great job! You seem to know a lot about VirtueMart. I am trying to stop the authorize.net payment method from attempting to authorize the customer info. Any idea on what code could be removed to do that? Could you explain? I just need to be able to get the customer payment info along with recurring payments but not authorize. Thanks in advance!
Option in settings
Mike, This is normally an option in the payment setting within VirtueMart. Teh default is "Authorize & Capture" which will check for funds and collect them. The other option is "Authorize" which just checks for available funds and then requires manual processing in the Authorize.net managment web site to collect the funds. No code changes required.
Authorize.net shipping charges
I wanted to know how to add shipping charges in authorize.net. I searched a lot but didn't got proper solution.
Please guide me. wanted to add shipping charges to form as per quantity.
Waiting for reply. Thanks
Shipping options
Prashant,
Shipping is independant of the Authorize.net payment module. There are many options to calculate shipping and all of the shipping charges will be passed to Authorize.net by default. You should have a look at the VirtueMart User Manual: Shipping Modules<
Compatibility?
Just curious, since I can't seem to find a publication date for this post, which version(s) of Joomla/VM was this designed for? Have you tested it yourself? Sounds like a great solution to a very relevant problem.
Please let me know! Though I suppose I could just try it and see what happens, but I support most of my clients remotely and could save everyone a lot of time and energy with a little info up front...
Thanks!
Compatible with VirtueMart 1.0.15 and 1.1.8
I just checked the current code for both releases of VirtueMart; 1.0.15 and 1.1.8. The code change looks to be compatible with these versions. The line numbers are slightly off so you will have to find the properly place to make the changes.
I had this code change working on one client's site for over a year before I created a new site for them. The new site is much more robust because it does not use Joomla or VirtueMart and has full synchronization between the online store and QuickBooks using an XML connector.
Add your comment