尝试使用QB Web连接器实现consolibyte / quickbooks-php

问题描述 投票:0回答:1

我尝试通过QB Web Connector实现example_web_connector我将App添加到QBWC,密码,验证通过,但QBWC收到错误“0x80045242:QBPOSXML:未知请求版本”在哪一方我必须“看”?

  1. QB POS 2013
  2. QBSDK 13.0
  3. QBC <?xml version="1.0"?> <QBWCXML> <AppName>QB</AppName> <AppID>IDNTS_POS_1</AppID> <AppURL>http://localhost/</AppURL> <AppDescription>QB</AppDescription> <AppSupport>http://localhost/dashboard/</AppSupport> <UserName>test</UserName> <OwnerID>{A91CC425-ABC4-4972-9FC6-D5F6B90F0472}</OwnerID> <FileID>{349C0857-7A5D-428c-B0B9-E0AC9377EE14}</FileID> <QBType>QBPOS</QBType> <Style>Document</Style> </QBWCXML> 来自http://localhost/的index.php的示例代码

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-master/QuickBooks.php';

$user = 'test';
$pass = 'test';

// Map QuickBooks actions to handler functions
$map = array(
    QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ),
    //QUICKBOOKS_ADD_SALESRECEIPT => array( '_quickbooks_salesreceipt_add_request', '_quickbooks_salesreceipt_add_response' ), 
    //'*' => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' ), 
    // ... more action handlers here ...
    );

// This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
$errmap = array(
    3070 => '_quickbooks_error_stringtoolong',              // Whenever a string is too long to fit in a field, call this function: _quickbooks_error_stringtolong()
    // 'CustomerAdd' => '_quickbooks_error_customeradd',    // Whenever an error occurs while trying to perform an 'AddCustomer' action, call this function: _quickbooks_error_customeradd()
    // '*' => '_quickbooks_error_catchall',                 // Using a key value of '*' will catch any errors which were not caught by another error handler
    // ... more error handlers here ...
    );

// An array of callback hooks
$hooks = array(
    // There are many hooks defined which allow you to run your own functions/methods when certain events happen within the framework
    // QuickBooks_WebConnector_Handlers::HOOK_LOGINSUCCESS => '_quickbooks_hook_loginsuccess',  // Run this function whenever a successful login occurs
    );

$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(
    //'authenticate' => ' *** YOU DO NOT NEED TO PROVIDE THIS CONFIGURATION VARIABLE TO USE THE DEFAULT AUTHENTICATION METHOD FOR THE DRIVER YOU'RE USING (I.E.: MYSQL) *** '
    //'authenticate' => 'your_function_name_here', 
    //'authenticate' => array( 'YourClassName', 'YourStaticMethod' ),
    'deny_concurrent_logins' => false, 
    'deny_reallyfast_logins' => false, 
    );      // See the comments in the QuickBooks/Server/Handlers.php file

$driver_options = array(        // See the comments in the QuickBooks/Driver/<YOUR DRIVER HERE>.php file ( i.e. 'Mysql.php', etc. )
    //'max_log_history' => 1024,    // Limit the number of quickbooks_log entries to 1024
    //'max_queue_history' => 64,    // Limit the number of *successfully processed* quickbooks_queue entries to 64
    );

$callback_options = array(
    );

$dsn = 'mysqli://root:@localhost/qb';

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 = 5;

    $Queue = new QuickBooks_WebConnector_Queue($dsn);
    $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $primary_key_of_your_customer);

$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)
{ 
    $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>[email protected]</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)
{   
    // Great, customer $ID has been added to QuickBooks with a QuickBooks 
    //  ListID value of: $idents['ListID']
    // 
    // We probably want to store that ListID in our database, so we can use it 
    //  later. (You'll need to refer to the customer by either ListID or Name 
    //  in other requests, say, to update the customer or to add an invoice for 
    //  the customer. 

    /*
    mysql_query("UPDATE your_customer_table SET quickbooks_listid = '" . mysql_escape_string($idents['ListID']) . "' WHERE your_customer_ID_field = " . (int) $ID);
    */
}

function _quickbooks_salesreceipt_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">
                <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)
{   
    // Great, sales receipt $ID has been added to QuickBooks with a QuickBooks 
    //  TxnID value of: $idents['TxnID']
    //
    // The QuickBooks EditSequence is: $idents['EditSequence']
    // 
    // We probably want to store that TxnID in our database, so we can use it 
    //  later. You might also want to store the EditSequence. If you wanted to 
    //  issue a SalesReceiptMod to modify the sales receipt somewhere down the 
    //  road, you'd need to refer to the sales receipt using the TxnID and 
    //  EditSequence 
}

function _quickbooks_error_stringtoolong($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{
    mail('[email protected]', 
        'QuickBooks error occured!', 
        'QuickBooks thinks that ' . $action . ': ' . $ID . ' has a value which will not fit in a QuickBooks field...');
}

另外我只安装了QB POS服务器工作站

quickbooks
1个回答
0
投票

您收到此错误消息:

0x80045242: QBPOSXML: Unknown request version

因为您正在发送错误版本的请求。这些要求:

$xml = '<?xml version="1.0" encoding="utf-8"?>
    <?qbxml version="2.0"?>
    <QBXML>
        <QBXMLMsgsRq onError="stopOnError">
            <CustomerAddRq requestID="' . $requestID . '">
                <CustomerAdd>

适用于QuickBooks Pro / Premier / Enterprise。它们根本不是QuickBooks销售点请求。 QuickBooks销售点是与QuickBooks Pro / Premier / Enterprise不同的产品系列。

您正在使用的库:

有一个专门针对QuickBooks销售点的示例:

您可以看到请求的结构不同(并且具有不同的版本和XML标头):

// We're just testing, so we'll just use a static test request:
$xml = '
    <?xml version="1.0" encoding="utf-8"?>
    <?qbposxml version="3.0"?>
    <QBPOSXML>
        <QBPOSXMLMsgsRq onError="stopOnError">
            <CustomerAddRq>

您还可以在此处查看文档,其中显示了以下请求:

https://developer.intuit.com/app/developer/qbdesktop/docs/get-started/get-started-with-the-quickbooks-pos-sdk#download-and-install-the-quickbooks-pos-sdk

© www.soinside.com 2019 - 2024. All rights reserved.