QuickBooks API(php)集成

QuickBooks API(php)集成,php,quickbooks,Php,Quickbooks,我是QuickBooks的新手。我已经在Quick Books中创建了一个试用帐户,我想在我的帐户中添加客户、创建发票或类似的内容。我已经从github下载了php SDK。现在我不知道如何开始,从哪里开始添加客户到我的帐户后,客户从我的网站订购。有谁能帮我提供一些详细的文档或示例,以便我继续前进。我对web应用程序连接器一无所知。我是全新的。感谢..在SDK中,使用示例_ipp_ids_6.php添加客户 以下是GitHub上完整代码的链接: 以及快速入门指南: 示例_ipp_i

我是QuickBooks的新手。我已经在Quick Books中创建了一个试用帐户,我想在我的帐户中添加客户、创建发票或类似的内容。我已经从github下载了php SDK。现在我不知道如何开始,从哪里开始添加客户到我的帐户后,客户从我的网站订购。有谁能帮我提供一些详细的文档或示例,以便我继续前进。我对web应用程序连接器一无所知。我是全新的。感谢..

在SDK中,使用示例_ipp_ids_6.php添加客户

以下是GitHub上完整代码的链接:

以及快速入门指南:

示例_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() . ']' . "\n\n");

    $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 . ']' . "\n\n");

    print("\n\n\n\n");
    print('Request [' . $IPP->lastRequest() . ']');
    print("\n\n\n\n");
    print('Response [' . $IPP->lastResponse() . ']');
    print("\n\n\n\n");
}
else
{
    die('Unable to load a context...?');
}

这将是一个由两部分组成的答案,因为您没有指定是使用QuickBooks ONLINE还是QuickBooks for WINDOWS

根据您使用的是哪一种,流程会有所不同,因此请注意以下粗体标题:

对于QuickBooks ONLINE:

如果您使用的是来自GitHub的,那么最好从指南开始

你要做的第一件事就是向Intuit注册你的应用程序。执行此操作时,Intuit将为您提供以下变量:

  • 应用令牌
  • 消费者秘密
  • 用户密钥
您将把这些变量替换到示例中包含的文件中。您还将更新这些值以指向您的应用程序:

  • oauth url(例如,your site.com/path/to/example/oauth.php)
  • 成功url(例如:your site.com/path/to/example/success.php)
  • 菜单url(例如,your site.com/path/to/example/menu.php)
  • dsn(用于OAuth令牌存储的数据库凭据)
除此之外,您还可以将config.php中的所有其他变量保留为默认值

如果随后访问index.php文件,它将提示您连接到QuickBooks。您可以连接,然后访问示例文件。以下是向QuickBooks Online添加客户/订单的一些示例:

代码最终看起来像:

    $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 . ']');
    }
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;
}
为了实现附加功能,您将在代码中找到其他示例

可用的对象/方法也会镜像,因此您需要查看它

适用于WINDOWS的QuickBooks:

对于QuickBooks For Windows,您将使用Web连接器。同样,从GitHub开始。改用指南

这将引导您完成一个简单的Web连接器服务的设置,该服务将测试客户添加到QuickBooks中

基本上,您将看到将加载到QuickBooks Web连接器中的内容(开始>所有程序>QuickBooks>Web连接器)。该.QWC文件将指向一个。在该示例脚本中,您只需交换此变量:

  • $dsn(将其指向您自己的数据库)
对于要添加的每一项新功能,您都将编写一个新的请求和响应函数,如中所述

您的代码最终将看起来像:

    $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 . ']');
    }
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;
}
function\u quickbook\u customer\u add\u请求($requestID、$user、$action、$ID、$extra、$err、$last\u action\u time、$last\u actionident\u time、$version、$locale)
{
//您可能需要在这里进行一些数据库访问,以便使用
//ID=$ID,并生成一个请求来添加特定的
//客户到QuickBooks。
//        
//因此,当您为您的业务实施此功能时,您可能会这样做
//像这样的东西…:
/*
//从数据库中获取客户记录
$record=mysql_fetch_数组(mysql_查询(“从您的_customer_表中选择*,其中您的_customer_ID_字段=”(int)$ID));
//创建并返回qbXML请求
$qbxml='0
“.$record[“您的客户名称”字段]。”
“.$record[“您的客户\公司\字段]。”
…许多其他与客户相关的领域。。。
';
返回$qbxml;
*/
//但我们只是在测试,所以我们将只使用静态测试请求:
$xml='0
ConsoliBYTE有限责任公司(“.mt_rand()”)
康赛比特有限责任公司
基思
帕默


我们还提供了一个您可以使用的wiki。

可能是您能告诉我从哪里可以获得令牌、消费者密钥、消费者秘密加密密钥和租户的副本。当您在Intuit注册时,他们会给您所有这些信息。$tenant您可以保留默认值。Hi@KeithPalmerJr、 该网站已无法访问。这是一个非常有用的项目,经过很长一段时间后才出现。我们有没有办法访问整个文档?我正在使用Quickbooks online感谢您的帮助…我已经尝试过了,现在单击“连接”按钮时出现以下错误第34行quickbooks php master/quickbooks/Encryption/Aes.php上的“调用未定义函数mcrypt_module_open()”。由于Intuit需要安全标准,您需要安装php mcrypt模块