Skip to content

Instantly share code, notes, and snippets.

@hotestimator
Created April 24, 2012 23:13
Show Gist options
  • Save hotestimator/2484506 to your computer and use it in GitHub Desktop.
Save hotestimator/2484506 to your computer and use it in GitHub Desktop.
Quickbooks Web Connector in PHP, raw.
<?php
require('includes/init.php');
/**
* QB_xml_request
*
* This class turns the posted xml file into a
* key/value pair object we can work with.
*
* @param xml object array
* $request->xml->WSDLFUNCTION
* $reuqest->xml->WSDLFUNCTION->param
*/
class QB_xml_request
{
public $xml;
public function __construct($post_xml)
{
$this->xml = $post_xml;
}
}
/**
* QB_response_auth
*
* This class builds and returnds the authenticateResult object to the
* quickbooks web connector.
*
* @param string $ticket
* The first member of the array is a session token, which could be a GUID or anything
* else that you want to use to identify the session. This token will be returned by QBWC
* in subsequent callbacks in the session.
*
* @param string $return_code
* The second member of the string array can contain a variety of things:
*
* a. If the username and password in the authenticate call is invalid, you would supply
* the value 'nvu'.
*
* b. If on the other hand the user data is valid but you have no work to do for that user,
* you would supply the value 'none'.
*
* c. If you do have work to do for the that user, you can supply the full pathname of the
* company to be used in the current update.
*
* d. If you want to use whatever QuickBooks company is currently open at the client
* end, simply supply an empty string.
*
* @param int [optional] $next_update
* The optional third member of the string array contains the number of seconds to
* wait before the next update. You would use this to in effect tell that QBWC client
* not to bother you for a specified time.
*
* @param int [optional] $interval
* The optional fourth member of the string array contains the number of seconds to
* be used as the MinimumRunEveryNSeconds time for your web service, which tells
* QBWC how frequently your web service needs to be contacted
*
* @return object authenticateResult provides authenticateResponse to qbwc
*/
class QB_response_auth
{
public $authenticateResult;
public function __construct($ticket, $return_code, $next_update = null, $interval = null)
{
$this->authenticateResult = array($ticket, $return_code);
if ((int) $next_update)
{
$this->authenticateResult[] = (int) $next_update;
}
if ((int) $interval)
{
$this->authenticateResult[] = (int) $interval;
}
}
}
/**
* This function takes the user and password provided
* by the web connector and validates them.
*
* It will then call the QB_response_auth class to return tru or false
* back to quickbooks.
*
* @param string $ticket
* @param string $return_code
* @param int [optional] $next_update
* @param int [optional] $interval
* @return calls QB_response_auth object
*/
function authenticate($request)
{
global $db;
$username = $request->xml->authenticate->strUserName;
$password = $request->xml->authenticate->strPassword;
$ticket = session_id();
$return_code = 'none';
// validate user
$sql = 'SELECT * FROM users WHERE username = ' . $db->qstr($username) . ' AND password = ' . $db->qstr($password);
$rs = $db->Execute($sql);
if ($rs->RecordCount() < 1)
{
$return_code = 'nva';
}
$resp = new QB_response_auth($ticket, $return_code);
return $resp;
}
// make sure we have a post request that contains at least xml data
if (isset($_POST))
{
if ( ! isset($_SERVER['HTTP_CONTENT_TYPE']) || $_SERVER['HTTP_CONTENT_TYPE'] != 'text/xml; charset=utf-8' )
{
echo "[VL] No.";
exit();
}
else
{
// get the file contents
$file_contents = file_get_contents('php://input');
$xml = simplexml_load_string($file_contents);
$post_xml = $xml->children("http://schemas.xmlsoap.org/soap/envelope/")->Body->children("");
$request = new QB_xml_request($post_xml);
}
}
$server = new SoapServer($wsdl);
$server->addFunction('authenticate');
authenticate($request);
$server->handle(); // sends output back to caller
@hotestimator
Copy link
Author

Proof that this works. Still need to write balance of functions and classes listed in the manual. Change user and password to ones that are not in your qwc file and watch the log file. You can see it 'not authenticate' ;-)

20120424.23:22:31 UTC   : QBWebConnector.WebServiceManager.DoUpdateSelected() : updateWS() for application = 'QuickBooks Integrator' has STARTED
20120424.23:22:31 UTC   : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
20120424.23:22:31 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
20120424.23:22:31 UTC   : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
20120424.23:22:31 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
20120424.23:22:31 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: QuickBooks Integrator
20120424.23:22:31 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): QuickBooks Integrator
20120424.23:22:31 UTC   : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: https://www.DOMAIN_WHERE_SOAP_SERVER_IS_HOSTED.com/qb/qbwc.php
20120424.23:22:31 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
20120424.23:22:32 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : Actual error received from web service for serverVersion call: <Function 'serverVersion' doesn't exist>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-serverVersion.
20120424.23:22:32 UTC   : QBWebConnector.SOAPWebService.do_serverVersion() : This application does not contain support for serverVersion. Allowing update operation for backward compatibility.
20120424.23:22:32 UTC   : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.1.0.24">
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.updateWS() : Actual error received from web service for clientVersion call: <Function 'clientVersion' doesn't exist>. For backward compatibility of all webservers, QBWC will catch all errors under app-not-supporting-clientVersion.
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.do_clientVersion() : This application does not contain support for clientVersion. Allowing update operation for backward compatibility.
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'QuickBooks Integrator', username = 'testuser'
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="testuser"><password=<MaskedForSecurity>
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.updateWS() : Received from authenticate() following parameters:<authRet[0]="1234"><authRet[1]=""><authRet[2]=""><authRet[3]="">
20120424.23:22:33 UTC   : QBWebConnector.RegistryManager.setCurrentWebServiceName() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\CurrentWebServiceName has been set to QuickBooks Integrator
20120424.23:22:33 UTC   : QBWebConnector.RegistryManager.setCurrentWebServiceSessionTicket() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\CurrentWebServiceSessionTicket has been set to 1234
20120424.23:22:33 UTC   : QBWebConnector.SOAPWebService.CheckCFNResponse() : User authenticated.
20120424.23:22:34 UTC   : QBWebConnector.SOAPWebService.do_authenticate() : Done.
20120424.23:22:34 UTC   : QBWebConnector.SOAPWebService.OpenConnection() : Connecting to QuickBooks...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment