如何使用consolibytes quickbooks-php和quickbooks web连接器防止在quickbooks中无限创建条目

时间:2016-09-21 14:01:17

标签: php soap quickbooks

我已按照the tutorial设置quickbooks-php,以便在基于桌面的安装上使用quickbooks Web连接器。

我遇到的问题是,无论何时我的网络服务运行,它都会无限制地将多个条目添加到quickbooks中,而我只想添加一个条目。

以下是我用来从我的网络服务添加条目的代码。任何帮助深表感谢。

<?php

    /**
     * Example integration with an application
     * 
     * The idea behind the action queue is basically just that you want to add an 
     * action/ID pair to the queue whenever something happens in your application 
     * that you need to tell QuickBooks about. 
     * 
     * @author Keith Palmer <keith@consolibyte.com>
     * 
     * @package QuickBooks
     * @subpackage Documentation
     */

    // Error reporting for easier debugging
    ini_set('display_errors', true);
    error_reporting(E_ALL | E_STRICT);

    // Require the queueuing class
    require_once '../../QuickBooks.php';



    $user = 'r2g';
    $pass = '******';
    $map = array(
        QUICKBOOKS_ADD_CUSTOMER => array( '_quickbooks_customer_add_request', '_quickbooks_customer_add_response' )
    );
    $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 ...
    );
    $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;
    $soap_options = array();
    $handler_options = array(
        'deny_concurrent_logins' => false, 
        'deny_reallyfast_logins' => false, 
    );

    $driver_options = array();
    $callback_options = array();

    $dsn = 'mysqli://root:******@localhost/quick_books_integration';

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


    if (!QuickBooks_Utilities::initialized($dsn))
        {
            QuickBooks_Utilities::initialize($dsn);
            QuickBooks_Utilities::createUser($dsn, $user, $pass);

            // QuickBooks queueing class
            $Queue = new QuickBooks_WebConnector_Queue($dsn);

            // Queue it up!
            $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER,6);
    }    



    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>Unifreight CFS Mombasa (' . mt_rand() . ')</Name>
                                <CompanyName>Unifreight</CompanyName>
                                <FirstName>Michael </FirstName>
                                <LastName>Makari</LastName>
                                <BillAddress>
                                    <Addr1>Unifreight CFS</Addr1>
                                    <Addr2>Makupa Causeway</Addr2>
                                    <City>Mombasa</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>r2g.technology@gmail.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
    ){

        return; 
    }

?>

0 个答案:

没有答案