//	Queue up a request to add a new customer to QuickBooks
    //	$Queue = new QuickBooks_Queue($dsn);
    //	$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_new_customer);
    //
    // We're going to queue up a request to add a customer, just as a demo...
    // 	NOTE: You would *never* want to do this in this file *unless* it's for testing. See example_integration.php for more details!
    $primary_key_of_your_customer = 5;
    $Queue = new QuickBooks_WebConnector_Queue($dsn);
    $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_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
}
// Set the DSN string because some of our callbacks will use it
$obj->setDSN($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);
/*
// If you wanted, you could do something with $response here for debugging

$fp = fopen('/path/to/file.log', 'a+');
fwrite($fp, $response);
fclose($fp);
*/
Beispiel #2
0
 /**
  * 
  * 
  * You can run this server in one of three modes:
  * 	- QUICKBOOKS_SERVER_SQL_MODE_READONLY: Data will only be read from 
  * 		QuickBooks; changes to data in the SQL database will never be 
  * 		pushed back to QuickBooks. 
  * 	- QUICKBOOKS_SERVER_SQL_MODE_WRITEONLY: Data will only be pushed to 
  * 		QuickBooks, and nothing that already exists in QuickBooks will be 
  * 		imported into the SQL database.
  * 	- QUICKBOOKS_SERVER_SQL_MODE_READWRITE: The server will do it's best to 
  * 		try to import all QuickBooks data into the SQL database, and then 
  * 		push changes that occur in either location to the other location. 
  * 		The server will try to syncronise the two locations as much as is 
  * 		possible. 
  * 
  * @param string $dsn_or_conn		DSN-style connection string or an already opened connection to the driver
  * @param string $how_often			The maximum time we wait between updates/syncs (you can use any valid interval: "1 hour", "15 minutes", 60, etc.)
  * @param char $mode				The mode the server should run in (see constants above)
  * @param char $conflicts			The steps towards update conflict resolution the server should take (see constants above)
  * @param mixed $users				The user (or an array of users) who will be using the SQL server
  * @param array $map				
  * @param array $onerror			
  * @param string $wsdl				
  * @param array $soap_options		
  * @param array $handler_options	
  * @param array $driver_options		
  */
 public function __construct($dsn_or_conn, $how_often, $mode, $conflicts, $delete, $users = null, $map = array(), $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array(), $sql_options = array(), $callback_options = array())
 {
     // $dsn_or_conn, $map, $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
     if (!is_array($users)) {
         $users = array($users);
     }
     // Map of callback handlers
     $sql_map = array();
     foreach (get_class_methods('QuickBooks_Callbacks_SQL_Callbacks') as $method) {
         if (strtolower(substr($method, -7)) == 'request') {
             $action = substr($method, 0, -7);
             $sql_map[$action] = array('QuickBooks_Callbacks_SQL_Callbacks::' . $action . 'Request', 'QuickBooks_Callbacks_SQL_Callbacks::' . $action . 'Response');
         }
     }
     /*
     $sql_map[QUICKBOOKS_DERIVE_ITEM] = array( 
     	'QuickBooks_Callbacks_SQL_Callbacks::ItemDeriveRequest', 
     	'QuickBooks_Callbacks_SQL_Callbacks::ItemDeriveResponse' );
     	
     $sql_map[QUICKBOOKS_DERIVE_CUSTOMER] = array( 
     	'QuickBooks_Callbacks_SQL_Callbacks::CustomerDeriveRequest', 
     	'QuickBooks_Callbacks_SQL_Callbacks::CustomerDeriveResponse' );
     
     $sql_map[QUICKBOOKS_DERIVE_INVOICE] = array( 
     	'QuickBooks_Callbacks_SQL_Callbacks::InvoiceDeriveRequest', 
     	'QuickBooks_Callbacks_SQL_Callbacks::InvoiceDeriveResponse' );			
     */
     //print_r($sql_map);
     //exit;
     // Default error handlers
     $sql_onerror = array('*' => 'QuickBooks_Callbacks_SQL_Errors::catchall');
     $sql_onerror = $this->_merge($sql_onerror, $onerror, false);
     // Default hooks
     $sql_hooks = array(QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => array('QuickBooks_Callbacks_SQL_Callbacks::onAuthenticate'));
     // Merge with user-defined hooks
     $sql_hooks = $this->_merge($hooks, $sql_hooks, true);
     // @TODO Prefix these with _ so that people don't accidentally overwrite them
     $sql_callback_options = array('hooks' => $sql_hooks, 'conflicts' => $conflicts, 'mode' => $mode, 'delete' => $delete, 'recur' => QuickBooks_Utilities::intervalToSeconds($how_often), 'map' => $sql_map);
     //print_r($sql_options);
     //exit;
     $defaults = $this->_sqlDefaults($sql_options);
     //$sql_callback_options['_only_query'] = $defaults['only_query'];
     //$sql_callback_options['_dont_query'] = $defaults['dont_query'];
     $sql_callback_options['_only_import'] = $defaults['only_import'];
     $sql_callback_options['_dont_import'] = $defaults['dont_import'];
     $sql_callback_options['_only_add'] = $defaults['only_add'];
     $sql_callback_options['_dont_add'] = $defaults['dont_add'];
     $sql_callback_options['_only_modify'] = $defaults['only_modify'];
     $sql_callback_options['_dont_modify'] = $defaults['dont_modify'];
     $sql_callback_options['_only_misc'] = $defaults['only_misc'];
     $sql_callback_options['_dont_misc'] = $defaults['dont_misc'];
     // Merge default values with passed in values
     //	(in this case, we are *required* to have these values present, so
     //	we make sure that the SQL options override any user-defined options
     $sql_callback_options = $this->_merge($callback_options, $sql_callback_options, false);
     // Initialize the Driver singleton
     $Driver = QuickBooks_Driver_Singleton::getInstance($dsn_or_conn, $driver_options, $sql_hooks, $log_level);
     // $dsn_or_conn, $map, $onerror = array(), $hooks = array(), $log_level = QUICKBOOKS_LOG_NORMAL, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
     parent::__construct($dsn_or_conn, $sql_map, $sql_onerror, $sql_hooks, $log_level, $soap, $wsdl, $soap_options, $handler_options, $driver_options, $sql_callback_options);
     /*
     // TESTING only
     $requestID = null;
     $user = '******';
     $hook = QUICKBOOKS_HANDLERS_HOOK_LOGINSUCCESS;
     $err = null;
     $hook_data = array();
     $callback_config = $sql_callback_options;
     QuickBooks_Callbacks_SQL_Callbacks::onAuthenticate($requestID, $user, $hook, $err, $hook_data, $callback_config);
     */
 }
 /**
  * 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);
 }
 /**
  * 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);
 }