使用php api(keith palmer)向Quickbooks Online添加发票

时间:2013-03-19 06:43:45

标签: php quickbooks quickbooks-online

我正在尝试使用keith palmer php api

通过我的应用程序向quickbook添加发票

我能够添加客户,列出发票并从中做一堆东西..

但是当我尝试使用基本示例添加发票时,它不会被创建..

继承我的代码片段

    <?php

        $Invoice = new QuickBooks_IPP_Object_Invoice();
        $Header = new QuickBooks_IPP_Object_Header();


        $Header->setTxnDate('2013-03-20');
        $Header->setCustomerId('{QBO-2}');

        $Header->setTotalAmt(101);

        $Invoice->addHeader($Header);

        $Line = new QuickBooks_IPP_Object_Line();
        $Line->setDesc('Invoice desp comes here');
        $Line->setTaxable('false');
        $Line->setItemId('{QBO-2}');
        $Line->setAmount(101);

        $Invoice->addLine($Line);

        print_r($Invoice->asIDSXML());

        print_r('Request [' . $IPP->lastRequest() . ']');
        print_r("<br/><br/>");
        print_r('Response [' . $IPP->lastResponse() . ']');
        print_r("<br/><br/>");

?>  

print_r($ Invoice-&gt; asIDSXML())向我展示了这个

<Invoice>
    <Header>
        <TxnDate>2013-03-20</TxnDate>
        <CustomerId idDomain="QBO">2</CustomerId>
        <TotalAmt>101.00</TotalAmt>
    </Header>
    <Line>
        <Desc>test input invoice descp comes here</Desc>
        <Amount>101</Amount>
        <Taxable>false</Taxable>
        <ItemId idDomain="QBO">2</ItemId>
    </Line>
</Invoice>

print_r('Request ['。$ IPP-&gt; lastRequest()。']')告诉我这个

Request [GET https://qbo.intuit.com/qbo1/rest/user/v2/666328865?oauth_consumer_key=qyprdorhgMjAeQswpCnBBuFUt5NGlv&oauth_nonce=GCRwB&oauth_signature=FKjWjA8VSwtxKvn%2ByGb1LaYd7Kw%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1363757537&oauth_token=qyprdmoCHU437qAutsaqwMzki7izqqjl7cioaZO4uTxkykse&oauth_version=1.0 HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 0

]

print_r('Response ['。$ IPP-&gt; lastResponse()。']')告诉我这个

Response [HTTP/1.1 200 OK
Date: Wed, 20 Mar 2013 05:32:17 GMT
Server: Apache
Set-Cookie: qboeuid=10.129.32.5.1363757537351379; path=/; expires=Thu, 20-Mar-14 05:32:17 GMT; domain=.intuit.com
Cache-Control: private
Expires: Wed, 31 Dec 1969 16:00:00 PST
Set-Cookie: JSESSIONID=3BC45AC1AAA82F57D777FF1DAB2F9729.c1-pprdqboas30d; Path=/; Secure; HttpOnly
Content-Encoding: gzip
Content-Length: 290
Content-Type: application/xml;charset=UTF-8

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><qbo:QboUser xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo"><qbo:LoginName>jeffery@netconnectweb.com</qbo:LoginName><qbo:Ticket>V1-48-Q0czg6etf4a8rhn9mxnc5a</qbo:Ticket><qbo:AgentId>666328880</qbo:AgentId><qbo:CurrentCompany><qbo:CompanyId>666328865</qbo:CompanyId><qbo:BaseURI>https://sg.qbo.intuit.com/qbo37</qbo:BaseURI></qbo:CurrentCompany></qbo:QboUser>]

1 个答案:

答案 0 :(得分:3)

我的问题是我没有为此添加相应的服务对象才能生效,下面给出的代码片段现在可以完美运行....

<?php

    $InvoiceService = new QuickBooks_IPP_Service_Invoice();
    $Invoice = new QuickBooks_IPP_Object_Invoice();
    $Header = new QuickBooks_IPP_Object_Header();


    $Header->setTxnDate('2013-03-20');
    $Header->setCustomerId('{QBO-2}');
    $Header->setTotalAmt(101);

    $Invoice->addHeader($Header);

    $Line = new QuickBooks_IPP_Object_Line();
    $Line->setDesc('Invoice desp comes here');
    $Line->setTaxable('false');
    $Line->setItemId('{QBO-2}');
    $Line->setAmount(101);

    $Invoice->addLine($Line);

    print_r($Invoice->asIDSXML());

    $resp = $InvoiceService->add($Context, $realmID, $Invoice);

    pr('New invoice is [' . $resp . ']' . "\n");

    print_r('Request [' . $IPP->lastRequest() . ']');
    print_r("<br/><br/>");
    print_r('Response [' . $IPP->lastResponse() . ']');
    print_r("<br/><br/>");

?>