C# QBO IPP API-如何将付款链接到发票

C# QBO IPP API-如何将付款链接到发票,c#,quickbooks,quickbooks-online,C#,Quickbooks,Quickbooks Online,我能够成功创建发票和付款,但似乎无法将付款与发票正确链接。我尝试了几种变体,但要么根本没有链接,要么在错误日志中出现“业务验证错误:意外内部错误”。下面是我的c代码。是否有一种将付款链接到发票的简化方法(示例) Invoice i = QBGet_InvoiceByMDVInvoiceNum(MDVInvoiceNum); Payment p = new Payment(); Customer customer = QBGet_CustomerByName(ClientName, "Compan

我能够成功创建发票和付款,但似乎无法将付款与发票正确链接。我尝试了几种变体,但要么根本没有链接,要么在错误日志中出现“业务验证错误:意外内部错误”。下面是我的c代码。是否有一种将付款链接到发票的简化方法(示例)

Invoice i = QBGet_InvoiceByMDVInvoiceNum(MDVInvoiceNum);
Payment p = new Payment();
Customer customer = QBGet_CustomerByName(ClientName, "CompanyName");
Account acc = QBGet_AccountsReceivableAccount();

p.TxnDate = DateTime.Now;
p.TxnDateSpecified = true;
List<Line> lineList1 = new List<Line>();
Line pmtLine = new Line();
pmtLine.Amount = ReceivedPaymentAmt;
pmtLine.AmountSpecified = true;
List<LinkedTxn> linkedTxnList = new List<LinkedTxn>();
LinkedTxn linkedtxn = new LinkedTxn();
linkedtxn.TxnId = i.Id;
linkedtxn.TxnType = "invoice";
linkedTxnList.Add(linkedtxn);

pmtLine.LinkedTxn = linkedTxnList.ToArray();

//p.LinkedTxn = linkedTxnList.ToArray();

lineList1.Add(pmtLine);
p.Line = lineList1.ToArray();

p.CustomerRef = new ReferenceType()
{
    Value = customer.Id
};

p.DepositToAccountRef = new ReferenceType() { Value = acc.Id };
p.PaymentRefNum = ReceiptCheckNo; 

p.TotalAmt = ReceivedPaymentAmt;
p.TotalAmtSpecified = true;

DataService service = new DataService(context);
var result = service.Add<Payment>(p);

共享Java代码和相应的工作JSON负载。这可能会有帮助

private void paymentAgainstInvoice() {
    Payment payment = new Payment();
    Date currentDateTime = null;
    try {
        currentDateTime = DateUtils.getCurrentDateTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    payment.setTxnDate(currentDateTime);

    Line line = new Line();
    line.setAmount(new BigDecimal("100"));
    LinkedTxn linkedTxn = new LinkedTxn();
    linkedTxn.setTxnId("248");
    linkedTxn.setTxnType("Invoice");
    List<LinkedTxn> linkedTxnList = new ArrayList<LinkedTxn>();
    linkedTxnList.add(linkedTxn);
    line.setLinkedTxn(linkedTxnList);
    List<Line> lineList = new ArrayList<Line>();
    lineList.add(line);

    payment.setLine(lineList);

    ReferenceType custReferenceType = new ReferenceType();
    custReferenceType.setValue("29");
    custReferenceType.setName("ABC");
    payment.setCustomerRef(custReferenceType);

    payment.setTotalAmt(new BigDecimal("100"));
    ReferenceType accountRefType = new ReferenceType();
    accountRefType.setValue("63");
    payment.setPaymentRefNum("ABC-100-Invoice");
    payment.setDepositToAccountRef(accountRefType );

    try {
        this.service.add(payment);
    } catch (FMSException e) {
        e.printStackTrace();
    }
}

您可以从QBO和UI创建发票,并进行相应的付款。之后,请使用getById调用(在调试模式下)检索对象以查看对象结构。这种调试方法总是有效的。谢谢你,玛纳斯。我已经试过了,但当我试图将付款与发票关联时,它似乎无法正确链接。我想我通过LinkTxn对象做的是对的。你看到我上面的代码有缺陷吗?根据这篇文章:我选择的应收账户似乎不正确,但我不确定如何选择“现金”或类似的东西。我删除了我的支付对象中的“DepositoAccountRef”行,它正常通过了!
private void paymentAgainstInvoice() {
    Payment payment = new Payment();
    Date currentDateTime = null;
    try {
        currentDateTime = DateUtils.getCurrentDateTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    payment.setTxnDate(currentDateTime);

    Line line = new Line();
    line.setAmount(new BigDecimal("100"));
    LinkedTxn linkedTxn = new LinkedTxn();
    linkedTxn.setTxnId("248");
    linkedTxn.setTxnType("Invoice");
    List<LinkedTxn> linkedTxnList = new ArrayList<LinkedTxn>();
    linkedTxnList.add(linkedTxn);
    line.setLinkedTxn(linkedTxnList);
    List<Line> lineList = new ArrayList<Line>();
    lineList.add(line);

    payment.setLine(lineList);

    ReferenceType custReferenceType = new ReferenceType();
    custReferenceType.setValue("29");
    custReferenceType.setName("ABC");
    payment.setCustomerRef(custReferenceType);

    payment.setTotalAmt(new BigDecimal("100"));
    ReferenceType accountRefType = new ReferenceType();
    accountRefType.setValue("63");
    payment.setPaymentRefNum("ABC-100-Invoice");
    payment.setDepositToAccountRef(accountRefType );

    try {
        this.service.add(payment);
    } catch (FMSException e) {
        e.printStackTrace();
    }
}
{
   "CustomerRef":{
      "value":"29",
      "name":"ABC"
   },
   "DepositToAccountRef":{
      "value":"63"
   },
   "PaymentRefNum":"ABC-100-Invoice",
   "TotalAmt":100,
   "TxnDate":"2014-11-30",
   "Line":[
      {
         "Amount":100,
         "LinkedTxn":[
            {
               "TxnId":"248",
               "TxnType":"Invoice"
            }
         ]
      }
   ]
}