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.

6 comments

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!

Mike Miller wrote 12 years 41 weeks ago
gbrandys's picture

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.

gbrandys wrote 11 years 40 weeks ago

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

Prashant Korane wrote 13 years 5 weeks ago
gbrandys's picture

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<

gbrandys wrote 11 years 40 weeks ago

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!

Marshall wrote 13 years 36 weeks ago
gbrandys's picture

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.

gbrandys wrote 13 years 33 weeks ago

Add your comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
  .dS5SMb.    .dS@88b.    .dEH85b.    .dS@88b.       d@M@8  
d8HP YM8b dH8P Y5Hb dEEP Y9Eb dH8P Y5Hb d8P8@5
89@ .dHEP Y8Hb. dMHP .dHEP dEP M88
8@Ed5@5b. 5959" "YSM@HM" 5959" d5P 5EH
ES9P "YM@b "Y9b. .d5P""Y5b. "Y9b. dH@ 89@
9S9 EHS E5E ME@ E8E @58 E5E ME@ S5E889ME@8
YE@b d@8P YEEb dSSP Y5Mb d@5P YEEb dSSP S@9
"Y5H8SP" "YS5S9P" "Y@@MHP" "YS5S9P" M95