使用PHP使用API​​在Quickbooks中创建发票时出错

时间:2016-06-30 01:13:43

标签: php quickbooks-online

我正在尝试在Quickbooks在线沙盒帐户中创建发票对象。这是发票对象文档https://developer.intuit.com/docs/api/accounting/Invoice,它定义了发票对象的最简单结构,我正在使用但仍然出错。缺少什么?

 $invoiceObj = new \IPPInvoice();
 $Line = new \IPPLine(); 
 $Line->Amount = 30; 
 $Line->Description = "Test invoice line item";
 $Line->DetailType = "SalesItemLineDetail";
 $Line->AmountSpecified = true;
 $saleItemLineDetail = new \IPPSalesItemLineDetail();
 $saleItemRefType = new \IPPNameValue(); 
 $saleItemRefType->name = "Services";
 $saleItemRefType->value = "1";
 $saleItemLineDetail->ItemRef = $saleItemRefType;
 $saleItemLineDetail->ServiceDate = '2016-06-28';
 $Line->SalesItemLineDetail = $saleItemLineDetail;
 $invoiceObj->Line = $Line;
//$invoiceObj->DocNumber = '23713';
//$invoiceObj->TxnDate = '2016-06-28';
 $invoiceObj->DueDate = date(strtotime('+5 days'));
 $invoiceObj->AutoDocNumber = true;

 $customerRefType = new \IPPNameValue();  
 $customerRefType->name = "DisplayName969745229";
 $customerRefType->value = 58;
 $invoiceObj->CustomerRef = $customerRefType;
 $resultingObj = $dataService->Add($invoiceObj);
 echo "Created Invoice Id={$resultingObj->Id}. Reconstructed response body:\n\n";
 $xmlBody = \XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
    echo $xmlBody . "\n";

`

此代码抛出以下错误:

IdsException: [0]: Required parameter Line.SalesItemLineDetail is missing in the request

任何帮助将不胜感激。感谢

1 个答案:

答案 0 :(得分:0)

我自己弄清楚我是在使用错误的类IPPNameValue设置属性,但它应该是IPPReferenceType

以下是我将来处理相同问题的其他人的工作代码。

$invoiceObj = new \IPPInvoice();
$Line = new \IPPLine(); 
$Line->Amount = 30; 
$Line->Description = "Test invoice line item";
$Line->DetailType = "SalesItemLineDetail";
$Line->AmountSpecified = true;
$saleItemLineDetail = new \IPPSalesItemLineDetail();
$saleItemRefType = new \IPPReferenceType(); 
$saleItemRefType->type = "Service";
$saleItemRefType->name = "Concrete";
$saleItemRefType->value = "1";
$saleItemLineDetail->ItemRef = $saleItemRefType;
$saleItemLineDetail->ServiceDate = '2016-06-28';

$Line->SalesItemLineDetail = $saleItemLineDetail;
$invoiceObj->Line = $Line;

$invoiceObj->DueDate = date(strtotime('+5 days'));
$invoiceObj->AutoDocNumber = true;

$customerRefType = new \IPPReferenceType();  
$customerRefType->type = 'Customer';
$customerRefType->name = "DisplayName969745229";
$customerRefType->value = 58;

$invoiceObj->CustomerRef = $customerRefType;

$resultingObj = $dataService->Add($invoiceObj);
// Echo some formatted output
echo "Created Invoice Id={$resultingObj->Id}. Reconstructed response body:\n\n";
        $xmlBody = \XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
        echo $xmlBody . "\n";