Josh
Josh

Reputation: 11070

Converting an application using Keith Palmer's QBWC framework to QuickBooks Online

We're using Keith Palmer/Consolibyte Solutions' excellent PHP QuickBooks Framework in our web application to communicate with QuickBooks Desktop edition via the QuickBooks Web Connector. We're using a QuickBooks_Server and a QuickBooks_Queue in our code as follows:

$this->myQBQueue = new QuickBooks_Queue($this->myDSN);

$mappedFunctions = array(
    QUICKBOOKS_ADD_CUSTOMER,
    QUICKBOOKS_ADD_SALESORDER,
    QUICKBOOKS_ADD_SALESRECEIPT,
    QUICKBOOKS_QUERY_CUSTOMER,
);

$map = array();

foreach($mappedFunctions as $function) {
    $map[$function] = array(
        array($this,"quickbooks{$function}Request"),
        array($this,"quickbooks{$function}Response"),
    );
}

$errmap = array('*' => array($this,'quickbooksErrorHandler'));

$hooks = array(
    QUICKBOOKS_HANDLERS_HOOK_LOGINFAILURE => array(
        array($this,'quickbooksLoginFailureHook')
    ),
    QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS => array(
        array($this,'quickbooksLoginSuccessHook')
    )
);

$soap_options = array();
$handler_options = array();
$driver_options = array();
$callback_options = array();

$this->myQBServer = new QuickBooks_Server($this->myDSN, $map, $errmap, $hooks, QUICKBOOKS_LOG_NORMAL, QUICKBOOKS_SOAPCLIENT_BUILTIN, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);

We now have a customer who has requested that we add support for QuickBooks online. Can we still use a QuickBooks_Server and a QuickBooks_Queue using Keith Palmer's framework for QuickBooks online, or do we have to write new code for the QuickBooks online portion?

Upvotes: 0

Views: 985

Answers (1)

Keith Palmer Jr.
Keith Palmer Jr.

Reputation: 27952

You could re-use the Queue stuff, but the framework doesn't natively support it - you could definitely hack it in easily though.

You will also definitely be able to re-use most (but not all) of your qbXML.

QuickBooks Online does support a qbXML interface (though it's not terribly good - Intuit has publicly stated that they will likely deprecate it within the next year or so, and they are no longer adding features to it). You should know that in the near future, it's very likely that you'll want to start thinking about moving towards Intuit Anywhere/IDS - especially if you're a SaaS app with a lot of QuickBooks Online customers.

You can find the qbXML docs for QuickBooks Online here: http://developer.intuit.com/qbsdk-current/common/newosr/index.html (make sure you tick the "OE" checkbox and uncheck the "US" checkbox)

A few things that bite a lot of people with QuickBooks Online:

  • When adding Payments, you MUST apply them to an invoice. There is no IsAutoApply in QBO
  • There's no support for UPDATING invoices in the qbXML API for QBO
  • There's no support for inventory items in the qbXML API for QBO

If you look at the docs/example_online_edition.php (or docs/example_raw_online_edition.php) file included with the QuickBooks PHP DevKit library code you have, you'll see how it works. Basically instead of a queue, you're just sending straight qbXML requests to Intuit's server via HTTPS instead of wrapping it in SOAP and waiting for the Web Connector to pick it up.

With that said, if you really wanted to continue using the Queue, you could - Queue stuff up just as you normally do, and just set up a script something like this that runs on a cron job:

(WARNING - totally untested code, you'll have to test and debug)

<?php

// Do some setup stuff here as shown in the example... 

$res = mysql_query("SELECT * FROM quickbooks_queue WHERE qb_username = 'the username' AND qb_status = 'q'");
while ($arr = mysql_fetch_array($res))
{
  $request_function = $map[$arr['qb_action']][0];
  $response_function = $map[$arr['qb_action']][1];

  $requestID = null;   // not relevant for QBO
  $user = 'the username';
  $ID = $arr['ident']; 
  $extra = null;
  if($arr['extra']) $extra = unserialize($arr['extra']);
  $err = null;
  $last_action_time = null;
  $last_actionident_time = null;
  $version = '6.0'; // QBO only supports 6.0
  $locale = 'US';   // QBO only supports US
  $qbxml = $request_function($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale);

  $xml = $API->qbxml($qbxml);

  $idents = _extractIdentifiers($xml);   // You can find this function in QuickBooks/Handlers.php and pull it into your app as a function instead of a method

  $response_function($requestID, $user, $action, $ID, $extra, $err, $last_action_time, $last_actionident_time, $xml, $idents);
}

Upvotes: 2

Related Questions