用php更新quickbooks发票

时间:2014-05-20 18:21:40

标签: php cakephp curl intuit-partner-platform quickbooks-online

我们需要使用PHP(CakePHP 1.3)在线更新单一发票。我环顾四周,我唯一能找到的就是" keith palmer php api"对于我们想要完成的事情的简单性,这似乎有点过分了。

有没有人完成这个?我不认为快速书更新发票只需要简单的卷曲执行吗?请指教。

4 个答案:

答案 0 :(得分:3)

  

有没有人完成这个?

是的!很多人!

  

我不认为快速书更新发票只需要简单的卷曲执行吗?

不幸的是,它需要的不仅仅是这个。

由于以下三个主要原因,它需要更多一点:

  1. Intuit要求您通过OAuth向QuickBooks Online(仅一次)进行身份验证。 Curl没有内置的OAuth支持,因此您需要使用某种库或代码来签署您的OAuth请求。 OAuth 是一个简单的协议/签名机制。

  2. 要在QuickBooks Online中更新对象,您必须向Intuit发送最新的SyncToken值。最新的SyncToken值只能通过首先通过API查询QuickBooks中的发票查询来获取。即,要进行更新,您必须首先能够进行查询。

  3. Intuit要求您注册一个" app"连接到QuickBooks Online。这提供了设置步骤,并需要OAuth流的信息。

  4. 据说,使用这个库:

    真的不是很难。

    请按照快速入门指南进行操作:

    并查看进行发票更新的示例:

    它看起来像这样:

        $InvoiceService = new QuickBooks_IPP_Service_Invoice();
    
        // Get the existing invoice first (you need the latest SyncToken value)
        $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice WHERE Id = '34' ");
        $Invoice = $invoices[0];
    
        print_r($Invoice);
    
        $Invoice->setTxnDate(date('Y-m-d'));  // Update the invoice date to today's date 
    
        if ($resp = $InvoiceService->update($Context, $realm, $Invoice->getId(), $Invoice))
        {
            print('&nbsp; Updated!<br>');
        }
    

答案 1 :(得分:0)

您可以参考以下步骤,使用IPP的官方PHP sdk与QBO V3 REST API进行通信。

要使用QB API开始开发,您需要在Intuit的appcenter中创建IA应用程序。

从上面的链接中你会得到 - apptoken,消费者密钥和消费者秘密。您可以在IPPOAuthPlayground(PFB链接)中使用上述3个密钥来获取与您的QB Online帐户对应的访问令牌和访问密码。

使用上述令牌,您可以针对QB Online帐户调用任何REST端点。

PHP devkit可以在这里找到。

PHP devkit用户指南

答案 2 :(得分:0)

完成!使用CakePHP 1.3,我们将Keith Palmers API放在webroot目录中。获得授权后,我们会在付款控制器中添加以下功能。

    function updateQBInvoice($invoiceNumber = null, $depositAmount = null) {            
        include(APP."webroot".DS."quickbooks-php".DS."docs".DS."example_app_ipp_v3".DS."config.php");
        $IPP = new QuickBooks_IPP($dsn);
        $creds = $IntuitAnywhere->load($the_username, $the_tenant);
        $IPP->authMode(QuickBooks_IPP::AUTHMODE_OAUTH, $the_username, $creds);  
        $realm = $creds['qb_realm'];

        if ($Context = $IPP->context()) {
            $IPP->version(QuickBooks_IPP_IDS::VERSION_3);
            $InvoiceService = new QuickBooks_IPP_Service_Invoice();
            $invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice");

            foreach ($invoices as $Invoice) {
                $docNumber = $Invoice->getDocNumber();
                if ($docNumber == $invoiceNumber) {

                    /* Set the invoice as paid. */
                    $Invoice->setDeposit($depositAmount);

                    if ($resp = $InvoiceService->update($Context, $realm, $Invoice->getId(), $Invoice)) {
                        echo '&nbsp; Updated!<br>';
                    } else {
                        echo '&nbsp; ' . $InvoiceService->lastError() . '<br>';
                    }
                }
            }               
        } else {
            echo 'Unable to load a context...?';
        }
    }

我想有一个更好的方法来抓住发票,但我还没有发现它。我尝试将查询调整为“SELECT * FROM Invoices WHERE DocNumber = XXX”,但这不起作用。

我要感谢大家的帮助,谢谢!

答案 3 :(得分:0)

@Keith

请求:

   [GET https://quickbooks.api.intuit.com/v3/company/210896252/query?query=SELECT+%2A+FROM+Invoice+WHERE+DocNumber%3D2060 HTTP/1.1
    Content-Type: text/plain
    Authorization: OAuth realm="", oauth_signature_method="HMAC-SHA1", oauth_signature="xxx",  oauth_nonce="gZxqN", oauth_timestamp="1400779429", oauth_token="xxx", oauth_consumer_key="xxx", oauth_version="1.0"

    ]

响应:

[HTTP/1.1 200 OK
Date: Thu, 22 May 2014 17:23:49 GMT
intuit_tid: 6f7b9023-3c8e-401c-9028-711300475720
Content-Length: 327
Via: 1.1 ipp-gateway-.net
Content-Type: application/xml;charset=UTF-8
Content-Encoding: gzip
QBO-Version: 73.223
Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
Expires: 0

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-05-22T10:23:50.031-07:00"><Fault type="ValidationFault"><Error code="4000"><Message>Error parsing query</Message><Detail>QueryParserError: Encountered &quot; &lt;INTEGER&gt; &quot;2060 &quot;&quot; at line 1, column 39.
Was expecting one of:
    &quot;false&quot; ...
    &quot;true&quot; ...
    </Detail></Error></Fault></IntuitResponse>]