/**
  * 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);
 }
    $file = dirname(__FILE__) . '/example.sql';
    if (file_exists($file)) {
        $contents = file_get_contents($file);
        foreach (explode(';', $contents) as $sql) {
            if (!trim($sql)) {
                continue;
            }
            mysql_query($sql) or die(trigger_error(mysql_error()));
        }
    } else {
        die('Could not locate "./example.sql" to create the demo SQL schema!');
    }
    //
    QuickBooks_Utilities::initialize($api_driver_dsn);
    // This
    QuickBooks_Utilities::createUser($api_driver_dsn, $user, $pass);
}
//
$API = new QuickBooks_API($api_driver_dsn, $user, $source_type, $source_dsn, $api_options, $source_options, $driver_options);
// Get the complete list of "Customers" from QuickBooks
//
// Unfortunately, non-US versions of QuickBooks do not yet support the use of
//	"iterators" to break up the response from QuickBooks into many smaller
//	chunks. So, if we ask for the complete customer list, the response is so
//	large that the transfer takes a long time, the Web Connector times out, or
//	the HTTP server throws an error after receiving to much data.
//
//	Thus, instead of sending just a single request, we're going to fetch the
//	list of customers by date range instead.
$seconds_in_a_day = 60 * 60 * 24;
for ($i = strtotime('2009-04-07'); $i < time(); $i = $i + $seconds_in_a_day) {
				$CustomerID AS ListObjID, 
				ordbillemail AS DataExtValue
			FROM
				isc_orders
			WHERE
				orderid = SUBSTRING($CustomerID, 3) AND 
				$CustomerID LIKE \'O:%\'
		) '), 'orderitem_additional_queries' => array(0 => '
			SELECT 
				ordershipmodule AS ShipMethodID, 
				(ordhandlingcost + ordshipcost) AS Amount,
				CONCAT(\'Shipping and Handling: \', ordshipmethod) AS Descrip,
				\'' . QUICKBOOKS_NONTAXABLE . '\' AS SalesTaxCodeName
			FROM
				isc_orders
			WHERE
				orderid = $OrderID', 1 => '
			SELECT
				CONCAT(\'Billing phone number: \', ordbillphone, \', Shipping phone number: \', ordshipphone) AS Descrip
			FROM
				isc_orders
			WHERE
				orderid = $OrderID '));
$callback_options = array();
if (!QuickBooks_Utilities::initialized($dsn)) {
    QuickBooks_Utilities::initialize($dsn);
    QuickBooks_Utilities::createUser($dsn, $user, $pass);
}
//
$Server = new QuickBooks_Server_Integrator_Interspire($dsn, $integrator_dsn, $alert, $user, $map, $onerror, $hooks, $log_level, $soap, $wsdl, $soap_options, $handler_options, $driver_options, $api_options, $source_options, $integrator_options, $callback_options);
$Server->handle(true, true);
set_time_limit(0);
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/Users/kpalmer/Projects/QuickBooks');
require_once 'QuickBooks.php';
if (function_exists('date_default_timezone_set')) {
    date_default_timezone_set('America/New_York');
}
$username = '******';
$password = '******';
error_reporting(E_ALL);
ini_set('display_errors', 1);
//rint(wtaf');
$dsn = 'mysql://*****:*****@localhost/quickbooksWIP2';
if (!QuickBooks_Utilities::initialized($dsn)) {
    header('Content-Type: text/plain');
    $driver_options = array();
    $init_options = array('quickbooks_sql_enabled' => true);
    QuickBooks_Utilities::initialize($dsn, $driver_options, $init_options);
    QuickBooks_Utilities::createUser($dsn, $username, $password);
    exit;
}
$mode = QUICKBOOKS_SERVER_SQL_MODE_READONLY;
//$mode = QUICKBOOKS_SERVER_SQL_MODE_WRITEONLY;
//$mode = QUICKBOOKS_SERVER_SQL_MODE_READWRITE;
//Delete Modes -- Remove or Flag?
//$deleteMode = QUICKBOOKS_SERVER_SQL_ON_DELETE_FLAG;
$deleteMode = QUICKBOOKS_SERVER_SQL_ON_DELETE_REMOVE;
// $dsn_or_conn, $how_often, $mode, $conflicts, $users = null,
//	$map = array(), $onerror = array(), $hooks = array(), $log_level, $soap = QUICKBOOKS_SOAPSERVER_BUILTIN, $wsdl = QUICKBOOKS_WSDL, $soap_options = array(), $handler_options = array(), $driver_options = array()
$server = new QuickBooks_Server_SQL($dsn, '1 minute', $mode, $deleteMode, QUICKBOOKS_SERVER_SQL_CONFLICT_NEWER, $username, array(), array(), array(), QUICKBOOKS_LOG_DEVELOP, QUICKBOOKS_SOAPSERVER_PHP, QUICKBOOKS_WSDL);
$server->handle(true, true);
 * 
 */
