Reputation: 3558
I am using IPP's PHP API to create invoices. I am creating the invoice using the following code:
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);
}
Which, for my example produces the following data:
{
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:""
}
However, when my code runs, it fails on the $result = $this->_dataService->Add($invoice);
line, and produces the following error.
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 Line 335 CoreHelper::CheckNullResponseAndThrowException($responseBody);
Has anyone ever come across this and have a fix?
Upvotes: 1
Views: 732
Reputation: 2367
Here is an example of an Invoice for a US based company. Please match your invoice against this.-
<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>[email protected]</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>[email protected]</Address>
</BillEmail>
<Balance>24.79</Balance>
<Deposit>0</Deposit>
<AllowIPNPayment>false</AllowIPNPayment>
<AllowOnlinePayment>false</AllowOnlinePayment>
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>
You need to send SalesItemLineDetail also in your line. Please refer these docs for sample invoice and basic tags that need to be sent. https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/030_entity_services_reference/invoice
Refer this for understanding all data types and key concepts- 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
Alternatively create an Invoice in UI and then read it using API explorer. Compare with your xml request. You will get an idea of how the correct payload should be.
Upvotes: 1