IPP .NET SDK for QuickBooks v3.0 Create Invoice Error - Bad Request
我很难弄清楚这里到底出了什么问题 - 我没有从错误的错误请求中得到很多见解 - 这是我的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 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 包缺少一些东西,我知道这不是真的 - 形成文档:
1 2 3 4 5 6 7 8 9 10 | <Invoice xmlns="http://schema.intuit.com/finance/v3"> <Line> <Amount>15</Amount> <DetailType>SalesItemLineDetail</DetailType> <SalesItemLineDetail> <ItemRef>1</ItemRef> </SalesItemLineDetail> </Line> <CustomerRef>67</CustomerRef> </Invoice> |
我从这个 SDK 获得的
谁有这方面的工作例子?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | //Find Customer QueryService<Customer> customerQueryService = new QueryService<Customer>(context); Customer customer = customerQueryService.ExecuteIdsQuery("Select * From Customer StartPosition 1 MaxResults 1").FirstOrDefault<Customer>(); //Find Tax Code for Invoice - Searching for a tax code named 'StateSalesTax' in this example QueryService<TaxCode> stateTaxCodeQueryService = new QueryService<TaxCode>(context); TaxCode stateTaxCode = stateTaxCodeQueryService.ExecuteIdsQuery("Select * From TaxCode Where Name='StateSalesTax' StartPosition 1 MaxResults 1").FirstOrDefault<TaxCode>(); //Find Account - Accounts Receivable account required QueryService<Account> accountQueryService = new QueryService<Account>(context); Account account = accountQueryService.ExecuteIdsQuery("Select * From Account Where AccountType='Accounts Receivable' StartPosition 1 MaxResults 1").FirstOrDefault<Account>(); //Find Item QueryService<Item> itemQueryService = new QueryService<Item>(context); Item item = itemQueryService.ExecuteIdsQuery("Select * From Item StartPosition 1 MaxResults 1").FirstOrDefault<Item>(); //Find Term QueryService<Term> termQueryService = new QueryService<Term>(context); Term term = termQueryService.ExecuteIdsQuery("Select * From Term StartPosition 1 MaxResults 1").FirstOrDefault<Term>(); 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>(invoice); |
这是 .NET devkit 与 Java 不同的地方之一。
您必须将
框架周围有一些看起来像这样的点点滴滴。
这是一个简短的示例,尽管根据评论它没有使用最新的 SDK。
1 2 3 4 5 6 7 8 9 10 11 |
我使用 V3 Java devkit 创建了一张发票。它工作得很好。 PFB 请求 XML。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Invoice xmlns="http://schema.intuit.com/finance/v3"> <DocNumber>b2980</DocNumber> <TxnDate>2013-09-05</TxnDate> <Line> <Id>3</Id> <Description>test</Description> <Amount>10000</Amount> <DetailType>SalesItemLineDetail</DetailType> <SalesItemLineDetail> <TaxCodeRef type="TaxCode" name="TAX">TAX</TaxCodeRef> </SalesItemLineDetail> </Line> <TxnTaxDetail> <DefaultTaxCodeRef type="Customer" name="TAX">TAX</DefaultTaxCodeRef> <TotalTax>0</TotalTax> </TxnTaxDetail> <CustomerRef name="TestDataCustomer620d5Sample1">1289</CustomerRef> <ARAccountRef type="Account" name="Account Receivable">QB:37</ARAccountRef> </Invoice> |
Java 代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | List<Line> invLine = new ArrayList<Line>(); 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(尚未设置)。完成后,我将发布代码。
谢谢