2017-10-16 52 views
1

我不知道我的深度,希望一些编码人员能够帮助一个崇高的事业。使用Consolibyte的PHP Devkit将客户添加到Quickbooks POS Desktop v.12 w/Web连接器

我在大学课程之外没有做过多的编程,需要一些基础知识的帮助。我为其他非营利组织开办了一家非营利性技术服务提供商。下面介绍的整合是我完全捐赠的第一个项目的一部分。如果我收取任何费用,我会支付这个帮助,因为它当然不是我的轮子之家。我在这个项目中还有许多其他项目需要参与,我希望有人能够帮助加快速度。

我正在进行的整合很简单。该非营利组织出售捐赠物品,并为注册其折扣计划的人提供10%的折扣。目前,用户正在通过Google表单注册,并在稍后的日期将信息手动添加到Quickbooks v。12 POS系统。由于该组织正在使用wordpress,php看起来不错。我完全接受其他方法,以下仅仅是我的研究成果。

我使用以下

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

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

  3. 基思·帕尔默/ Consolibyte的PHP开发套件 consolibyte.com/downloads/quickbooks-php-devkit/

我已经成功地使用(这是一个开发的LAMP堆栈):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_point_of_sale.php下面的代码(docs/example_web_connector_queueing.php)。

文档/ 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 <[email protected]> 
* 
* @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:[email protected]/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 <[email protected]> 
* 
* @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:[email protected]/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>[email protected]</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); 
    */ 
} 
+0

不要使用此示例代码,它写得很差,过时并且不安全。 –

+0

如果您提供了替代解决方案并解释了您的意见,那将会更有帮助。 –

+0

不要使用'mysql_ *'函数。自v5.5(2013年6月)开始,它们已被弃用,并从v7.0(2015年12月)开始删除。请使用[** mysqli _ ***](https://secure.php.net/manual/en/book.mysqli.php)或[** PDO **](https://secure.php.net /manual/en/book.pdo.php)与[**准备语句**](https://secure.php.net/manual/en/pdo.prepare.php)和[**绑定参数** ](https://secure.php.net/manual/en/pdostatement.bindparam.php)。 –

回答

0

首先,创建一个WordPress的形式和存储无论是在数据库输入。网上有很多关于如何做到这一点的教程。这里有一个:

应该会得到某种你插入的记录Id价值。用它来排队的记录保存到数据库后立即:

require_once 'path/to/QuickBooks.php'; 

// QuickBooks queueing class 
$Queue = new QuickBooks_WebConnector_Queue('mysql://root:[email protected]/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_*功能后,而不是(他们不建议使用)
  • 预处理语句或参数语句是好主意,数据库查询
+0

感谢这一点,当发现礼券证书漏洞时,它很快就不再成为问题。我很感谢你为此所做的任何指导。我创建了一个单独的问题 –

相关问题