Question

I'm trying to query for purchases from my QBO.

    $IPP->version(QuickBooks_IPP_IDS::VERSION_3);

    $PurchaseService = new QuickBooks_IPP_Service_Purchase();

    $purchases = $PurchaseService->query($Context, $realm, "SELECT * FROM Purchase");
    //print_r($purchases);
    foreach($purchases as $purchase){
        //$purchase  how to get the details TxnDate, TotalAmount and other 
line object details  from each purchase object.
    }

Please provide me link if there is any doc explaining how to handle the response object using php. i'm using IPP V3 Keith Palmer sdk

There are methods for retrieving information form account query object as show below.

$accounts = $AccountService->query($Context, $realm, "SELECT * FROM Account");

    foreach ($accounts as $Account)
    {
        print('Account Id=' . $Account->getId() . ' is named: ' . $Account->getFullyQualifiedName() . '<br>');
        print_r($Account);
    }

I'm looking for similar kind of methods to work on purchase response object

I checked the purchase entities doc on quickbooks but its not providing details on how to extract data from the response object

Was it helpful?

Solution

The PHP methods exactly mirror the XML node names displayed in the Intuit documentation.

For example, Intuit's documentation shows an object like this:

<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-04-22T08:58:03.798-07:00">
  <Purchase domain="QBO" sparse="false">
    <Id>603</Id>
    <SyncToken>1</SyncToken>
    <MetaData>
      <CreateTime>2018-07-18T00:00:00-07:00</CreateTime>
      <LastUpdatedTime>2014-04-22T08:57:37-07:00</LastUpdatedTime>
    </MetaData>
    <TxnDate>2018-07-18</TxnDate>
    <CurrencyRef name="United States Dollar">USD</CurrencyRef>
    <PrivateNote>Taxable expense.</PrivateNote>
    <Line>
      <Id>1</Id>
      <Amount>26.00</Amount>

So, your Purchase object is going to have methods that mirror this XML structure. For example:

$Id = $PurchaseOrder->getId();
$SyncToken = $PurchaseOrder->getSyncToken();

$MetaDataObject = $PurchaseOrder->getMetaData();
$CreateTime = $PurchaseOrder->getMetaData()->getCreateTime();

$TxnDate = $PurchaseOrder->getTxnDate();

Unsurprisingly, there are also ->set*(...) methods too.

$PurchaseOrder->setTxnDate('2014-04-24');

In the case of line items (which there can be more than one of), you can count the number of Line nodes like this:

$number_of_lines = $PurchaseOrder->countLine();

And then loop through them:

for ($i = 0; $i < $number_of_lines; $i++)
{
  $Line = $PurchaseOrder->getLine($i);
  print_r($Line);
}

Unsurprisingly, the Line object will have a method for each node it contains too:

$line_Id = $Line->getId();
$line_Amount = $Line->getAmount();

As a shortcut, you can also use XPath statements to get at this data:

$CreateTime = $Purchase->getXPath('//Purchase/MetaData/CreateTime');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top