vendredi 1 février 2019

QuickBooks desktop and Laravel- content type xml; charset=UTF-8 but expected text/xml

I'm trying to get one of the examples for consolibyte quickbooks-php working in Laravel (5.1). I'm having trouble getting it to work using a controller. The Web Connector's log shows client found response content type of 'xml; charset=UTF-8', but expected 'text/xml'.

The code I'm using is a slightly modified version of quickbooks-php demo. I've been unable to find an example of quickbooks-php desktop and laravel and am unsure of what I'm doing wrong.

Note- The require_once('../QuickBooks.php') is in app/config/app.php.

Controller

public function sync(RequestInterface $request, InvoiceSyncService $obj){
    $this->logger->info('############################### Start QB sync (laravel) ######################################');

    $user = 'user';
    $pass = 'password';

    // Map QuickBooks actions to handler functions
    $map = array(
        QUICKBOOKS_ADD_CUSTOMER => array( array( $obj, 'addCustomerRequest' ), array( $obj, 'addCustomerResponse' ) ),
    );

    // This is entirely optional, use it to trigger actions when an error is returned by QuickBooks
    $errmap = array(
        500 => array( $obj, 'handleError500' ),
    );

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

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

    // What SOAP server you're using
    $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(
    );      // See the comments in the QuickBooks/Server/Handlers.php file

    $driver_options = array(
    );

    $callback_options = array(
    );

    $dsn = 'mysqli://username:password@localhost/database';

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

    // Set the DSN string because some of our callbacks will use it
    $obj->setDSN($dsn);

    // Create a new server and tell it to handle the requests
    $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);

    return response()->view('invoicing/sync', ['response' => $response])->header('Content-type', 'xml');
}

InvoiceSyncService

protected $_dsn;

private $logger;

public function __construct(LoggerFactory $loggerFactory)
{
    $this->logger = $loggerFactory->createLogger('invoice-sync');
}


public function setDSN($dsn)
{
    $this->_dsn = $dsn;
}

public function addCustomerRequest($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    $this->logger->info('A request occurred');

    $xml = '<?xml version="1.0" encoding="utf-8"?>
        <?qbxml version="2.0"?>
        <QBXML>
            <QBXMLMsgsRq onError="stopOnError">
                <CustomerAddRq>
                    <CustomerAdd>
                        <Name>ConsoliBYTE Solutions (' . mt_rand() . ')</Name>
                        <CompanyName>ConsoliBYTE Solutions</CompanyName>
                        <FirstName>Keith</FirstName>
                        <LastName>Palmer</LastName>
                        <BillAddress>
                            <Addr1>ConsoliBYTE Solutions</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>Keith@ConsoliBYTE.com</Email>
                        <Contact>Keith Palmer</Contact>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBXMLMsgsRq>
        </QBXML>';

    return $xml;
}


public function addCustomerResponse($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $xml, $idents)
{

    $this->logger->info('A response occured');
}

public function handleError500($requestID, $user, $action, $ID, $extra, &$err, $xml, $errnum, $errmsg)
{


    // return true;         // If you return TRUE, it will continue to process requests
    return false;           // If you return FALSE, it will stop processing requests
}

public function hookLoginSuccess($requestID, $user, $hook, &$err, $hook_data, $callback_config)
{
    if ($this->_dsn)
    {
        return true;
    }

    return false;
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire