intuit / QuickBooks-V3-PHP-SDK

Official PHP SDK for QuickBooks REST API v3.0: https://developer.intuit.com/
Apache License 2.0
243 stars 246 forks source link

Deleted status from XML response is not reflected in DataService::CDC return value #431

Open spencerwasden opened 2 years ago

spencerwasden commented 2 years ago

I have a deleted payment in QBO. When I query for modified payments since a certain date with DataService::CDC, the response XML indicates the deleted status (see status="Deleted" in Payment element):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2021-12-16T16:40:17.645-08:00">
    <CDCResponse>
        <QueryResponse maxResults="1" totalCount="1">
            <Payment domain="QBO" status="Deleted">
                <Id>2359</Id>
                <MetaData>
                    <LastUpdatedTime>2021-12-15T09:14:16-08:00</LastUpdatedTime>
                </MetaData>
            </Payment>
        </QueryResponse>
    </CDCResponse>
</IntuitResponse>

However, the status member in the corresponding returned object of DataService::CDC is null (see print_r results of CDC's $returnValue below). Should it not reflect the status attribute in the XML above? I would like to be able to query for payments (possibly other types as well) using the CDC function and, while iterating through them, know explicitly which are deleted (without having to use webhooks). The docs say "Deleted entities return a Deleted value for the status field." (https://developer.intuit.com/app/developer/qbo/docs/learn/explore-the-quickbooks-online-api/change-data-capture)

QuickBooksOnline\API\DataService\IntuitCDCResponse Object
(
    [entities] => Array
        (
            [Payment] => Array
                (
                    [0] => QuickBooksOnline\API\Data\IPPPayment Object
                        (
                            [CustomerRef] => 
                            [RemitToRef] => 
                            [ARAccountRef] => 
                            [DepositToAccountRef] => 
                            [PaymentMethodRef] => 
                            [PaymentRefNum] => 
                            [PaymentType] => 
                            [CheckPayment] => 
                            [CreditCardPayment] => 
                            [TotalAmt] => 
                            [UnappliedAmt] => 
                            [ProcessPayment] => 
                            [PaymentEx] => 
                            [DocNumber] => 
                            [TxnDate] => 
                            [DepartmentRef] => 
                            [CurrencyRef] => 
                            [ExchangeRate] => 
                            [PrivateNote] => 
                            [TxnStatus] => 
                            [LinkedTxn] => 
                            [Line] => 
                            [TxnTaxDetail] => 
                            [TxnSource] => 
                            [TaxFormType] => 
                            [TaxFormNum] => 
                            [TransactionLocationType] => 
                            [Tag] => 
                            [TxnApprovalInfo] => 
                            [RecurDataRef] => 
                            [RecurringInfo] => 
                            [Id] => 2359
                            [SyncToken] => 
                            [MetaData] => QuickBooksOnline\API\Data\IPPModificationMetaData Object
                                (
                                    [CreatedByRef] => 
                                    [CreateTime] => 
                                    [LastModifiedByRef] => 
                                    [LastUpdatedTime] => 2021-12-15T09:14:16-08:00
                                    [LastChangedInQB] => 
                                    [Synchronized] => 
                                )

                            [CustomField] => 
                            [AttachableRef] => 
                            [domain] => 
                            [status] => 
                            [sparse] => 
                        )

                )

        )

    [exceptions] => Array
        (
        )

)
exintrovert commented 10 months ago

I fixed this by editing the CDC function in DataService.php Find the following for block:

            for($i = 0; $i < sizeof($responseArray); $i++){
                $currentResponse = $responseArray[$i];
                $currentEntityName = $entityList[$i];
                $entities = $this->responseSerializer->Deserialize($currentResponse->asXML(), false);
                $entityName = $currentEntityName;
                //If we find the actual name, update it.
                foreach ($currentResponse->children() as $currentResponseChild) {
                    $entityName = (string)$currentResponseChild->getName();
                    break;
                }
                $returnValue->entities[$entityName] = $entities;
            }

Add:

$j = 0;
foreach($currentResponse as $item){
    if($item->attributes()->status == "Deleted"){
        $entities[$j]->status = "Deleted";
    }
    $j++;
}

Result:

            for($i = 0; $i < sizeof($responseArray); $i++){
                $currentResponse = $responseArray[$i];
                $currentEntityName = $entityList[$i];
                $entities = $this->responseSerializer->Deserialize($currentResponse->asXML(), false);
                $entityName = $currentEntityName;
                $j = 0;
                foreach($currentResponse as $item){
                    if($item->attributes()->status == "Deleted"){
                        $entities[$j]->status = "Deleted";
                    }
                    $j++;
                }
                //If we find the actual name, update it.
                foreach ($currentResponse->children() as $currentResponseChild) {
                    $entityName = (string)$currentResponseChild->getName();
                    break;
                }
                $returnValue->entities[$entityName] = $entities;
            }

Hope this helps