doushan6161 2017-10-16 18:05
浏览 69

使用Consolibyte的PHP Devkit将客户添加到Quickbooks POS Desktop v.12 w / Web Connector

I'm out of my depth and am hoping a few coders will help with a noble cause.

I haven't done much programming outside of college classes and need some help with some basics. I've started a nonprofit technology service provider for other nonprofits. The integration described below is part of my first project which I've completely donated. If I were charging any fees, I'd pay for this help as it's certainly not my wheel house. I have many other items to attend to in this project and am hoping that somebody will help speed things along.

The integration that I'm working on is simple. The nonprofit sells donated goods and offers a ten percent discount to folks that sign up for their discount program. Currently, users are signing up via a google form and at a later date, the information is manually added to the Quickbooks v. 12 POS system. As the organization is using wordpress, php seemed like a goodfit. I'm totally open to other methods, the following is simply where my research landed.

I'm using the following

  1. Intuit Quickbooks POS v.12 http://dlm2.download.intuit.com/akdlm/SBD/QuickBooks/2015/Latest/QuickBooksPOSV12Trial30.exe

  2. Web Connector v. 2.1.0.30 developer.intuit.com/docs/0200_quickbooks_desktop/0100_essentials/quickbooks_web_connector

  3. Keith Palmer's / Consolibyte's PHP Dev Kit consolibyte.com/downloads/quickbooks-php-devkit/

I've been successful in using (it's a dev lamp stack): lamp.pond.im/qb/docs/web_connector/example_web_connector_point_of_sale.php to add a static customer record

I'm struggling with some basic next steps. If I'm understanding the documentation correctly: http://www.consolibyte.com/docs/index.php/PHP_DevKit_for_QuickBOoks_-_Point_of_Sale_Quick-Start

My next step is to queue a user provided by a form. My goal is to implement this for the organization using a wordpress plugin. That said, at this point I just need to get things functional. I believe the code below is what I need to queue up the new user, but I'm struggling with implementation. I think I need to create a form, but don't understand how to use the code below (docs/example_web_connector_queueing.php) with docs/example_web_connector_point_of_sale.php.

docs/example_web_connector_queueing.php

<?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';

if (isset($_POST['customer']))
{
// Oooh, here's a new customer, let's do some stuff with them

// Connect to your own MySQL server....
$link = mysql_connect('localhost', 'your_mysql_username', 
'your_mysql_password');
if (!$link) 
{
    die('Could not connect to MySQL: ' . mysql_error());
}

// ... and use the correct database
$selected = mysql_select_db('your_database_name', $link);
if (!$selected) 
{
    die ('Could not select database: ' . mysql_error());
}   

// Insert into our local MySQL database
mysql_query("INSERT INTO my_customer_table ( name, phone, email ) VALUES ( '" . $_POST['customer']['name'] . "', '" . $_POST['customer']['phone'] . "', '" . $_POST['customer']['email'] . "' ) ");
$id_value = mysql_insert_id();

// QuickBooks queueing class
$Queue = new QuickBooks_WebConnector_Queue('mysql://root:password@localhost/my_database');

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

}

Here's the example_web_connector_point_of_sale.php code

<?php

/**
 * Example QuickBooks SOAP Server / Web Service for QuickBooks Point of Sale
 * 
 * This is an example Web Service which adds test dummy customers to QuickBooks 
 * Point of Sale via the Web Connector. 
 * 
 * You should probably also look through docs/example_web_connector.php for 
 * some additional documentation about what things do.  
 * 
 * @author Keith Palmer <keith@consolibyte.com>
 * 
 * @package QuickBooks
 * @subpackage Documentation
 */

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

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

// Require the framework
require_once '../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_pos_customer_add_request', '_quickbooks_pos_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_NORMAL;
//$log_level = QUICKBOOKS_LOG_VERBOSE;
//$log_level = QUICKBOOKS_LOG_DEBUG;                
$log_level = QUICKBOOKS_LOG_DEVELOP;        // Use this level until you're sure everything works!!!

// What SOAP server you're using 
//$soapserver = QUICKBOOKS_SOAPSERVER_PHP;          // The PHP SOAP extension, see: www.php.net/soap
$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(
    'deny_concurrent_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. )
    );

$callback_options = array(
    );

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

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

    // We're going to queue up a request to add a customer, just as a test...
    $primary_key_of_your_customer = 5;

    $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, $soapserver, QUICKBOOKS_WSDL, $soap_options, $handler_options, $driver_options, $callback_options);
$response = $Server->handle(true, true);

/**
 * Generate a qbXML request for QuickBooks Point of Sale
 */
function _quickbooks_pos_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
    // 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>
                    <CustomerAdd>
                        <CompanyName>ConsoliBYTE, LLC</CompanyName>
                        <EMail>support@ConsoliBYTE.com</EMail>
                        <FirstName>Keith</FirstName>
                        <LastName>Palmer Jr.</LastName>
                        <Phone>860-341-1464</Phone>
                        <Salutation>Mr.</Salutation>
                        <BillAddress>
                            <City>Willington</City>
                            <Country>USA</Country>
                            <PostalCode>06279</PostalCode>
                            <State>CT</State>
                            <Street>56 Cowles Road</Street>
                        </BillAddress>
                        <ShipAddress>
                            <City>Willington</City>
                            <Country>USA</Country>
                            <PostalCode>06279</PostalCode>
                            <State>CT</State>
                            <Street>56 Cowles Road</Street>
                        </ShipAddress>
                    </CustomerAdd>
                </CustomerAddRq>
            </QBPOSXMLMsgsRq>
        </QBPOSXML>';

    return $xml;
}

/**
 * Receive a response from QuickBooks 
 */
function _quickbooks_pos_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);
    */
}
  • 写回答

1条回答 默认 最新

  • dongniaocheng3773 2017-10-17 13:15
    关注

    First, create a WordPress form and store whatever is input in the database. Lots of tutorials online about how to do that. Here's one:

    You should get back some sort of Id value for the record you inserted. Use that to queue up the record immediately after saving it to the database:

    require_once 'path/to/QuickBooks.php';
    
    // QuickBooks queueing class
    $Queue = new QuickBooks_WebConnector_Queue('mysql://root:password@localhost/my_database');
    
    // Queue it up!
    $Queue->enqueue(QUICKBOOKS_ADD_CUSTOMER, $id_value);
    

    Separately, in a totally separate script, modify your function to add a customer to QuickBooks POS:

    function _quickbooks_pos_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
    {
        // Pull the data out of the database that we stored from the WordPress form submission
        $arr = mysql_fetch_array(mysql_query("SELECT * FROM your_table WHERE id = " . (int) $ID));
    
        // Build $xml using the data in $arr
        $xml = '
    

    As other users have pointed out, this code is old so take some time to clean it up and make sure it's secure. Among the things you'll want to look at:

    • Use PDO or mysqli or another database later instead of the mysql_* functions (they are deprecated)
    • Prepared statements or parameterized statements are good idea for database queries
    评论

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答