适用于QuickBooks v3.0的IPP .NET SDK创建发票错误 – 错误请求

我很难弄清楚这里到底出了什么问题 – 我从错误的错误请求中得不到很多见解 – 这是我的代码:

OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret); ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBO, oauthValidator); DataService service = new DataService(context); Customer customer = new Customer(); customer.GivenName = "Mary " + DateTime.Now.Second; customer.Title = "Ms."; customer.MiddleName = "Jayne"; customer.FamilyName = "Cooper"; customer.CompanyName = "Mary " + DateTime.Now.Second; Customer resultCustomer = service.Add(customer) as Customer; Invoice invoice = new Invoice(); //Mandatory fields invoice.DocNumber = Guid.NewGuid().ToString("N").Substring(0, 10); invoice.TxnDate = DateTime.Today.Date; invoice.TxnDateSpecified = true; invoice.CustomerRef = new ReferenceType() { Value = resultCustomer.Id }; Line invLine = new Line(); invLine.Amount = 10000; invLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail; invLine.Description = "Test Product"; invoice.Line = new Line[] { invLine }; Invoice resutlInvoice = service.Add(invoice) as Invoice; var invId = resutlInvoice.Id; 

基本上我正在生成一个新客户(工作正常)然后我正在尝试为它们创建一个发票,上面有一个项目。

查看文档中的XML说明: http : //ippdocs.intuit.com/0025_QuickBooksAPI/0050_Data_Services/V3/030_Entity_Services_Reference/Invoice

NuGet包缺少一些东西,我知道这不是真的 – 形成文档:

   15 SalesItemLineDetail  1   67  

我从此SDK获得的Line对象上没有SalesItemLineDetail或ItemRef的属性。

任何人都有这方面的工作示例?

这是.NET devkit与Java不同的领域之一。

您必须将AnyIntuitObject属性设置为SalesItemLineDetail,然后将DetailType属性设置为LineDetailTypeEnum.SalesItemLineDetail"

框架周围有一些零碎的东西,看起来像这样。

这是一个简短的示例,尽管根据评论它没有使用最新的SDK。

 Line l = new Line() { l.AnyIntuitObject = new SalesItemLineDetail() { ItemElementName = ItemChoiceType.UnitPrice, AnyIntuitObject = amount, ... }, DetailType = LineDetailTypeEnum.SalesItemLineDetail, ... } 
 //Find Customer QueryService customerQueryService = new QueryService(context); Customer customer = customerQueryService.ExecuteIdsQuery("Select * From Customer StartPosition 1 MaxResults 1").FirstOrDefault(); //Find Tax Code for Invoice - Searching for a tax code named 'StateSalesTax' in this example QueryService stateTaxCodeQueryService = new QueryService(context); TaxCode stateTaxCode = stateTaxCodeQueryService.ExecuteIdsQuery("Select * From TaxCode Where Name='StateSalesTax' StartPosition 1 MaxResults 1").FirstOrDefault(); //Find Account - Accounts Receivable account required QueryService accountQueryService = new QueryService(context); Account account = accountQueryService.ExecuteIdsQuery("Select * From Account Where AccountType='Accounts Receivable' StartPosition 1 MaxResults 1").FirstOrDefault(); //Find Item QueryService itemQueryService = new QueryService(context); Item item = itemQueryService.ExecuteIdsQuery("Select * From Item StartPosition 1 MaxResults 1").FirstOrDefault(); //Find Term QueryService termQueryService = new QueryService(context); Term term = termQueryService.ExecuteIdsQuery("Select * From Term StartPosition 1 MaxResults 1").FirstOrDefault(); Invoice invoice = new Invoice(); //DocNumber - QBO Only, otherwise use DocNumber invoice.AutoDocNumber = true; invoice.AutoDocNumberSpecified = true; //TxnDate invoice.TxnDate = DateTime.Now.Date; invoice.TxnDateSpecified = true; //PrivateNote invoice.PrivateNote = "This is a private note"; //Line Line invoiceLine = new Line(); //Line Description invoiceLine.Description = "Invoice line description."; //Line Amount invoiceLine.Amount = 330m; invoiceLine.AmountSpecified = true; //Line Detail Type invoiceLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail; invoiceLine.DetailTypeSpecified = true; //Line Sales Item Line Detail SalesItemLineDetail lineSalesItemLineDetail = new SalesItemLineDetail(); //Line Sales Item Line Detail - ItemRef lineSalesItemLineDetail.ItemRef = new ReferenceType() { name = item.Name, Value = item.Id }; //Line Sales Item Line Detail - UnitPrice lineSalesItemLineDetail.AnyIntuitObject = 33m; lineSalesItemLineDetail.ItemElementName = ItemChoiceType.UnitPrice; //Line Sales Item Line Detail - Qty lineSalesItemLineDetail.Qty = 10; lineSalesItemLineDetail.QtySpecified = true; //Line Sales Item Line Detail - TaxCodeRef //For US companies, this can be 'TAX' or 'NON' lineSalesItemLineDetail.TaxCodeRef = new ReferenceType() { Value = "TAX" }; //Line Sales Item Line Detail - ServiceDate lineSalesItemLineDetail.ServiceDate = DateTime.Now.Date; lineSalesItemLineDetail.ServiceDateSpecified = true; //Assign Sales Item Line Detail to Line Item invoiceLine.AnyIntuitObject = lineSalesItemLineDetail; //Assign Line Item to Invoice invoice.Line = new Line[] { invoiceLine }; //TxnTaxDetail TxnTaxDetail txnTaxDetail = new TxnTaxDetail(); txnTaxDetail.TxnTaxCodeRef = new ReferenceType() { name = stateTaxCode.Name, Value = stateTaxCode.Id }; Line taxLine = new Line(); taxLine.DetailType = LineDetailTypeEnum.TaxLineDetail; TaxLineDetail taxLineDetail = new TaxLineDetail(); //Assigning the fist Tax Rate in this Tax Code taxLineDetail.TaxRateRef = stateTaxCode.SalesTaxRateList.TaxRateDetail[0].TaxRateRef; taxLine.AnyIntuitObject = taxLineDetail; txnTaxDetail.TaxLine = new Line[] { taxLine }; invoice.TxnTaxDetail = txnTaxDetail; //Customer (Client) invoice.CustomerRef = new ReferenceType() { name = customer.DisplayName, Value = customer.Id }; //Billing Address PhysicalAddress billAddr = new PhysicalAddress(); billAddr.Line1 = "123 Main St."; billAddr.Line2 = "Unit 506"; billAddr.City = "Brockton"; billAddr.CountrySubDivisionCode = "MA"; billAddr.Country = "United States"; billAddr.PostalCode = "02301"; billAddr.Note = "Billing Address Note"; invoice.BillAddr = billAddr; //Shipping Address PhysicalAddress shipAddr = new PhysicalAddress(); shipAddr.Line1 = "100 Fifth Ave."; shipAddr.City = "Waltham"; shipAddr.CountrySubDivisionCode = "MA"; shipAddr.Country = "United States"; shipAddr.PostalCode = "02452"; shipAddr.Note = "Shipping Address Note"; invoice.ShipAddr = shipAddr; //SalesTermRef invoice.SalesTermRef = new ReferenceType() { name = term.Name, Value = term.Id }; //DueDate invoice.DueDate = DateTime.Now.AddDays(30).Date; invoice.DueDateSpecified = true; //ARAccountRef invoice.ARAccountRef = new ReferenceType() { name = account.Name, Value = account.Id }; Invoice invoiceAdded = dataService.Add(invoice); 

我使用V3 Java devkit创建了发票。 它工作正常。 PFB请求XML。

   b2980 2013-09-05  3 test 10000 SalesItemLineDetail  TAX    TAX 0  1289 QB:37  

Java代码

 List invLine = new ArrayList(); Line line = new Line(); line.setId("3"); line.setDescription("test"); line.setAmount(new BigDecimal("10000")); line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL); SalesItemLineDetail silDetails = new SalesItemLineDetail(); ReferenceType refTaxCode = new ReferenceType(); refTaxCode.setName(taxCode.getName()); refTaxCode.setType(ObjectNameEnumType.TAX_CODE.value()); refTaxCode.setValue(taxCode.getId()); silDetails.setTaxCodeRef(refTaxCode); line.setSalesItemLineDetail(silDetails); invLine.add(line); invoice.setLine(invLine); 

请检查您是否在.net devkit中找到了类似的对象。 我将尝试使用.net devkit(它尚未设置)。 完成后,我将发布代码。

谢谢