QuickBooks客户添加请求中的PHP SDK ENUMTYPE

时间:2015-12-05 17:47:28

标签: quickbooks

如果省略了ENUMTYPE的可选元素PreferredDeliveryMethod,那么一切正常。如果PreferredDeliveryMethod包含在XML中,则会提供以下消息 -

Message:
0x80040400: QuickBooks found an error when parsing the provided XML text stream.

代码如下。除了PreferredDeliveryMethod之外,这种方式运行良好。我需要知道如何在添加请求中包含ENUMTYPE。

/**
 * Example QuickBooks Web Connector web service with custom authentication
 * 
 * This example shows how to use a custom authentication function to 
 * 
 * @author Keith Palmer <keith@consolibyte.com>
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */

// I always program in E_STRICT error mode... 
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', true);

// We need to make sure the correct timezone is set, or some PHP installations will complain
if (function_exists('date_default_timezone_set'))
{
    // 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';
//require_once '/Users/kpalmer/Projects/QuickBooks/QuickBooks.php';
require_once 'C:\wamp\www\quickbooks\QuickBooks.php';
// A username and password you'll use in: 
//  a) Your .QWC file
//  b) The Web Connector
//  c) The QuickBooks framework
$user = 'quickbooks';
$pass = 'password';

// Map QuickBooks actions to handler functions
$map = array(
    QUICKBOOKS_ADD_CUSTOMER => 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();

// An array of callback hooks
$hooks = array();

// Logging level
$log_level = QUICKBOOKS_LOG_DEVELOP;        // Use this level until you're sure everything works!!!

// SOAP backend
$soap = QUICKBOOKS_SOAPSERVER_BUILTIN;

// SOAP options
$soap_options = array();

// * MAKE SURE YOU CHANGE THE DATABASE CONNECTION STRING BELOW TO A VALID MYSQL USERNAME/PASSWORD/HOSTNAME *
$dsn = 'mysqli://root@localhost/qb_database';

// Handler options
$handler_options = array(
    'authenticate' => '_quickbooks_custom_auth', 
    //'authenticate' => '_QuickBooksClass::theStaticMethod',
    'deny_concurrent_logins' => false, 
    );

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);

    // Queueing up a test request
    $primary_key_of_your_customer = 2;
    $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, $soap, QUICKBOOKS_WSDL, $soap_options, $handler_options);
$response = $Server->handle(true, true);

/**
 * Authenticate a Web Connector session
 */
function _quickbooks_custom_auth($username, $password, &$qb_company_file)
{
    global $user, $pass;
    if ($username == $user and $password == $pass)
    {
        // Use this company file and auth successfully
        //$qb_company_file = 'C:\path\to\the\file-function.QBW';

        return true;
    }

    // Login failure
    return false;
}

/**
 * Generate a qbXML response to add a particular customer to QuickBooks
 */
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="1">
          <CustomerAdd>
            <Name>RHP, Kristy</Name>
            <Salutation>Mrs.</Salutation>
            <FirstName>Kristy</FirstName>
            <LastName>Abercrombie</LastName>
            <BillAddress>
              <Addr1>Kristy Abercrombie</Addr1>
              <Addr2>5647 Cypress Hill Rd</Addr2>
              <City>Bayshore</City>
              <State>CA</State>
              <PostalCode>94326</PostalCode>
            </BillAddress>
             <ShipAddress>
              <Addr1>Kristy Abercrombie</Addr1>
              <Addr2>5647 Cypress Hill Rd</Addr2>
              <City>Bayshore</City>
              <State>CA</State>
              <PostalCode>94326</PostalCode>
            </ShipAddress>
            <Phone>415-555-6579</Phone>
            <Email>kristy@samplename.com</Email>
            <Contact>Kristy Abercrombie</Contact>
            <AltContact>Steve Darcangelo</AltContact>
            <PreferredDeliveryMethod>Email</PreferredDeliveryMethod>
           </CustomerAdd>
        </CustomerAddRq>
      </QBXMLMsgsRq>
    </QBXML>';
return $xml;
}

/**
 * Receive a response from QuickBooks 
 */
function _quickbooks_customer_add_response($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{
    return; 
}

1 个答案:

答案 0 :(得分:1)

如果您参考文档:

PreferredDeliveryMethod标记至少需要qbXML 12.0或更高版本。

您使用的是版本:

  • <?qbxml version="2.0"?>

要么不使用标记,要么使用支持标记的版本。