【问题标题】:Using Consolibyte's PHP Devkit to Add a Customer to Quickbooks POS Desktop v.12 w/ Web Connector使用 Consolibyte 的 PHP Devkit 将客户添加到带有 Web 连接器的 Quickbooks POS Desktop v.12
【发布时间】:2018-03-28 08:07:51
【问题描述】:

我已经超出了我的能力范围,我希望一些程序员能帮助完成一项崇高的事业。

我在大学课程之外没有做过太多编程,需要一些基础知识方面的帮助。我已经为其他非营利组织创办了一家非营利技术服务提供商。下面描述的集成是我完全捐赠的第一个项目的一部分。如果我收取任何费用,我会为这种帮助付费,因为它肯定不是我的驾驶室。在这个项目中,我还有许多其他项目要处理,我希望有人能帮助加快进度。

我正在进行的集成很简单。该非营利组织出售捐赠的商品,并为注册折扣计划的人提供 10% 的折扣。目前,用户通过谷歌表单进行注册,稍后,信息会手动添加到 Quickbooks v. 12 POS 系统中。由于该组织正在使用 wordpress,php 似乎很合适。我对其他方法完全开放,以下只是我研究的地方。

我正在使用以下

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

  2. Web 连接器 v. 2.1.0.30 developer.intuit.com/docs/0200_quickbooks_desktop/0100_essentials/quickbooks_web_connector

  3. Keith Palmer / Consolibyte 的 PHP 开发工具包 consolibyte.com/downloads/quickbooks-php-devkit/

我已经成功使用(它是一个开发灯堆栈):lamp.pond.im/qb/docs/web_connector/example_web_connector_point_of_sale.php 添加静态客户记录

我正在努力完成一些基本的后续步骤。如果我正确理解文档: http://www.consolibyte.com/docs/index.php/PHP_DevKit_for_QuickBOoks_-_Point_of_Sale_Quick-Start

我的下一步是对表单提供的用户进行排队。我的目标是使用 wordpress 插件为组织实现这一点。也就是说,在这一点上,我只需要让事情发挥作用。我相信下面的代码是我需要为新用户排队的代码,但我正在努力实现。我想我需要创建一个表单,但不明白如何将下面的代码 (docs/example_web_connector_queueing.php) 与 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);

}

这是 example_web_connector_point_of_sale.php 代码

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

【问题讨论】:

  • 不要使用这个示例代码,它写得不好、过时而且不安全。
  • 如果您提供替代解决方案并解释您的意见会更有帮助。
  • 不要使用mysql_* 函数。它们自 v5.5(2013 年 6 月)起已被弃用,自 v7.0(2015 年 12 月)起已被删除。而是将mysqli_*PDO 函数与prepared statementsbound parameters 一起使用。
  • 该代码易受SQL injection 攻击。您应该通过mysqliPDO 驱动程序使用带有绑定参数的预处理语句。 This post 有一些很好的例子。
  • 感谢您的澄清。一旦我能够使用 php 和 mysql 制作一个将用户添加到 qbposv12 的表单的原型,我会回过头来确保我收紧了。感谢您让我保持警惕!

标签: php wordpress forms lamp quickbooks


【解决方案1】:

首先,创建一个 WordPress 表单并将输入的内容存储在数据库中。网上有很多关于如何做到这一点的教程。这是一个:

您应该为您插入的记录取回某种Id 值。在将记录保存到数据库后立即使用它来排队:

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

另外,在一个完全独立的脚本中,修改您的函数以将客户添加到 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 = '

正如其他用户所指出的,此代码,因此需要一些时间来清理它并确保它是安全的。您需要查看的内容包括:

  • 稍后使用PDOmysqli 或其他数据库代替mysql_* 函数(它们已被弃用)
  • 准备好的语句或参数化语句是数据库查询的好主意

【讨论】:

  • 感谢这一点,当发现礼券漏洞时,它很快就不再是问题了。我将不胜感激您为此提供的任何指导。我创建了一个单独的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多