php: CheckNullResponseAndThrowException - 添加记录时响应为 Null 或 Empty?

php: CheckNullResponseAndThrowException - Response Null or Empty while adding record?

我正在使用 quickbook 进行 quickbook 在线集成 php sdk.When 我想尝试创建发票然后发生以下错误。 在我的应用程序中添加发票记录时出现错误。当我以同样的方式添加客户时它起作用了。

异常:

v3-php-sdk-2.4.1/DataService/DataService.php - 587 - CheckNullResponseAndThrowException - Response Null or Empty.

下面是我的代码:

$invoiceObj = new IPPInvoice();
$invoiceObj->Deposit = '0';
$invoiceObj->AllowIPNPayment = 'false';
$invoiceObj->AllowOnlinePayment = 'false';
$invoiceObj->AllowOnlineCreditCardPayment = 'false';
$invoiceObj->AllowOnlineACHPayment = 'false';
$invoiceObj->DocNumber = '1045';
$invoiceObj->TxnDate = "2016-10-19";
$invoiceObj->Balance = '250.0';
 $invoiceObj->CustomerRef = '4';
$invoiceObj->CustomerMemo = 'Thank you for your business and have a great day!';

$billAddr = new IPPPhysicalAddress();
$billAddr->Id = '2';
$billAddr->Line1 = '4581 Banani St.';
$billAddr->City = 'Dhaka';
$invoiceObj->BillAddr =  $billAddr;

$billEmailAddr = new IPPEmailAddress();
$billEmailAddr->Address = 'test'.rand(0,100).'@gmail.com';
$invoiceObj->BillEmail = $billEmailAddr;

$invoiceObj->CurrencyRef = 'USD';
$invoiceObj->Id = '198';
$invoiceObj->DueDate = date(strtotime('+5 days'));

$invoiceObj->TotalAmt = '250.0';
$invoiceObj->ApplyTaxAfterDiscount = 'false';
$invoiceObj->PrintStatus = 'NeedToPrint';
$invoiceObj->EmailStatus = 'NotSet';

$txnTaxDetail = new IPPTxnTaxDetail();
$txnTaxDetail->TotalTax = '0';

$invoiceObj->TxnTaxDetail = $txnTaxDetail;
$invoiceObj->SyncToken = '0';

$customField = new IPPCustomField();
$customField->DefinitionId = '1';
$customField->Name = 'Crew #';
$customField->Type = 'StringType';

$invoiceObj->CustomField = $customField;

try
{
    $resultingInvoiceObj = $dataService->Add($invoiceObj);
    echo "Created Invoice Id={$resultingInvoiceObj->Id}";
}
catch (Exception $e)
{
    echo $e->getMessage();

}
    I have solved this problem. Missing following required params:

    at least one Line record
    Line.DetailType
    Line.Amount
    Line.Description
    at least one Line.SalesItemLineDetail
    Line.SalesItemLineDetail.ItemRef
    Line.SalesItemLineDetail.Quantity
    Line.SalesItemLineDetail.UnitPrice

**Now final code :** 

 $invoiceObj = new IPPInvoice();
    $invoiceObj->Deposit = '0';
    $invoiceObj->AllowIPNPayment = 'false';
    $invoiceObj->AllowOnlinePayment = 'false';
    $invoiceObj->AllowOnlineCreditCardPayment = 'false';
    $invoiceObj->AllowOnlineACHPayment = 'false';
    $invoiceObj->DocNumber = '1045';
    $invoiceObj->TxnDate = "2016-10-19";
    $invoiceObj->Balance = '250.0';
    $invoiceObj->CustomerRef = '4';
    $invoiceObj->CustomerMemo = 'Thank you for your business and have a great day!';

    $billAddr = new IPPPhysicalAddress();
    $billAddr->Id = '2';
    $billAddr->Line1 = '4581 Banani St.';
    $billAddr->City = 'Dhaka';
    $invoiceObj->BillAddr =  $billAddr;

    $billEmailAddr = new IPPEmailAddress();
    $billEmailAddr->Address = 'test'.rand(0,100).'@gmail.com';
    $invoiceObj->BillEmail = $billEmailAddr;

    $invoiceObj->CurrencyRef = 'USD';
    $invoiceObj->DueDate = date(strtotime('+5 days'));

    $invoiceObj->TotalAmt = '250.0';
    $invoiceObj->ApplyTaxAfterDiscount = 'false';
    $invoiceObj->PrintStatus = 'NeedToPrint';
    $invoiceObj->EmailStatus = 'NotSet';

    $Line = new IPPline();
    $Line->Amount = 15; 
    $Line->DetailType = 'SalesItemLineDetail'; 
    $Line->Description = 'Tst Product';
    $saleItemLineDetail = new IPPSalesItemLineDetail();
    $saleItemLineDetail->ItemRef = '1'; 
    $saleItemLineDetail->Quantity = 2;
    $saleItemLineDetail->UnitPrice = 50;
    $Line->SalesItemLineDetail = $saleItemLineDetail; 
    $invoiceObj->Line = $Line;


    $txnTaxDetail = new IPPTxnTaxDetail();
    $txnTaxDetail->TotalTax = '0';

    $invoiceObj->TxnTaxDetail = $txnTaxDetail;
    $invoiceObj->SyncToken = '0';

    $customField = new IPPCustomField();
    $customField->DefinitionId = '1';
    $customField->Name = 'Crew #';
    $customField->Type = 'StringType';

    $invoiceObj->CustomField = $customField;

    try {
        $resultingInvoiceObj = $dataService->Add($invoiceObj);
        echo "Created Invoice Id={$resultingInvoiceObj->Id}";
    } catch (Exception $e) {
        echo $e->getMessage();
    }