2

我正在尝试为要导入 QuickBooks Online (QBO) 公司文件的发票的发票行项目指定产品/服务列表项,但出现错误。

我收到的错误是:

Intuit.Ipp.Exception.IdsException: InternalServerError ---> Intuit.Ipp.Exception.EndpointNotFoundException: Ids service endpoint was not found.

这个例外没有给出任何关于我正在做的事情是否有效的进一步细分。

我的单元测试方法:

    [TestMethod()]
    public void CreateTest()
    {
        Entities.Invoice invoice = new Entities.Invoice();
        invoice.ReferenceId = Guid.NewGuid().ToString("N").Substring(0, 10);
        invoice.CreatedDate = DateTime.Now;
        invoice.CustomerId = 1;
        invoice.LineItems.Add(new InvoiceLine() { ItemName = "Initial Funding", Description = "Initial Funding", Amount = 5500 });
        invoice.LineItems.Add(new InvoiceLine() { ItemName = "Lien Fee", Description = "Lien Fee", Amount = 100 });


        IPPRestProfile restProfile = new IPPRestProfile(realmId, accessToken, accessTokenSecret, Intuit.Ipp.Core.IntuitServicesType.QBO, consumerKey, consumerSecret);
        IPP.Invoices target = new IPP.Invoices(restProfile);
        Intuit.Ipp.Data.Invoice actual = target.Create(invoice);

        if (actual != null)
        {
            Console.WriteLine("QB Invoice ID: {0}", actual.Id);
            Console.WriteLine("QB Sync Token: {0}", actual.SyncToken);
            Console.WriteLine("================================================");
            ObjectDumper.Write(actual, 4);
        }
    }

单元测试调用的方法:

        public Intuit.Ipp.Data.Invoice Create(Entities.Invoice invoice)
    {
        // Check pre-conditions
        if (invoice == null) { throw new ArgumentException("Invoice object is required.", "invoice"); }

        var qboInvoice = new Intuit.Ipp.Data.Invoice();
        BuildInvoiceEntity(qboInvoice, invoice);

        return _Service.Add(qboInvoice) as Intuit.Ipp.Data.Invoice;
    }

最后是构建发票方法:

    private void BuildInvoiceEntity(Intuit.Ipp.Data.Invoice qboInvoice, Entities.Invoice invoice)
    {
        if (qboInvoice != null && invoice != null)
        {
            IQuickBooksHeader header = invoice as IQuickBooksHeader;

            if (String.IsNullOrEmpty(header.Id))
            {
                qboInvoice.DocNumber = invoice.ReferenceId;
                qboInvoice.TxnDate = invoice.CreatedDate;
                qboInvoice.TxnDateSpecified = true;

                // Customer
                qboInvoice.CustomerRef = new ReferenceType()
                {
                    type = objectNameEnumType.Customer.ToString(),
                    Value = invoice.CustomerId.ToString()
                };

                // AR Account
                qboInvoice.ARAccountRef = new ReferenceType()
                {
                    type = objectNameEnumType.Account.ToString(),
                    name = "Accounts Receivable"
                };
            }

            if (invoice.LineItems.Count > 0)
            {
                Intuit.Ipp.Data.Line[] invoiceLineCollection = new Intuit.Ipp.Data.Line[invoice.LineItems.Count];
                for (int i = 0; i < invoice.LineItems.Count; i++)
                {
                    var line = invoice.LineItems[i];
                    var qboInvoiceLine = new Intuit.Ipp.Data.Line()
                    {
                        Amount = line.Amount,
                        AmountSpecified = true,
                        Description = line.Description,
                        DetailType = LineDetailTypeEnum.SalesItemLineDetail,
                        DetailTypeSpecified = true,
                        AnyIntuitObject = new SalesItemLineDetail()
                        {
                            ItemRef = new ReferenceType()
                            {
                                name = line.ItemName,
                            },
                            ItemElementName = ItemChoiceType.UnitPrice,
                            AnyIntuitObject = line.Amount
                        }
                    };
                    invoiceLineCollection[i] = qboInvoiceLine;
                }
                qboInvoice.Line = invoiceLineCollection;
            }
        }
    }

如果我从构建方法中删除这段代码:

      ItemRef = new ReferenceType()
      {
          name = line.ItemName,
      },

发票已成功添加发票行项目的产品/服务的默认“服务”列表项。

IPP .NET SDK V3 的在线文档对 ReferenceType 的指定内容含糊不清。只指定列表项的名称有什么问题?如果我尝试为发票行项目指定产品/服务列表项目的方式有误,那么正确的方法是什么?

4

1 回答 1

3

经过几天的研究,我从来没有找到关于为什么我不能像我想要的那样使用名称的答案,即使它在指定 AccountRef 时是这样工作的。但我离题了,这是我的解决方案:

// Hold a collection of QBO items
private ReadOnlyCollection<Item> _Items;

// I set the collection in the constructor only once
public Invoices(Entities.IPPRestProfile restProfile)
{
    if (restProfile == null)
        throw new ArgumentException("IPPRestProfile object is required.", "restProfile");

    OAuthRequestValidator oAuthValidator = new OAuthRequestValidator(restProfile.OAuthAccessToken, restProfile.OAuthAccessTokenSecret,
            restProfile.ConsumerKey, restProfile.ConsumerSecret);
    ServiceContext context = new ServiceContext(restProfile.RealmId, restProfile.DataSource, oAuthValidator);
    _Service = new DataService(context);
    _Items = (new QueryService<Item>(context)).ExecuteIdsQuery("SELECT * FROM Item", QueryOperationType.query);
}

每当我构建发票时,我都会按名称查询集合中的项目 ID:

private void BuildInvoiceEntity(Intuit.Ipp.Data.Invoice qboInvoice, Entities.Invoice invoice)
{
    ...
    // Get the Id value of the item by name
    string itemTypeId = _Items.Where(o => o.Name == line.ItemName).FirstOrDefault().Id;

    // Specify the Id value in the item reference of the SalesItemLineDetail
    var qboInvoiceLine = new Intuit.Ipp.Data.Line()
    {
        Amount = (decimal)amount,
        AmountSpecified = true,
        Description = line.Description,
        DetailType = LineDetailTypeEnum.SalesItemLineDetail,
        DetailTypeSpecified = true,
        AnyIntuitObject = new SalesItemLineDetail()
        {
            ItemRef = new ReferenceType() { Value = itemTypeId },
            AnyIntuitObject = (decimal)line.Rate,
            ItemElementName = ItemChoiceType.UnitPrice
        }
    };
    ...
}

希望这有助于将某人指向正确的方向,以找到可能的更好解决方案。

于 2013-11-04T22:27:01.483 回答