问题
I'm using the awesome consolibyte framework for Quickbooks but I'm having trouble adding a simple xml request. I have the web connector set up and it successfully runs through the update with no error, but nothing gets added to quickbooks. I'm testing with Keith's sample xml and I also tried my own xml that I know successfully inserts time through the Quickbooks SDK. I'm using the sample file docs/web_connector/example_web_connector.php I've also tried other sample files but nothing ever added to Quickbooks. I'm developing locally so not using https. Log files don't show errors. Any suggestions? Thanks.
sample-time.php is the file that i'm connecting to: (I edited the example_web_connector.php file). I removed most of the comments.
Shouldn't it queue up the xml and add ConsoliBYTE, LLCxxxx to the customer list?
<?php
// I always program in E_STRICT error mode...
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// 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');
}
// Require the framework
require_once '../QuickBooks.php';
$user = 'quickbooks';
$pass = 'password';
// Map QuickBooks actions to handler functions
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
);
// This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
$errmap = array(
3070 => '_quickbooks_error_stringtoolong',
);
// An array of callback hooks
$hooks = array(
);
// Logging level
$log_level = QUICKBOOKS_LOG_DEBUG;
$soapserver = QUICKBOOKS_SOAPSERVER_BUILTIN; // A pure-PHP SOAP server (no PHP ext/soap extension required, also makes debugging easier)
$soap_options = array( // See http://www.php.net/soap
);
$handler_options = array(
'deny_concurrent_logins' => false,
'deny_reallyfast_logins' => false,
); // See the comments in the QuickBooks/Server/Handlers.php file
$driver_options = array(
);
$callback_options = array(
);
$dsn = 'mysql://douggie:testit@localhost/test';
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);
$primary_key_of_your_customer = 10023;
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}
// 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);
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
// But we're just testing, so we'll just use a static test request:
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE, LLC</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE, LLC</Addr1>
<Addr2>134 Stonemill Road</Addr2>
<City>Mansfield</City>
<State>CT</State>
<PostalCode>06268</PostalCode>
<Country>United States</Country>
</BillAddress>
<Phone>860-634-1602</Phone>
<AltPhone>860-429-0021</AltPhone>
<Fax>860-429-5183</Fax>
<Email>Keith@ConsoliBYTE.com</Email>
<Contact>Keith Palmer</Contact>
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
}
function _quickbooks_salesreceipt_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
/*
<CustomerRef>
<ListID>80003579-1231522938</ListID>
</CustomerRef>
*/
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<SalesReceiptAddRq requestID="' . $requestID . '">
<SalesReceiptAdd>
<CustomerRef>
<FullName>Keith Palmer Jr.</FullName>
</CustomerRef>
<TxnDate>2009-01-09</TxnDate>
<RefNumber>16466</RefNumber>
<BillAddress>
<Addr1>Keith Palmer Jr.</Addr1>
<Addr3>134 Stonemill Road</Addr3>
<City>Storrs-Mansfield</City>
<State>CT</State>
<PostalCode>06268</PostalCode>
<Country>United States</Country>
</BillAddres>
<SalesReceiptLineAdd>
<ItemRef>
<FullName>Gift Certificate</FullName>
</ItemRef>
<Desc>$25.00 gift certificate</Desc>
<Quantity>1</Quantity>
<Rate>25.00</Rate>
<SalesTaxCodeRef>
<FullName>NON</FullName>
</SalesTaxCodeRef>
</SalesReceiptLineAdd>
<SalesReceiptLineAdd>
<ItemRef>
<FullName>Book</FullName>
</ItemRef>
<Desc>The Hitchhiker\'s Guide to the Galaxy</Desc>
<Amount>19.95</Amount>
<SalesTaxCodeRef>
<FullName>TAX</FullName>
</SalesTaxCodeRef>
</SalesReceiptLineAdd>
</SalesReceiptAdd>
</SalesReceiptAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_salesreceipt_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
}
function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
mail('your-email@your-domain.com',
'QuickBooks error occured!',
'QuickBooks thinks that ' . $action . ': ' . $ID . ' has a value which will not fit in a QuickBooks field...');
}
QWClog:
55 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : updateWS() for application = 'Time Keeper' has STARTED
20160830.21:31:55 UTC : QBWebConnector.RegistryManager.getUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock = FALSE
20160830.21:31:55 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to True
20160830.21:31:55 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session locked *********************
20160830.21:31:55 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : Initiated connection to the following application.
20160830.21:31:55 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppName: Time Keeper
20160830.21:31:55 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppUniqueName (if available): Time Keeper
20160830.21:31:55 UTC : QBWebConnector.SOAPWebService.instantiateWebService() : AppURL: http://localhost/quickbooks-2016/docs/sample-time.php
20160830.21:31:55 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : *** Calling serverVersion().
20160830.21:31:57 UTC : QBWebConnector.SOAPWebService.do_serverVersion() : Received from serverVersion() following parameter:<serverVersionRet="PHP QuickBooks SOAP Server v3.0 at /quickbooks-2016/docs/sample-time.php">
20160830.21:31:57 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : *** Calling clientVersion() with following parameter:<productVersion="2.1.0.30">
20160830.21:32:00 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : Received from clientVersion() following parameter:<clientVersionRet="">
20160830.21:32:00 UTC : QBWebConnector.SOAPWebService.do_clientVersion() : This application agrees with the current version of QBWebConnector. Allowing update operation.
20160830.21:32:00 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Authenticating to application 'Time Keeper', username = 'quickbooks'
20160830.21:32:00 UTC : QBWebConnector.SOAPWebService.do_authenticate() : *** Calling authenticate() with following parameters:<userName="quickbooks"><password=<MaskedForSecurity>
20160830.21:32:02 UTC : QBWebConnector.SOAPWebService.updateWS() : Received from authenticate() following parameters:<authRet[0]="476baa7e-ee32-5e34-f90b-e3da55df0de5"><authRet[1]="none"><authRet[2]=""><authRet[3]="">
20160830.21:32:02 UTC : QBWebConnector.RegistryManager.setCurrentWebServiceName() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\CurrentWebServiceName has been set to Time Keeper
20160830.21:32:02 UTC : QBWebConnector.RegistryManager.setCurrentWebServiceSessionTicket() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\CurrentWebServiceSessionTicket has been set to 476baa7e-ee32-5e34-f90b-e3da55df0de5
20160830.21:32:02 UTC : QBWebConnector.SOAPWebService.CheckCFNResponse() : No data to exchange for this application. Job ending.
20160830.21:32:02 UTC : QBWebConnector.SOAPWebService.do_authenticate() : Done.
20160830.21:32:02 UTC : QBWebConnector.RegistryManager.setUpdateLock() : HKEY_CURRENT_USER\Software\Intuit\QBWebConnector\UpdateLock has been set to False
20160830.21:32:02 UTC : QBWebConnector.RegistryManager.setUpdateLock() : ********************* Update session unlocked *********************
20160830.21:32:02 UTC : QBWebConnector.WebServiceManager.DoUpdateSelected() : No data to exchange for the application: Time Keeper
来源:https://stackoverflow.com/questions/39234743/consolibyte-quickbooks-php-to-add-simple-xml