4

How do I apply a payment to an existing invoice with the QuickBooks Online API v3 in C#?

I have tried the following code:

    private void UpdateInvoice(Payment payment)
    {
        Invoice oldInvoice = cmbInvoices.SelectedItem as Invoice;
        if (oldInvoice == null) return;
        Invoice invoiceToUpdate = new Invoice();
        invoiceToUpdate.Id = oldInvoice.Id;
        invoiceToUpdate.SyncToken = oldInvoice.SyncToken;
        invoiceToUpdate.Deposit = payment.TotalAmt;
        invoiceToUpdate.DepositSpecified = true;
        invoiceToUpdate.sparse = true;
        invoiceToUpdate.sparseSpecified = true;
        invoiceToUpdate.PaymentType = PaymentTypeEnum.CreditCard;
        invoiceToUpdate.PaymentTypeSpecified = true;
        invoiceToUpdate.PaymentMethodRef = payment.PaymentMethodRef;
        invoiceToUpdate.PaymentRefNum = payment.PaymentRefNum;
        invoiceToUpdate.CustomerRef = oldInvoice.CustomerRef;
        QBO.DataService.Update(invoiceToUpdate);
    }

and it fails with this error:

{"ValidationException was thrown."}

I'm clearly missing something here or I must be doing something wrong. The error message is useless and wish Intuit would clean this up.

I'm getting pretty frustrated with the bad documentation that Intuit puts out for their QuickBooks Online API v3 and wish their would start cleaning it up and making it useful. Also, please remove those dead 404 pages as well while you are at it.

Any help or pointers would be awesome.

Thomas Jaeger
  • 923
  • 1
  • 9
  • 27
  • I too was dissatisfied with the QuickBooks API, so much so, that we ended up scrapping it and just exporting the data we needed from QuickBooks to handle it ourselves. – dub stylee Feb 26 '15 at 00:47
  • @dubstylee, I understand. The thing is, I'm using the REST based IPP v3 SDK and need to update an existing invoice with the online version of QuickBooks via a C# Winform application. So, no QuickBooks desktop interaction here. – Thomas Jaeger Feb 26 '15 at 01:07
  • This is old, so I know this may be well gone... but I've actually found their errors to be pretty straight forward, they just arent bubbled up through the .net v3 api by default. Turn on logging to see request/response, and its real easy to get at the validation error – Ronnyek Sep 30 '15 at 22:05

2 Answers2

2

you need to just create a payment object and associate it with the invoice. It works successfully for my QBO v3 setup.

You are linking the Invoice in the "LinkedTxn" area, so my InvoiceId would be 1282 in this example. My ProccessPayment is false because we're handling payments manually and logging in QBO.

Payment p = new Payment
{
               PaymentRefNum = "73453",
               PaymentTypeSpecified = true,
               PaymentType = PaymentTypeEnum.CreditCard,
               UnappliedAmt = 0,
               UnappliedAmtSpecified = true,
               TotalAmt = amount,
               TotalAmtSpecified = true,
               ProcessPayment = false,
               ProcessPaymentSpecified = true,
               TxnDateSpecified = true,
               TxnDate = charge.Created,
               CurrencyRef = new ReferenceType { name = "US Dollar", Value = "USD" },
               Line = new Line[] { new Line
               {
                              Amount = amount,
                              AmountSpecified = true,
                              DetailType = LineDetailTypeEnum.PaymentLineDetail,
                              DetailTypeSpecified = true,
                              LinkedTxn = new LinkedTxn[] { new LinkedTxn { TxnId = "1282", TxnType = "Invoice" } } }
               },
               CustomerRef = new ReferenceType { Value = "123" }
};
SlaterCodes
  • 1,139
  • 10
  • 21
0

For what its worth trying this very thing was causing me the same problems. Ends up it doesnt like not specifying line items, even when specifying a sparse update. I found reference by a sdk engineer that said just take the originally saved invoice, modify and pass that up to the api. Ended up taking care of at least my problem.

Ronnyek
  • 482
  • 5
  • 16