Search code examples
quickbooks

QuickBooks PHP SDK ENUMTYPE in the Customer Add Request


Everything works fine if optional element PreferredDeliveryMethod is omitted that's an ENUMTYPE. If PreferredDeliveryMethod is included in the XML, it gives the following message-

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

The code is as below. This is running good except for PreferredDeliveryMethod. I need to know how to include ENUMTYPE in the Add Request.

/**
 * Example QuickBooks Web Connector web service with custom authentication
 * 
 * This example shows how to use a custom authentication function to 
 * 
 * @author Keith Palmer <[email protected]>
 * 
 * @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>[email protected]</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; 
}

Solution

  • If you refer to the documentation:

    The PreferredDeliveryMethod tag requires at least qbXML version 12.0 or higher.

    You are using version:

    • <?qbxml version="2.0"?>

    Either don't use the tag, or use a version that supports the tag.