我正在使用IPP的PHP API来创建发票。我使用以下代码创建发票:
public function create_invoice($data) {
$this->_getClientByID($data['clientId']);
$invoice = new IPPInvoice();
$invoice->AllowIPNPayment = "false";
$invoice->AllowOnlinePayment = "false";
$invoice->AllowOnlineCreditCardPayment = "false";
$invoice->AllowOnlineACHPayment = "false";
$invoice->ApplyTaxAfterDiscount = "false";
$invoice->CustomerRef = $data['clientId'];
$invoice->BillAddr = $this->_client[0]->BillAddr;
$invoice->ShipAddr = $this->_client[0]->ShipAddr;
$invoice->DueDate = Date('Y-m-d');
$invoice->PrintStatus = "NotSet";
$invoice->EmailStatus = "EmailSent";
$invoice->BillEmail = array('id'=>'', 'address'=>$data['email'],'default'=>'','tag'=>'');
$invoice->TxnDate = Date('Y-m-d');
$invoice->CurrencyRef = "USD";
$lineItems = array();
$invoiceTotal = 0;
foreach ($data['invoice_items'] as $line) {
$lineItem = new IPPLine();
$invoiceTotal = $invoiceTotal + $line->amount;
$lineItem->Description = $line->service_name;
$lineItem->Amount = $line->amount;
$salesLineItem = new IPPSalesItemLineDetail();
$salesLineItem->ItemRef = 1;
$salesLineItem->UnitPrice = $line->amount;
$salesLineItem->Qty = 1;
$lineItem->DetailType = "SalesItemLineDetail";
$lineItem->SalesItemLineDetail = $salesLineItem;
$lineItems[] = $lineItem;
}
$lineItem = new IPPLine();
$lineItem->DetailType = "SubTotalLineDetail";
$lineItem->Amount = $invoiceTotal;
$lineItems[] = $lineItem;
$invoice->Line = $lineItems;
$invoice->TotalAmt = $invoiceTotal;
$invoice->Balance = $invoiceTotal;
$result = $this->_dataService->Add($invoice);
}
其中,我的示例产生以下数据:
{
Deposit:"",
AllowIPNPayment:"false",
AllowOnlinePayment:"false",
AllowOnlineCreditCardPayment:"false",
AllowOnlineACHPayment:"false",
EInvoiceStatus:"",
ECloudStatusTimeStamp:"",
InvoiceEx:"",
AutoDocNumber:"",
CustomerRef:"889",
CustomerMemo:"",
BillAddr:{
Id:"5438",
Line1:"2021E Pulasky Highway",
Line2:"",
Line3:"",
Line4:"",
Line5:"",
City:"Havre de Grace",
Country:"US",
CountryCode:"",
CountrySubDivisionCode:"MD",
PostalCode:"21078",
PostalCodeSuffix:"",
Lat:"",
Long:"",
Tag:"",
Note:""
},
ShipAddr:{
Id:"5438",
Line1:"2021E Pulasky Highway",
Line2:"",
Line3:"",
Line4:"",
Line5:"",
City:"Havre de Grace",
Country:"US",
CountryCode:"",
CountrySubDivisionCode:"MD",
PostalCode:"21078",
PostalCodeSuffix:"",
Lat:"",
Long:"",
Tag:"",
Note:""
},
RemitToRef:"",
ClassRef:"",
SalesTermRef:"",
DueDate:"2014-08-28",
SalesRepRef:"",
PONumber:"",
FOB:"",
ShipMethodRef:"",
ShipDate:"",
TrackingNum:"",
GlobalTaxCalculation:"",
TotalAmt:"44.85",
HomeTotalAmt:"",
ApplyTaxAfterDiscount:"false",
TemplateRef:"",
PrintStatus:"NotSet",
EmailStatus:"EmailSent",
BillEmail:{
id:"",
address:"",
default:"",
tag:""
},
ARAccountRef:"",
Balance:"44.85",
FinanceCharge:"",
PaymentMethodRef:"",
PaymentRefNum:"",
PaymentType:"",
CheckPayment:"",
CreditCardPayment:"",
DepositToAccountRef:"",
DeliveryInfo:"",
DocNumber:"",
TxnDate:"2014-08-28",
DepartmentRef:"",
CurrencyRef:"USD",
ExchangeRate:"",
PrivateNote:"",
TxnStatus:"",
LinkedTxn:"",
Line:{
0:{
Id:"",
LineNum:"",
Description:"Hosting - Standard",
Amount:"14.95",
LinkedTxn:"",
DetailType:"SalesItemLineDetail",
PaymentLineDetail:"",
DiscountLineDetail:"",
TaxLineDetail:"",
SalesItemLineDetail:{
ServiceDate:"",
TaxInclusiveAmt:"",
SalesItemLineDetailEx:"",
ItemRef:"1",
ClassRef:"",
UnitPrice:"14.95",
RatePercent:"",
PriceLevelRef:"",
MarkupInfo:"",
Qty:"1",
UOMRef:"",
ItemAccountRef:"",
InventorySiteRef:"",
TaxCodeRef:""
},
DescriptionLineDetail:"",
ItemBasedExpenseLineDetail:"",
AccountBasedExpenseLineDetail:"",
DepositLineDetail:"",
PurchaseOrderItemLineDetail:"",
SalesOrderItemLineDetail:"",
ItemReceiptLineDetail:"",
JournalEntryLineDetail:"",
GroupLineDetail:"",
SubTotalLineDetail:"",
CustomField:"",
LineEx:""
},
1:{
Id:"",
LineNum:"",
Description:"Hosting - Standard",
Amount:"14.95",
LinkedTxn:"",
DetailType:"SalesItemLineDetail",
PaymentLineDetail:"",
DiscountLineDetail:"",
TaxLineDetail:"",
SalesItemLineDetail:{
ServiceDate:"",
TaxInclusiveAmt:"",
SalesItemLineDetailEx:"",
ItemRef:"1",
ClassRef:"",
UnitPrice:"14.95",
RatePercent:"",
PriceLevelRef:"",
MarkupInfo:"",
Qty:"1",
UOMRef:"",
ItemAccountRef:"",
InventorySiteRef:"",
TaxCodeRef:""
},
DescriptionLineDetail:"",
ItemBasedExpenseLineDetail:"",
AccountBasedExpenseLineDetail:"",
DepositLineDetail:"",
PurchaseOrderItemLineDetail:"",
SalesOrderItemLineDetail:"",
ItemReceiptLineDetail:"",
JournalEntryLineDetail:"",
GroupLineDetail:"",
SubTotalLineDetail:"",
CustomField:"",
LineEx:""
},
2:{
Id:"",
LineNum:"",
Description:"Hosting - Standard",
Amount:"14.95",
LinkedTxn:"",
DetailType:"SalesItemLineDetail",
PaymentLineDetail:"",
DiscountLineDetail:"",
TaxLineDetail:"",
SalesItemLineDetail:{
ServiceDate:"",
TaxInclusiveAmt:"",
SalesItemLineDetailEx:"",
ItemRef:"1",
ClassRef:"",
UnitPrice:"14.95",
RatePercent:"",
PriceLevelRef:"",
MarkupInfo:"",
Qty:"1",
UOMRef:"",
ItemAccountRef:"",
InventorySiteRef:"",
TaxCodeRef:""
},
DescriptionLineDetail:"",
ItemBasedExpenseLineDetail:"",
AccountBasedExpenseLineDetail:"",
DepositLineDetail:"",
PurchaseOrderItemLineDetail:"",
SalesOrderItemLineDetail:"",
ItemReceiptLineDetail:"",
JournalEntryLineDetail:"",
GroupLineDetail:"",
SubTotalLineDetail:"",
CustomField:"",
LineEx:""
},
3:{
Id:"",
LineNum:"",
Description:"",
Amount:"44.85",
LinkedTxn:"",
DetailType:"SubTotalLineDetail",
PaymentLineDetail:"",
DiscountLineDetail:"",
TaxLineDetail:"",
SalesItemLineDetail:"",
DescriptionLineDetail:"",
ItemBasedExpenseLineDetail:"",
AccountBasedExpenseLineDetail:"",
DepositLineDetail:"",
PurchaseOrderItemLineDetail:"",
SalesOrderItemLineDetail:"",
ItemReceiptLineDetail:"",
JournalEntryLineDetail:"",
GroupLineDetail:"",
SubTotalLineDetail:"",
CustomField:"",
LineEx:""
}
},
TxnTaxDetail:"",
TxnSource:"",
Id:"",
SyncToken:"",
MetaData:"",
CustomField:"",
AttachableRef:"",
domain:"",
status:"",
sparse:""
}
但是,当我的代码运行时,它会在$result = $this->_dataService->Add($invoice);
行上失败,并产生以下错误。
Fatal error: Uncaught IdsException: [0]: 2014-08-28 13:24:33 - /var/www/emoxie.com/vendor/emoxie/quickbooks-sdk/src/DataService/DataService.php - 335 - CheckNullResponseAndThrowException - Response Null or Empty thrown in /var/www/emoxie.com/vendor/emoxie/quickbooks-sdk/src/Core/CoreHelper.php on line 95
DataService.php第335行 CoreHelper :: CheckNullResponseAndThrowException($ responseBody);
有没有人遇到这个问题并有解决方法?
答案 0 :(得分:1)
以下是美国公司的发票示例。请将您的发票与此匹配.-
<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schema.intuit.com/finance/v3">
<DocNumber>96</DocNumber>
<TxnDate>2014-08-21</TxnDate>
<CurrencyRef name="Angolan Kwanza">AOA</CurrencyRef>
<ExchangeRate>1</ExchangeRate>
<Line>
<Id>1</Id>
<LineNum>1</LineNum>
<Amount>23.00</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="bat">3</ItemRef>
<UnitPrice>23</UnitPrice>
<Qty>1</Qty>
<TaxCodeRef>10</TaxCodeRef>
</SalesItemLineDetail>
</Line>
<Line>
<Amount>23.00</Amount>
<DetailType>SubTotalLineDetail</DetailType>
<SubTotalLineDetail />
</Line>
<Line>
<Amount>0.46</Amount>
<DetailType>DiscountLineDetail</DetailType>
<DiscountLineDetail>
<PercentBased>true</PercentBased>
<DiscountPercent>2</DiscountPercent>
<DiscountAccountRef name="Discounts given">74</DiscountAccountRef>
</DiscountLineDetail>
</Line>
<TxnTaxDetail>
<TotalTax>2.25</TotalTax>
<TaxLine>
<Amount>2.25</Amount>
<DetailType>TaxLineDetail</DetailType>
<TaxLineDetail>
<TaxRateRef>20</TaxRateRef>
<PercentBased>true</PercentBased>
<TaxPercent>10</TaxPercent>
<NetAmountTaxable>22.54</NetAmountTaxable>
</TaxLineDetail>
</TaxLine>
</TxnTaxDetail>
<CustomerRef name="gg">3</CustomerRef>
<SalesTermRef>3</SalesTermRef>
<DueDate>2014-09-20</DueDate>
<GlobalTaxCalculation>TaxExcluded</GlobalTaxCalculation>
<TotalAmt>24.79</TotalAmt>
<HomeTotalAmt>24.79</HomeTotalAmt>
<PrintStatus>NotSet</PrintStatus>
<EmailStatus>NotSet</EmailStatus>
<BillEmail>
<Address>foop@gmail.com</Address>
</BillEmail>
<Balance>24.79</Balance>
<Deposit>0</Deposit>
<AllowIPNPayment>false</AllowIPNPayment>
<AllowOnlinePayment>false</AllowOnlinePayment>
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>
</Invoice>
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2014-08-20T23:23:07.692-07:00">
<Invoice domain="QBO" sparse="false">
<Id>14</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2014-08-20T23:23:07-07:00</CreateTime>
<LastUpdatedTime>2014-08-20T23:23:07-07:00</LastUpdatedTime>
</MetaData>
<DocNumber>96</DocNumber>
<TxnDate>2014-08-21</TxnDate>
<CurrencyRef name="Angolan Kwanza">AOA</CurrencyRef>
<ExchangeRate>1</ExchangeRate>
<Line>
<Id>1</Id>
<LineNum>1</LineNum>
<Amount>23.00</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="bat">3</ItemRef>
<UnitPrice>23</UnitPrice>
<Qty>1</Qty>
<TaxCodeRef>10</TaxCodeRef>
</SalesItemLineDetail>
</Line>
<Line>
<Amount>23.00</Amount>
<DetailType>SubTotalLineDetail</DetailType>
<SubTotalLineDetail />
</Line>
<Line>
<Amount>0.46</Amount>
<DetailType>DiscountLineDetail</DetailType>
<DiscountLineDetail>
<PercentBased>true</PercentBased>
<DiscountPercent>2</DiscountPercent>
<DiscountAccountRef name="Discounts given">74</DiscountAccountRef>
</DiscountLineDetail>
</Line>
<TxnTaxDetail>
<TotalTax>2.25</TotalTax>
<TaxLine>
<Amount>2.25</Amount>
<DetailType>TaxLineDetail</DetailType>
<TaxLineDetail>
<TaxRateRef>20</TaxRateRef>
<PercentBased>true</PercentBased>
<TaxPercent>10</TaxPercent>
<NetAmountTaxable>22.54</NetAmountTaxable>
</TaxLineDetail>
</TaxLine>
</TxnTaxDetail>
<CustomerRef name="gg">3</CustomerRef>
<SalesTermRef>3</SalesTermRef>
<DueDate>2014-09-20</DueDate>
<GlobalTaxCalculation>TaxExcluded</GlobalTaxCalculation>
<TotalAmt>24.79</TotalAmt>
<HomeTotalAmt>24.79</HomeTotalAmt>
<PrintStatus>NotSet</PrintStatus>
<EmailStatus>NotSet</EmailStatus>
<BillEmail>
<Address>foop@gmail.com</Address>
</BillEmail>
<Balance>24.79</Balance>
<Deposit>0</Deposit>
<AllowIPNPayment>false</AllowIPNPayment>
<AllowOnlinePayment>false</AllowOnlinePayment>
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>
您还需要在您的行中发送SalesItemLineDetail。请参阅这些文档以获取需要发送的样本发票和基本标签。 https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice
请参阅此内容以了解所有数据类型和关键概念 - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/020_key_concepts/0700_other_topics https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services
或者在UI中创建一个Invoice,然后使用API explorer读取它。与您的xml请求进行比较。您将了解正确的有效负载应该如何。