Page 1 of 1
Cannot add Invoice Payments via the SoftPro Select SDK
Posted: Fri Dec 22, 2023 4:54 pm
by skosloske
We are trying to post payments to invoices via the SoftPro Select SDK and are receiving 'Cannot access member.' response on some but not all orders.
While debugging I see that orders that accept invoice payments have the following property at the invoice->payments level:
SoftPro.ClientModel.Collections.IBindingListEx.AllowAdd = true
And orders that are return the 'Cannot access member.' error have
SoftPro.ClientModel.Collections.IBindingListEx.AllowAdd = false
Is there somewhere in the SPS Client that I can check this property at the order level?
Re: Cannot add Invoice Payments via the SoftPro Select SDK
Posted: Sat Dec 23, 2023 5:19 pm
by BobRichards
Please submit your code. I'll take a look at it.
Re: Cannot add Invoice Payments via the SoftPro Select SDK
Posted: Tue Dec 26, 2023 9:23 am
by skosloske
The
'Cannot access member.' error is thrown in the AddPayment method @
payments.Add(invPayment); I am able to add notes for these same orders if I bypass the AddPayment. I am also able to add payments to older orders successfully. Thanks!
Code: Select all
private void AddInvoicePaymentsAndNotes(IOrder order, InvoiceModel invoiceModel)
{
//Get the invoice we are paying.
dynamic invoice = GetInvoice(order, invoiceModel);
if (invoice == null)
{
Logger.Info($"Invoice not found: {invoiceModel.SpsInvoiceNumber}");
throw new KeyNotFoundException($"Invoice not found: {invoiceModel.SpsInvoiceNumber}"); // aka NotFoundException
}
// Get payments collection for the invoice.
IList payments = (IList)invoice.Payments;
// Clear the payments
payments.Clear();
// Add the invoice payments in order
invoiceModel.Payments?.OrderBy(p => p.Sort).ToList().ForEach(p => AddPayment(p, payments, order));
// Add the invoice payment notes
invoiceModel.Notes?.ToList().ForEach(n => _noteHelper.AddInvoiceNote(order, invoice, n));
}
private void AddPayment(PaymentModel paymentModel, IList payments, IOrder order)
{
// Create the new payment and add it to the payments collection.
// Payment is always @ the top of the list and if there is a Payment Adjustment it is second
IOrderItem invPayment = order.CreateNew("InvoicePayment");
payments.Add(invPayment);
// Modify properties AFTER it is added to collection.
invPayment.SetProperty("DatePaid", paymentModel.DatePaid);
invPayment.SetProperty("Description", paymentModel.Description);
invPayment.SetProperty("Amount", paymentModel.Amount);
}
Re: Cannot add Invoice Payments via the SoftPro Select SDK
Posted: Wed Dec 27, 2023 9:09 am
by skosloske
UPDATE:
We found the root cause of this issue was a new COR that was setting invoice payments to read only for certain scenarios. That explains why we are receiving the 'cannot access member' for orders created after a certain date.
Please disregard this question and thank you for your initial response!
Re: Cannot add Invoice Payments via the SoftPro Select SDK
Posted: Tue Jan 02, 2024 3:02 pm
by BobRichards
I'm glad you found the problem. Thanks for the update!