Skip to content

Instantly share code, notes, and snippets.

@browniefed
Created June 25, 2013 00:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save browniefed/5855005 to your computer and use it in GitHub Desktop.
Save browniefed/5855005 to your computer and use it in GitHub Desktop.
Quickbooks web connector write up. This is how the PHP SDK written by Consolibyte operates.
Quickbooks Process
-------------------
1) A QWC file is generated (file generateQWC.php). This creates the XML for the web connector, adds in the username to the qwc file, also writes the username/password to the quickbooks_user database.
2) The top of the server.php builds the global constants, and builds arrays that get passed into the web connector handler/php sdk.
2 a) QB_QUICKBOOKS_MAX_RETURNED is the amount of items that we tell quickbooks to send to us at one time. Limit this to a minimal amount.
2 b) Then we set up priorities (ie.QB_PRIORITY_CUSTOMER_IMPORT, QB_PRIORITY_INVOICE_IMPORT, etc). The higher the number means that this queue item will get run before the lower numbers.
This comes in handy when you are doing a customer import, and then an invoice import that has to link all invoices to customers. Setting customer import ot
higher than the invoice import will ensure that all customers are imported first.
2 c) $map variable: This links all the SDK functions to PHP functions. These objects can be found in the Quickbooks.php file in the root of the sdk.
Each object takes an array, first being the request(where the XML is built and sent to quickbooks), and then the response (where XML is sent to from quickbooks)
These objects (QUICKBOOKS_ADD_INVOICE, QUICKBOOKS_ADD_CUSTOMER,QUICKBOOKS_IMPORT_CUSTOMER, etc) are what get queued up in relation to the priorities from above.
2 d) $errmap variable: This defines functions to get called when things error.
!IMPORTANT! If you query quickbooks( for example with a QUICKBOOKS_QUERY_CUSTOMER ) and it returns no results, meaning it could not find that particular customer,
then it will throw an error that should be caught by these error handlers. It does not return a blank set to the response, and the response function does not get called.
2 e) $hooks variable: Is where various callbacks are setup, most importantly the Post login success function which is where the queue gets built one time.
2 f) $log_level variable: Depending on this setting the SDK will log more or less data to the quickbooks_log
2 g) $handler_options variable: !IMPORTANT! SET deny_reallyfast_logins to false, if you try to run the update too fast it will say that it has nothing for the web connector
Setting this to false allows you to click update as many times as you want on the web connector and not have issues.
Also set up custom authentication to query our database. This function just needs to return true/false if user is authed
2 h) $dsn variable: This is just the link to the database, must set it to the QB_QUICKBOOKS_DSN constant.
2 i) If DB table are not initiliazed then intialize them
if (!QuickBooks_Utilities::initialized($dsn))
{
// Create the database tables
QuickBooks_Utilities::initialize($dsn);
}
3) QUEUE, this is setup in the hook for login success
We create a $Queue singleton instance.
Using quickbooks_set_last_run/get_last_run will write or read from quickbooks_config.
This can be used in a variety of ways.
a) Checking if a particular object (usually imports) hasn't been run before and then queuing it up for a one time run
b) Using get_last_run and using LastModified date to get changed records (customers, etc)
Usually check if QBRefID is null for records that have not been inserted in quickbooks, then queue up an add.
!IMPORTANT! This is the main place that you queue stuff up but you can queue anything up from any function.
All you have to do is create a Queue instance and add stuff. The PHP SDK will make sure it gets run.
4) The $Queue->enqueue function takes these parameters. The action, $ident is usually our PK, priority is explained above, and $extra is additional information to pass along to the response
The extra param gets serialized and saved in the quickbooks_queue. Often it is used to save the editsequence for when a modification of a customer needs to take place
* @param string $action An action to be performed within QuickBooks (see the qbXML and QuickBooks SDK documentation, i.e.: "CustomerAdd", "InvoiceAdd", "CustomerMod", etc.)
* @param mixed $ident A unique identifier (if required) for a record being operated on (i.e. if you're doing a "CustomerAdd", you'd probaly put a unique customer ID number here, so you're SOAP handler function knows which customer it is supposed to add)
* @param integer $priority The priority of the update (higher priority actions will be pushed to QuickBooks before lower priority actions)
* @param array $extra If you need to make additional bits of data available to your request/response functions, you can pass an array of extra data here
* @param string $user The username of the QuickBooks Web Connector user this item should be queued for
* @param boolean $replace Whether or not to replace any other currently queued entries with the same action/ident
* @return boolean
5 a) Request functions: These merely return properly formatted XML. This is what will get sent to quickbooks, and must be in the same order as the documentation.(https://member.developer.intuit.com/qbSDK-current/Common/newOSR/index.html)
5 b) Response functions: XML gets sent here, and needs to be processed however.
6) EDIT SEQUENCE
In order to edit a customer, invoice, payment, or anything you must query for it first.
The process to edit a customer would go like this.
a) In hook login success query for anything with LastModified that is >= to whenever QUICKBOOKS_CUSTOMER_MOD was previously run
b) If yes then queue up QUICKBOOKS_CUSTOMER_QUERY with the $ident being the CustomerPK
c) The customer_query_request function gets called, we build the XML query to search quickbooks based on the QBRefID in our database (using ListID param in QB xml)
d) The customer_query_response function gets called, here we parse out the ListID(our QBRefID) and the EditSequence param.
e) $Queue->enqueue(QUICKBOOKS_CUSTOMER_MOD,$CustomerPK,QUICKBOOKS_CUSTOMER_MOD_PRIORITY,$EDITSEQUENCE)
----The customer mod is now queued up since the customer was found in quickbooks
f) The customer_mod_request function gets called with all the information that was just queued up. Now simply build the xml for customer_mod and add in the <EditSequence></EditSequence> into the xml
g) The customer_mod_response gets called, update whatever is needed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment