public function qbwcAction()
 {
     // Set up our queue singleton
     \QuickBooks_WebConnector_Queue_Singleton::initialize($this->container->get('jfortunato_quick_books_desktop.config')->getDsn());
     $server = $this->container->get('jfortunato_quick_books_desktop.wrapper.server');
     $handled = $server->handle(true, true);
     $response = new Response();
     $response->headers->set('Content-Type', 'text/xml');
     return $response;
 }
Example #2
0
 /**
  * Houses the instance of the soap server and creates the mappings for errors, function callbacks
  * @author Jayson Lindsley <*****@*****.**>
  */
 public function action_index()
 {
     //Username and password used for the web connector, QWC file, and the QB Framework
     $user = '******';
     $pass = '******';
     //Configure the logging level
     $log_level = QUICKBOOKS_LOG_DEVELOP;
     //Pure-PHP SOAP server
     $soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
     //we can turn this off
     $handler_options = array('deny_concurrent_logins' => false, 'deny_reallyfast_logins' => false);
     // The next three params $map, $errmap, and $hooks are callbacks which
     // will be called when certain actions/events/requests/responses occur within
     // the framework
     // Maps inbound requests to functions
     $map = array(QUICKBOOKS_ADD_CUSTOMER => array(array($this, '_quickbooks_customer_add_request'), array($this, '_quickbooks_customer_add_response')), QUICKBOOKS_MOD_CUSTOMER => array(array($this, '_quickbooks_customer_mod_request'), array($this, '_quickbooks_customer_mod_response')));
     //Map error handling to functions
     $errmap = array(3070 => array($this, '_quickbooks_error_stringtoolong'), 3140 => array($this, '_quickbooks_reference_error'), '*' => array($this, '_quickbooks_error_handler'));
     //Login success callback
     $hooks = array(QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => array(array($this, '_quickbooks_hook_loginsuccess')));
     //MySQL database name containing the QuickBooks tables is named 'quickbooks' (if the tables don't exist, they'll be created for you)
     $dsn = 'mysql://*****:*****@host/databasename';
     QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
     if (!QuickBooks_Utilities::initialized($dsn)) {
         // Initialize creates the neccessary database schema for queueing up requests and logging
         QuickBooks_Utilities::initialize($dsn);
         // This creates a username and password which is used by the Web Connector to authenticate
         QuickBooks_Utilities::createUser($dsn, $user, $pass);
         // Initial test case customer
         $primary_key_of_new_customer = 512;
         // Fire up the Queue
         $Queue = new QuickBooks_WebConnector_Queue($dsn);
         // Drop the directive and the customer into the queue
         $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_new_customer);
         // Also note the that ->enqueue() method supports some other parameters:
         // 	string $action				The type of action to queue up
         //	mixed $ident = null			Pass in the unique primary key of your record here, so you can pull the data from your application to build a qbXML request in your request handler
         //	$priority = 0				You can assign priorities to requests, higher priorities get run first
         //	$extra = null				Any extra data you want to pass to the request/response handler
         //	$user = null				If you're using multiple usernames, you can pass the username of the user to queue this up for here
         //	$qbxml = null
         //	$replace = true
     }
     //To be used with singleton queue
     $driver_options = array();
     //Callback options, not needed at the moment
     $callback_options = array();
     //nothing needed here at the moment
     $soap_options = array();
     //construct a new instance of the web connector server
     $Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
     //instruct server to handle responses
     $response = $Server->handle(true, true);
 }
Example #3
0
 /**
  * Get the instance of the queueing class
  * 
  * @return QuickBooks_Queue
  */
 public static function getInstance()
 {
     return QuickBooks_WebConnector_Queue_Singleton::initialize(null, null, null, false);
 }