require_once 'QuickBooks.php';
$user = '******';
$source_type = QUICKBOOKS_API_SOURCE_WEB;
$api_driver_dsn = 'mysql://*****:*****@localhost/quickbooks_api';
//$api_driver_dsn = 'pgsql://pgsql@localhost/quickbooks';
$source_dsn = 'http://*****:*****@localhost/path/to/server.php';
$api_options = array();
$source_options = array();
$driver_options = array();
if (!QuickBooks_Utilities::initialized($api_driver_dsn)) {
    //
    QuickBooks_Utilities::initialize($api_driver_dsn);
    //
    QuickBooks_Utilities::createUser($api_driver_dsn, 'api', 'password');
}
$API = new QuickBooks_API($api_driver_dsn, $user, $source_type, $source_dsn, $api_options, $source_options, $driver_options);
// CUSTOMERS
$fname = 'Shannon ' . mt_rand();
$lname = 'Daniels';
$Customer = new QuickBooks_Object_Customer();
$Customer->setFirstName($fname);
$Customer->setLastName($lname);
$Customer->setShipAddress('56 Cowles Road', '', '', '', '', 'Willington', 'CT');
$Customer->setMiddleName('R');
$Customer->setSalutation('Mr.');
$Customer->setPhone('1.860.634.1602');
$API->addCustomer($Customer, '_quickbooks_customer_add_callback', 15);
// INVOICES
$Invoice = new QuickBooks_Object_Invoice();
Beispiel #6
0
 * 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
 */
// 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('America/New_York');
}
// I always program in E_STRICT error mode...
error_reporting(E_ALL | E_STRICT);
// Require the framework
require_once dirname(__FILE__) . '/../../QuickBooks.php';
// Your .QWC file username/password
$qbwc_user = '******';
$qbwc_pass = '******';
// * MAKE SURE YOU CHANGE THE DATABASE CONNECTION STRING BELOW TO A VALID MYSQL USERNAME/PASSWORD/HOSTNAME *
$dsn = 'mysql://*****:*****@localhost/quickbooks_example_app_web_connector';
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, $qbwc_user, $qbwc_pass);
    // Create our test table
    mysql_query("CREATE TABLE my_customer_table (\n\t  id int(10) unsigned NOT NULL AUTO_INCREMENT,\n\t  name varchar(64) NOT NULL,\n\t  fname varchar(64) NOT NULL,\n\t  lname varchar(64) NOT NULL,\n\t  quickbooks_listid varchar(255) DEFAULT NULL,\n\t  quickbooks_editsequence varchar(255) DEFAULT NULL,\n\t  quickbooks_errnum varchar(255) DEFAULT NULL,\n\t  quickbooks_errmsg varchar(255) DEFAULT NULL,\n\t  PRIMARY KEY (id)\n\t) ENGINE=MyISAM");
}
 /**
  * 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);
 }
//	style connection string to the database here.
$api_driver_dsn = null;
// $api_driver_dsn = 'mysql://root:@localhost/quickbooks_api';
// $api_driver_dsn = 'pgsql://pgsql@localhost/quickbooks_onlineedition';
// This is not applicable to QBOE
$source_dsn = null;
// Various API options
$api_options = array();
// Options for QBOE
$source_options = array('certificate' => '/Users/kpalmer/Projects/QuickBooks/QuickBooks/dev/test_qboe.pem', 'connection_ticket' => 'TGT-47-1sRm2nXMVfm$n8hb2MZfVQ', 'application_login' => 'test.www.academickeys.com', 'application_id' => '134476472');
// Driver options
$driver_options = array();
// If you want to log requests/responses to a database, initialize the database
if ($api_driver_dsn and !QuickBooks_Utilities::initialized($api_driver_dsn)) {
    QuickBooks_Utilities::initialize($api_driver_dsn);
    QuickBooks_Utilities::createUser($api_driver_dsn, $username, $password);
}
// Create the API instance
$API = new QuickBooks_API($api_driver_dsn, $username, $source_type, $source_dsn, $api_options, $source_options, $driver_options);
// Turn on debugging mode
//$API->useDebugMode(true);
// With QuickBooks Online Edition, the API can return values to you rather than
//	using callback functions to return values. Remember that is you use this,
//	your code will be less portable to systems using non-real-time connections
//	(i.e. the QuickBooks Web Connector).
//$API->enableRealtime(true);
// Let's get some general information about this connection to QBOE:
print 'Our connection ticket is: ' . $API->connectionTicket() . "\n";
print 'Our session ticket is: ' . $API->sessionTicket() . "\n";
print 'Our application id is: ' . $API->applicationID() . "\n";
print 'Our application login is: ' . $API->applicationLogin() . "\n";