Scrappy Cocco
Scrappy Cocco

Reputation: 1204

Add an invoice to Quickbooks Online using php api (keith palmer)

am trying to add an invoice to quickbook via my app using the keith palmer php api

am able to add customers, list invoices and do bunch of stuffs from it..

but when i try to add an invoice using the basic example it doesnt get created..

heres my code snippet

    <?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->asIDSXML()) shows me this

<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->lastRequest() . ']') shows me this

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->lastResponse() . ']') shows me this

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>[email protected]</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>]

Upvotes: 1

Views: 2827

Answers (1)

Scrappy Cocco
Scrappy Cocco

Reputation: 1204

my problem was that i didnt add the corresponding service object for this to have effect, code snippet given below now works perfectly....

<?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/>");

?>

Upvotes: 3

Related Questions