php:CheckNullResponseAndThrowException - 添加记录时响应为空还是空?

时间:2016-09-29 12:50:47

标签: php sdk quickbooks-online

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

例外:

  

v3-php-sdk-2.4.1 / DataService / DataService.php - 587 -   CheckNullResponseAndThrowException - 响应空或空。

以下是我的代码:

$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();

}

1 个答案:

答案 0 :(得分:0)

    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();
    }