![](/img/trans.png)
[英]PHP QuickBooks Web Connector consolibyte - no data exchange required
[英]“no data exchange required”
我是quickbook的新手,我的客戶希望將他的Magento訂單與QuickBooks同步。 他使用QuickBooks Enterprises桌面版來同步訂單。 我們正在使用PHP devkit Web連接器並嘗試在doc中給出的示例示例來添加客戶。
添加客戶示例第一次工作正常,但在此之后,當我嘗試添加另一個客戶時,我在快速Web連接器中收到了“需要數據交換”消息,並且用戶未添加到quickbook中。
請幫我解決一下,並指導我如何將Magento訂單添加到quickbook和客戶。 以下是我使用的代碼:
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);
if (function_exists('date_default_timezone_set')){
date_default_timezone_set('America/New_York');
}
require_once '../QuickBooks.php';
$user = 'quickbooks';
$pass = 'password';
$map = array(
QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
QUICKBOOKS_ADD_INVOICE => array( '_quickbooks_invoice_add_request', '_quickbooks_invoice_add_response' )
);
$errmap = array();
$hooks = array();
$log_level = QUICKBOOKS_LOG_DEVELOP;
$dsn = 'mysql://root:root@localhost/quickbooks_server';
if (!QuickBooks_Utilities::initialized($dsn))
{
QuickBooks_Utilities::initialize($dsn);
QuickBooks_Utilities::createUser($dsn, $user, $pass);
$primary_key_of_your_customer = 5;
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
$Queue->enqueue(QUICKBOOKS_ADD_INVOICE, $primary_key_of_your_customer);
}
$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)
{
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>Muralidhar, LLC (' . mt_rand() . ')</Name>
<CompanyName>Muralidhar, LLC</CompanyName>
<FirstName>Muralidhar</FirstName>
<LastName>Jampa</LastName>
<BillAddress>
<Addr1>Muralidhar, LLC</Addr1>
<Addr2>134 Stonemill Road</Addr2>
<City>NewYork</City>
<State>NY</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>murarimaniram@gmail.com</Email>
<Contact>Muralidhar Jampa</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)
{
return;
}
function _quickbooks_invoice_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<InvoiceAddRq requestID="' . $requestID . '">
<InvoiceAdd>
<CustomerRef>
<FullName>Muralidhar Jampa</FullName>
</CustomerRef>
<TxnDate>2014-04-14</TxnDate>
<RefNumber>9869</RefNumber>
<BillAddress>
<Addr1>56 Cowles Road</Addr1>
<City>Willington</City>
<State>CT</State>
<PostalCode>06279</PostalCode>
<Country>United States</Country>
</BillAddress>
<PONumber></PONumber>
<Memo></Memo>
<InvoiceLineAdd>
<ItemRef>
<FullName>Test Item</FullName>
</ItemRef>
<Desc>Item 1 Description Goes Here</Desc>
<Quantity>1</Quantity>
<Rate>295</Rate>
</InvoiceLineAdd>
<InvoiceLineAdd>
<ItemRef>
<FullName>Test Item</FullName>
</ItemRef>
<Desc>Item 2 Description Goes Here</Desc>
<Quantity>3</Quantity>
<Rate>25</Rate>
</InvoiceLineAdd>
</InvoiceAdd>
</InvoiceAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $xml;
}
function _quickbooks_invoice_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
return;
}
?>
如果您閱讀示例文件中的注釋,您將找到以下注釋:
// IMPORTANT NOTE: This particular example of queueing something up will
// only ever happen *once* when these scripts are first run/used. After
// this initial test, you MUST do your queueing in another script. DO NOT
// DO YOUR OWN QUEUEING IN THIS FILE! See
// docs/example_web_connector_queueing.php for more details and examples
// of queueing things up.
以及此頁面的鏈接:
哪個說:
沒有可交換的數據。 沒有什么可做的。 Web連接器和此框架使用“隊列”概念。 一旦隊列為空,沒有別的事可做,你就會得到那條消息。 如果您向隊列中添加了一些內容,那么它將處理這些項目,直到沒有任何事情要做,然后您將再次收到“無數據交換...”消息。
因此,例如,假設您要構建一個流程,每次在您的商店中創建客戶時,客戶都會在QuickBooks中創建。 然后,您需要設置一個流程,在該流程中,在您的商店中創建該客戶時,您將請求排隊以將客戶添加到QuickBooks。
您使用QuickBooks_Queue類和→enqueue()方法進行排隊。
所以基本上問題是你沒有告訴它做任何事情 。 該示例僅向QuickBooks添加一個客戶。
如果要添加更多客戶,則需要對某些內容進行排隊,以便嘗試執行此操作。
排隊時,請注意您必須在其他地方進行排隊。 不要在這個文件中加入錯誤(就像上面的評論所說的那樣)。
因此,在您的應用程序中的其他位置,當您向應用程序數據庫添加新客戶時,您可能會有一些類似的代碼:
// end-user submitted a form, let's save the customer to our database
if ($_POST['customer_name'])
{
mysql_query("INSERT INTO my_customer_table ( ... ) VALUES ( ... )");
}
你應該修改你的應用程序代碼,然后看起來像這樣:
// end-user submitted a form, let's save the customer to our database
if ($_POST['customer_name'])
{
mysql_query("INSERT INTO my_customer_table ( ... ) VALUES ( ... )");
// ... and queue them up to be added to QB
$primary_key_of_your_customer = mysql_insert_id();
$Queue = new QuickBooks_WebConnector_Queue($dsn);
$Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);
}
作為旁注,請注意此塊中的任何內容:
if (!QuickBooks_Utilities::initialized($dsn))
{
只運行ONCE。 因此,不要在這個塊中做任何事情 - 它不會再次運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.