intuit / QuickBooks-V3-PHP-SDK

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

IntuitResponse with ValidationFault is invalid XML #445

Open ljudbane opened 2 years ago

ljudbane commented 2 years ago

I noticed that in case of a specific ValidationFault, the XML we can get with DataService->getLastError()->getResponseBody() is not a valid XML. It's missing a closing </Error> tag.

The request was to create an invoice.

Example1:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2022-02-15T06:48:39.759-08:00">
    <Fault type="ValidationFault">
        <Error code="6070" element="Line.Amount">
            <Message>Amount calculation incorrect in the request.</Message>
            <Detail>Amount is not equal to UnitPrice * Qty. Supplied value:58</Detail>
        </Fault>
    </IntuitResponse>

Example2 (validation error in 2 Line elements):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2022-02-15T06:05:45.299-08:00">
    <Fault type="ValidationFault">
        <Error code="6070" element="Line.Amount">
            <Message>Amount calculation incorrect in the request.</Message>
            <Detail>Amount is not equal to UnitPrice * Qty. Supplied value:290</Detail>
            <Error code="6070" element="Line.Amount">
                <Message>Amount calculation incorrect in the request.</Message>
                <Detail>Amount is not equal to UnitPrice * Qty. Supplied value:58</Detail>
            </Error>
        </Fault>
    </IntuitResponse>

Our code that triggered this:

$invoiceObj = Invoice::create($invoiceData);    // $invoiceData is prepared array with our data for invoice.
$resultingInvoiceObj = $this->dataService->Add($invoiceObj);
$error = $this->dataService->getLastError();

if ($error) {
    $responseBody = $error->getResponseBody();
    throw new Exception('Create invoice failed. QB data service response body: ' . $responseBody);
    // Once $responseBody was inspected we noticed the invalid XML.
}

I'm not sure if this is an issue with PHP SDK, it looks more like an issue with QuickBooks backend.