Example #4
0
 /**
  * SOAP endpoint for the Web Connector to connect to
  */
 public function qbwc()
 {
     $user = $this->config->item('quickbooks_user');
     $pass = $this->config->item('quickbooks_pass');
     // Memory limit
     ini_set('memory_limit', $this->config->item('quickbooks_memorylimit'));
     // We need to make sure the correct timezone is set, or some PHP installations will complain
     if (function_exists('date_default_timezone_set')) {
         // * MAKE SURE YOU SET THIS TO THE CORRECT TIMEZONE! *
         // List of valid timezones is here: http://us3.php.net/manual/en/timezones.php
         date_default_timezone_set($this->config->item('quickbooks_tz'));
     }
     // Map QuickBooks actions to handler functions
     $map = array(QUICKBOOKS_ADD_CUSTOMER => array(array($this, '_addCustomerRequest'), array($this, '_addCustomerResponse')));
     // Catch all errors that QuickBooks throws with this function
     $errmap = array('*' => array($this, '_catchallErrors'));
     // Call this method whenever the Web Connector connects
     $hooks = array();
     // An array of callback options
     $callback_options = array();
     // Logging level
     $log_level = $this->config->item('quickbooks_loglevel');
     // What SOAP server you're using
     //$soapserver = QUICKBOOKS_SOAPSERVER_PHP;			// The PHP SOAP extension, see: www.php.net/soap
     $soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN;
     // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
     $soap_options = array();
     $handler_options = array('deny_concurrent_logins' => false, 'deny_reallyfast_logins' => false);
     // See the comments in the QuickBooks/Server/Handlers.php file
     $driver_options = array('max_log_history' => 32000, 'max_queue_history' => 1024);
     // Build the database connection string
     $dsn = 'mysql://' . $this->db->username . ':' . $this->db->password . '@' . $this->db->hostname . '/' . $this->db->database;
     // Check to make sure our database is set up
     if (!QuickBooks_Utilities::initialized($dsn)) {
         // Initialize creates the neccessary database schema for queueing up requests and logging
         QuickBooks_Utilities::initialize($dsn);
         // This creates a username and password which is used by the Web Connector to authenticate
         QuickBooks_Utilities::createUser($dsn, $user, $pass);
     }
     // Set up our queue singleton
     QuickBooks_WebConnector_Queue_Singleton::initialize($dsn);
     // Create a new server and tell it to handle the requests
     // __construct($dsn_or_conn, $map, $errmap = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_PHP, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $callback_options = array()
     $Server = new QuickBooks_WebConnector_Server($dsn, $map, $errmap, $hooks, $log_level, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
     $response = $Server->handle(true, true);
 }
/**
 * Handle a 500 not found error from QuickBooks
 * 
 * Instead of returning empty result sets for queries that don't find any 
 * records, QuickBooks returns an error message. This handles those error 
 * messages, and acts on them by adding the missing item to QuickBooks. 
 */
function _quickbooks_error_e500_notfound($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
    $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
    if ($action == QUICKBOOKS_IMPORT_INVOICE) {
        return true;
    } else {
        if ($action == QUICKBOOKS_IMPORT_CUSTOMER) {
            return true;
        } else {
            if ($action == QUICKBOOKS_IMPORT_SALESORDER) {
                return true;
            } else {
                if ($action == QUICKBOOKS_IMPORT_ITEM) {
                    return true;
                } else {
                    if ($action == QUICKBOOKS_IMPORT_PURCHASEORDER) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
/** 
 * Handle a response from QuickBooks 
 */
function _quickbooks_customer_import_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
    if (!empty($idents['iteratorRemainingCount'])) {
        // Queue up another request
        $Queue = QuickBooks_WebConnector_Queue_Singleton::getInstance();
        $Queue->enqueue(QUICKBOOKS_IMPORT_CUSTOMER, null, 0, array('iteratorID' => $idents['iteratorID']));
    }
    // This piece of the response from QuickBooks is now stored in $xml. You
    //	can process the qbXML response in $xml in any way you like. Save it to
    //	a file, stuff it in a database, parse it and stuff the records in a
    //	database, etc. etc. etc.
    //
    // The following example shows how to use the built-in XML parser to parse
    //	the response and stuff it into a database.
    // Import all of the records
    $errnum = 0;
    $errmsg = '';
    $Parser = new QuickBooks_XML_Parser($xml);
    if ($Doc = $Parser->parse($errnum, $errmsg)) {
        $Root = $Doc->getRoot();
        $List = $Root->getChildAt('QBXML/QBXMLMsgsRs/CustomerQueryRs');
        foreach ($List->children() as $Customer) {
            $values = array('ListID' => $Customer->getChildDataAt('CustomerRet ListID'), 'FullName' => $Customer->getChildDataAt('CustomerRet FullName'), 'FirstName' => $Customer->getChildDataAt('CustomerRet FirstName'), 'LastName' => $Customer->getChildDataAt('CustomerRet LastName'));
            foreach ($Customer->children() as $Node) {
                // Be careful! Custom field names are case sensitive!
                if ($Node->name() === 'DataExtRet' and $Node->getChildDataAt('DataExtRet DataExtName') == 'Your Custom Field Name Goes Here') {
                    $values['Your Custom Field Names Goes Here'] = $Node->getChildDataAt('DataExtRet DataExtValue');
                }
            }
            // Do something with that data...
            // mysql_query("INSERT INTO ... ");
        }
    }
    return true;
}