我是QuickBooks的新手。我在Quick Books中创建了一个试用帐户,我想向我的帐户添加客户、创建发票或类似的东西。我已经从github下载了php SDK。现在我不知道如何开始,在客户从我的网站上下单后,从哪里开始将客户添加到我的账户中。有人能帮我提供一些详细的文档或例子吗?这样我就可以继续前进了。我对web应用程序连接器一无所知。我是一个全新的人。谢谢
这将是一个由两部分组成的答案,因为您没有指定是在使用QuickBooks ONLINE还是在使用QuickBooks for WINDOWS。
根据您使用的不同,流程会有所不同,因此请注意下面的粗体标题:
对于QuickBooks在线:
如果你使用的是GitHub的开源QuickBooks PHP DevKit,那么最好的起点是QuickBooks Online with PHP快速入门指南。
- http://www.consolibyte.com/docs/index.php/PHP_DevKit_for_QuickBooks_-_Intuit_Partner_Platform_Quick-Start
你要做的第一件事就是向Intuit注册你的应用程序。当你这样做时,Intuit会给你这些变量:
- 应用程序令牌
- 消费者秘密
- 使用者密钥
您将把这些变量替换到示例中包含的config.php文件中。您还将更新这些值以指向您的应用程序:
- oauth url(例如您的站点.com/path/to/example/oauth.php)
- 成功url(例如您的站点.com/path/to/example/success.php)
- 菜单url(例如,您的站点.com/path/to/example/manue.php)
- dsn(OAuth令牌存储的数据库凭据)
除此之外,可以将config.php中的所有其他变量保留为默认值。
如果您随后访问index.php文件,它将提示您连接到QuickBooks。您可以连接,然后访问示例文件。以下是一些将客户/订单添加到QuickBooks Online的示例:
- QuickBooks Online-使用PHP添加客户
- QuickBooks Online-使用PHP添加发票
代码最终看起来像:
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setTitle('Mr');
$Customer->setGivenName('Keith');
$Customer->setMiddleName('R');
$Customer->setFamilyName('Palmer');
$Customer->setDisplayName('Keith R Palmer Jr ' . mt_rand(0, 1000));
// Phone #
$PrimaryPhone = new QuickBooks_IPP_Object_PrimaryPhone();
$PrimaryPhone->setFreeFormNumber('860-532-0089');
$Customer->setPrimaryPhone($PrimaryPhone);
// Bill address
$BillAddr = new QuickBooks_IPP_Object_BillAddr();
$BillAddr->setLine1('72 E Blue Grass Road');
$BillAddr->setLine2('Suite D');
$BillAddr->setCity('Mt Pleasant');
$BillAddr->setCountrySubDivisionCode('MI');
$BillAddr->setPostalCode('48858');
$Customer->setBillAddr($BillAddr);
if ($resp = $CustomerService->add($Context, $realm, $Customer))
{
print('Our new customer ID is: [' . $resp . ']');
}
要实现其他功能,您将在代码中找到其他示例。
可用的对象/方法也反映了Intuit的文档,因此您需要查看该文档。
对于适用于WINDOWS的QuickBooks:
对于适用于Windows的QuickBooks,您将使用Web连接器。再次,从GitHub的开源QuickBooks PHP DevKit开始。请使用QuickBooks for Windows+PHP快速入门指南。
这将引导您完成一个简单的Web连接器服务的设置,该服务将测试客户添加到QuickBooks中。
基本上,您将创建一个.QWC文件,并将其加载到QuickBooks Web连接器中(开始>所有程序>QuickBooks>Web连接器)。QWC文件将指向一个PHP脚本,该脚本协商QuickBooks和PHP之间的连接。在这个示例脚本中,您所要做的就是交换这个变量:
- $dsn(将其指向您自己的数据库)
对于您想要添加的每一个新功能,您最终都会编写一个新的请求和响应函数,如QuickBooksWebConnector+PHP文档中所述。
你的代码最终会看起来像:
function _quickbooks_customer_add_request($requestID, $user, $action, $ID, $extra, &$err, $last_action_time, $last_actionident_time, $version, $locale)
{
// You'd probably do some database access here to pull the record with
// ID = $ID from your database and build a request to add that particular
// customer to QuickBooks.
//
// So, when you implement this for your business, you'd probably do
// something like this...:
/*
// Fetch your customer record from your database
$record = mysql_fetch_array(mysql_query("SELECT * FROM your_customer_table WHERE your_customer_ID_field = " . (int) $ID));
// Create and return a qbXML request
$qbxml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>' . $record['your_customer_name_field'] . '</Name>
<CompanyName>' . $record['your_customer_company_field'] . '</CompanyName>
... lots of other customer related fields ...
</CustomerAdd>
</CustomerAddRq>
</QBXMLMsgsRq>
</QBXML>';
return $qbxml;
*/
// But we're just testing, so we'll just use a static test request:
$xml = '<?xml version="1.0" encoding="utf-8"?>
<?qbxml version="2.0"?>
<QBXML>
<QBXMLMsgsRq onError="stopOnError">
<CustomerAddRq requestID="' . $requestID . '">
<CustomerAdd>
<Name>ConsoliBYTE, LLC (' . mt_rand() . ')</Name>
<CompanyName>ConsoliBYTE, LLC</CompanyName>
<FirstName>Keith</FirstName>
<LastName>Palmer</LastName>
<BillAddress>
<Addr1>ConsoliBYTE, LLC</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;
}
您可以使用QuickBooks OSR找到其他qbXML引用。
我们还提供了一个wiki,其中包含许多您可以使用的示例qbXML请求。
从SDK中,使用example_ipp_ids_6.php添加客户。
以下是GitHub:上完整代码的链接
- GitHub-开源QuickBooks PHP DevKit
快速入门指南:
-
QuickBooks在线快速启动PHP
-
QuickBooks for WINDOWS使用PHP 快速启动
example_ipp_ids_6.php
<?php
// Turn on some error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
header('Content-Type: text/plain');
/**
* Require the QuickBooks library
*/
require_once dirname(__FILE__) . '/../QuickBooks.php';
/**
* Require some IPP/OAuth configuration data
*/
require_once dirname(__FILE__) . '/example_ipp_config.php';
// Set up the IPP instance
$IPP = new QuickBooks_IPP($dsn);
// Set up our IntuitAnywhere instance
$IntuitAnywhere = new QuickBooks_IPP_IntuitAnywhere($dsn, $encryption_key, $oauth_consumer_key, $oauth_consumer_secret);
// Get our OAuth credentials from the database
$creds = $IntuitAnywhere->load($the_username, $the_tenant);
// Tell the framework to load some data from the OAuth store
$IPP->authMode(
QuickBooks_IPP::AUTHMODE_OAUTH,
$the_username,
$creds);
// Print the credentials we're using
//print_r($creds);
// This is our current realm
$realm = $creds['qb_realm'];
// Load the OAuth information from the database
if ($Context = $IPP->context())
{
// Set the DBID
$IPP->dbid($Context, 'something');
// Set the IPP flavor
$IPP->flavor($creds['qb_flavor']);
// Get the base URL if it's QBO
if ($creds['qb_flavor'] == QuickBooks_IPP_IDS::FLAVOR_ONLINE)
{
$IPP->baseURL($IPP->getBaseURL($Context, $realm));
}
print('Base URL is [' . $IPP->baseURL() . ']' . "nn");
$CustomerService = new QuickBooks_IPP_Service_Customer();
$Customer = new QuickBooks_IPP_Object_Customer();
$Customer->setName('Willy Wonka #' . mt_rand(0, 1000));
$Customer->setGivenName('Willy');
$Customer->setFamilyName('Wonka');
$resp = $CustomerService->add($Context, $realm, $Customer);
print_r($Customer);
print('New customer is [' . $resp . ']' . "nn");
print("nnnn");
print('Request [' . $IPP->lastRequest() . ']');
print("nnnn");
print('Response [' . $IPP->lastResponse() . ']');
print("nnnn");
}
else
{
die('Unable to load a context...?');
}
在example_ipp_config.php 中配置您的密钥和用户名
<?php
/**
* Intuit Partner Platform configuration variables
*
* See the scripts that use these variables for more details.
*
* @package QuickBooks
* @subpackage Documentation
*/
// Your OAuth token (Intuit will give you this when you register an Intuit Anywhere app)
$token = 'c640731cb411db4132b8475b4198a7efae08';
// Your OAuth consumer key and secret (Intuit will give you both of these when you register an Intuit app)
//
// IMPORTANT:
// To pass your tech review with Intuit, you'll have to AES encrypt these and
// store them somewhere safe.
//
// The OAuth request/access tokens will be encrypted and stored for you by the
// PHP DevKit IntuitAnywhere classes automatically.
$oauth_consumer_key = 'qyprdzUiOLX60UK4cMwYhg1QVGfOGT';
$oauth_consumer_secret = '32mIB75pqqPreOADcxRvryC0fBduJhnRr52JfUdf';
// This is the URL of your OAuth auth handler page
$this_url = 'http://localhost/quick/docs/example_ipp_oauth.php';
// This is the URL to forward the user to after they have connected to IPP/IDS via OAuth
$that_url = 'http://localhost/quick/docs/example_ipp_ids_6.php';
// This is a database connection string that will be used to store the OAuth credentials
// $dsn = 'pgsql://username:password@hostname/database';
// $dsn = 'mysql://username:password@hostname/database';
$dsn = 'mysql://root:@localhost/quickbooks';
// You should set this to an encryption key specific to your app
$encryption_key = 'abcd1234';
// The user that's logged in
$the_username = 'test@gmail.com';
// The tenant that user is accessing within your own app
$the_tenant = 12345;
// Initialize the database tables for storing OAuth information
if (!QuickBooks_Utilities::initialized($dsn))
{
// Initialize creates the neccessary database schema for queueing up requests and logging
QuickBooks_Utilities::initialize($dsn);
}