/** * 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); }
QuickBooks_Utilities::createUser($dsn, $user, $pass); // Queueing up a test request // // You can instantiate and use the QuickBooks_Queue class to queue up // actions whenever you want to queue something up to be sent to // QuickBooks. So, for instance, a new customer is created in your // database, and you want to add them to QuickBooks: // // 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);
* * @author Keith Palmer <*****@*****.**> * * @package QuickBooks * @subpackage Documentation */ // Error reporting for easier debugging ini_set('display_errors', true); error_reporting(E_ALL | E_STRICT); // Require the queueuing class require_once '../QuickBooks.php'; if (isset($_POST['customer'])) { // Oooh, here's a new customer, let's do some stuff with them // Connect to your own MySQL server.... $link = mysql_connect('localhost', 'your_mysql_username', 'your_mysql_password'); if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); } // ... and use the correct database $selected = mysql_select_db('your_database_name', $link); if (!$selected) { die('Could not select database: ' . mysql_error()); } // Insert into our local MySQL database mysql_query("INSERT INTO my_customer_table ( name, phone, email ) VALUES ( '" . $_POST['customer']['name'] . "', '" . $_POST['customer']['phone'] . "', '" . $_POST['customer']['email'] . "' ) "); $id_value = mysql_insert_id(); // QuickBooks queueing class $Queue = new QuickBooks_WebConnector_Queue('mysql://*****:*****@localhost/my_database'); // Queue it up! $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $id_value); }
<?php /** * Example Web Connector application * * This is a very simple application that allows someone to enter a customer * name into a web form, and then adds the customer to QuickBooks. * * @author Keith Palmer <*****@*****.**> * * @package QuickBooks * @subpackage Documentation */ /** * Require some configuration stuff */ require_once dirname(__FILE__) . '/config.php'; // Handle the form post if (isset($_POST['submitted'])) { // Save the record mysql_query("\n\t\tINSERT INTO\n\t\t\tmy_customer_table\n\t\t(\n\t\t\tname, \n\t\t\tfname, \n\t\t\tlname\n\t\t) VALUES (\n\t\t\t'" . mysql_escape_string($_POST['name']) . "', \n\t\t\t'" . mysql_escape_string($_POST['fname']) . "', \n\t\t\t'" . mysql_escape_string($_POST['lname']) . "'\n\t\t)"); // Get the primary key of the new record $id = mysql_insert_id(); // Queue up the customer add $Queue = new QuickBooks_WebConnector_Queue($dsn); $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $id); die('Great, queued up a customer!'); }
/** * Queue up a request for the Web Connector to process */ public function enqueue($action, $ident, $priority = 0, $extra = null, $user = null) { $Queue = new QuickBooks_WebConnector_Queue($this->_dsn); return $Queue->enqueue($action, $ident, $priority, $extra, $user); }