本文介绍了QuickBooks API(php)集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是QuickBooks的新手.我已经在快速图书"中创建了一个试用帐户,并且想要向我的帐户添加客户,创建发票或类似的东西.我已经从github下载了php SDK.现在我不知道如何开始,在客户从我的网站下订单后,从哪里开始将客户添加到我的帐户.谁能帮我提供一些详细的文档或示例,以便我继续前进.我对Web应用程序连接器一无所知.我是全新的.谢谢.

I am a very new to QuickBooks. I have created a trial account in Quick Books and I want to add customers, create invoices or similar sort of things to my account. I have downloaded the php SDK from github. Now I have no Idea how to start, from where to start to add the customer to my account after the customer make the order from my website. Can anyone help me with some detail documentation or some examples so that I can move forward. I have no knowledge about the web app connector. I am totally new. Thanks..

推荐答案

这将分为两部分,因为您没有指定是使用QuickBooks ONLINE还是Windows的QuickBooks.

This is going to be a two-part answer, because you didn't specify if you're using QuickBooks ONLINE, or QuickBooks for WINDOWS.

根据您使用的进程,该过程将有所不同,因此请注意下面的粗体标题:

The process will be DIFFERENT depending on which you're using, so pay attention to the bold headers below:

对于在线QuickBooks:

如果您使用的是GitHub上的开源QuickBooks PHP DevKit ,那么最好的起点是使用PHP快速入门在线快速入门指南.

If you're using the open source QuickBooks PHP DevKit from GitHub, then the best place to start is the QuickBooks Online with PHP quick-start guide.

您要做的第一件事就是在Intuit中注册您的应用程序.执行此操作时,Intuit将给您这些变量:

The very first thing you'll have to do is register your app with Intuit. When you do this, Intuit will give you these variables:

  • 应用令牌
  • 消费者的秘密
  • 消费者密钥

您将把这些变量代入 config.php 示例中包含的文件.您还将更新这些值以指向您的应用程序:

You will substitute these variables into the config.php file that is included in the example. You'll also update these values to point to your app:

  • oauth网址(例如your-site.com/path/to/example/oauth.php)
  • 成功网址(例如your-site.com/path/to/example/success.php)
  • 菜单网址(例如your-site.com/path/to/example/menu.php)
  • dsn(用于OAuth令牌存储的数据库凭据)

除此之外,您可以将config.php中的所有其他变量保留为默认值.

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

If you then visit the index.php file, it will prompt you to connect to QuickBooks. You can connect, and then visit the example files. Here are some examples of adding customers/orders to QuickBooks Online:

  • QuickBooks Online - add customer with PHP
  • QuickBooks Online - add invoice with 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 . ']');
    }

要实现其他功能,您将找到代码中包含的其他示例.

To implement additional functionality, you'll find other examples included in the code.

可用的对象/方法也反映了 Intuit的文档,因此您需要查看一下.

The objects/methods available also mirror Intuit's documentation so you'll want to look at that.

对于适用于WINDOWS的QuickBooks:

对于Windows的QuickBooks,您将使用Web连接器.同样,从GitHub的开源QuickBooks PHP DevKit 开始.请改用适用于Windows的QuickBooks + PHP快速入门指南.

For QuickBooks for Windows, you'll use the Web Connector. Again, start with the open source QuickBooks PHP DevKit from GitHub. Use the QuickBooks for Windows + PHP quick-start guide instead.

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

That will walk you through setting up a simple Web Connector service which adds test customers to QuickBooks.

基本上,您将创建一个.QWC文件,然后将其加载到QuickBooks中Web连接器(开始>所有程序> QuickBooks> Web连接器).该.QWC文件将指向用于协商QuickBooks与PHP之间的连接的PHP脚本. .在该示例脚本中,您要做的就是交换此变量:

Basically you'll create a .QWC file which you'll load into the QuickBooks Web Connector (Start > All Programs > QuickBooks > Web Connector). That .QWC file will point to a PHP script which negotiates the connection between QuickBooks and PHP. All you have to do in that example script is swap this variable:

  • $ dsn(将其指向您自己的数据库)

对于每个要添加的新功能,最终将编写一个新的请求和响应功能,如.

For each new piece of functionality you want to add, you'll end up writing a new request and response function, as detailed in the QuickBooks Web Connector + PHP docs.

您的代码最终看起来像:

Your code will end up looking something like:

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>[email protected]</Email>
                                                <Contact>Keith Palmer</Contact>
                                        </CustomerAdd>
                                </CustomerAddRq>
                        </QBXMLMsgsRq>
                </QBXML>';

        return $xml;
}

您可以使用 QuickBooks OSR 查找其他qbXML参考.

You can find additional qbXML reference using the QuickBooks OSR.

我们还提供了一个Wiki,其中包含您可以使用的许多示例qbXML请求.

We also provide a wiki with lots of example qbXML requests that you can use.

这篇关于QuickBooks API(php)集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 23:55