I’m trying to add the Bank Deposit (CA305000) to a custom endpoint, however I’m struggling with getting the payment details to populate.
I have no issue with adding the Header or the charges, but I’ve tried a bunch of different ways of adding the payments without any success.
Below is how I have the endpoint at the moment however I have tried it with the AddPaymentDetail not being nested within AddPayment as well as trying to add the payments directly through Payments.
When I submit a request the record will create however the payment detail will be empty
The closest I can got to having it look like it is trying to add the payments is if I omit the DocModule property of $.AddPayment.Payments[*] then I receive the following error.
Any help here would be greatly appreciated.
Best answer by matthewgerdan
If anyone finds themselves in the same boat,
I was able to get this working by adding a new child DAC mapped to a separate detail point in the webservice and then overriding the Persist method of CADepositEntry so that it if any records were added to this new DAC it then adds them into the Details cache using the Base.AddPaymentInfoBatch. Also cancels an attempt to persist to the PaymentInsert DAC.
publicdelegatevoidPersistDelegate();
[PXOverride]
publicvoidPersist(PersistDelegate baseMethod)
{
// Retrieve the current CADeposit record.
CADeposit deposit = this.Base.Document.Current;
if (deposit == null) return;
// Prepare a list to store PaymentInfo records to be added.
List<PaymentInfo> paymentsToAdd = new List<PaymentInfo>();
// Iterate over each detail record in the UnboundPayments view.foreach (BCCAPaymentInsert detail in UnboundPayments.Select())
{
// Extract necessary fields from the detail record.string docModule = detail.OrigModule;
string docType = detail.OrigDocType;
string refNbr = detail.OrigRefNbr;
// Ensure all fields are non-null before proceeding.if (docModule != null && docType != null && refNbr != null)
{
// Query the AvailablePayments view to find a matching payment.// Correct filters need to be applied to PaymentFiltervar query = Base.AvailablePayments.Select().RowCast<PaymentInfo>().FirstOrDefault(pi =>
pi.DocType == docType &&
pi.RefNbr == refNbr &&
pi.Module == docModule);
// If a matching payment is found, add it to the list.if (query != null)
{
paymentsToAdd.Add(query);
}
else
{
// Throw an exception if no matching payment is found.string exceptionMessage = String.Format(BCCA.Messages.PaymentMissingFromAvailablePayments, refNbr);
thrownew PXException(exceptionMessage);
}
}
}
// If there are payments to add, process them using the native method.if (paymentsToAdd.Count > 0)
{
Base.AddPaymentInfoBatch(paymentsToAdd);
}
// Clear the cache of UnboundPayments to remove processed records.
UnboundPayments.Cache.Clear();
// Call the base Persist method.
baseMethod();
}
protectedvoid _(Events.RowPersisting<BCCAPaymentInsert> e)
{
e.Cancel = true;
}
@matthewgerdan , I don’t think you need to wrapt the Payments object in AddPayment object. In other words, have your Payments on the same level as Charges.
@Yuri Karpenko , I adjusted the endpoint but I’m still getting the same result, I also tried adding into Payments as well as AddPaymenst (sorry about the typo). In both cases the result is the same.
@Yuri Karpenko , Yeah, I’ve got no issues when doing this through the UI, I do have to add the payment through the pop-up form after clicking Add Payment.
I can also then access the payments with a get request. I have also tested deleting payments that were added and have no issues, it’s only with adding them that I’m struggling.
@matthewgerdan , thanks for your patience. I just double checked with our developers, and indeed, it required some custom code (Acumatica customization) to enable adding payments to bank deposits. Unfortunately, that code is not something that is publicly available.
I was able to get this working by adding a new child DAC mapped to a separate detail point in the webservice and then overriding the Persist method of CADepositEntry so that it if any records were added to this new DAC it then adds them into the Details cache using the Base.AddPaymentInfoBatch. Also cancels an attempt to persist to the PaymentInsert DAC.
publicdelegatevoidPersistDelegate();
[PXOverride]
publicvoidPersist(PersistDelegate baseMethod)
{
// Retrieve the current CADeposit record.
CADeposit deposit = this.Base.Document.Current;
if (deposit == null) return;
// Prepare a list to store PaymentInfo records to be added.
List<PaymentInfo> paymentsToAdd = new List<PaymentInfo>();
// Iterate over each detail record in the UnboundPayments view.foreach (BCCAPaymentInsert detail in UnboundPayments.Select())
{
// Extract necessary fields from the detail record.string docModule = detail.OrigModule;
string docType = detail.OrigDocType;
string refNbr = detail.OrigRefNbr;
// Ensure all fields are non-null before proceeding.if (docModule != null && docType != null && refNbr != null)
{
// Query the AvailablePayments view to find a matching payment.// Correct filters need to be applied to PaymentFiltervar query = Base.AvailablePayments.Select().RowCast<PaymentInfo>().FirstOrDefault(pi =>
pi.DocType == docType &&
pi.RefNbr == refNbr &&
pi.Module == docModule);
// If a matching payment is found, add it to the list.if (query != null)
{
paymentsToAdd.Add(query);
}
else
{
// Throw an exception if no matching payment is found.string exceptionMessage = String.Format(BCCA.Messages.PaymentMissingFromAvailablePayments, refNbr);
thrownew PXException(exceptionMessage);
}
}
}
// If there are payments to add, process them using the native method.if (paymentsToAdd.Count > 0)
{
Base.AddPaymentInfoBatch(paymentsToAdd);
}
// Clear the cache of UnboundPayments to remove processed records.
UnboundPayments.Cache.Clear();
// Call the base Persist method.
baseMethod();
}
protectedvoid _(Events.RowPersisting<BCCAPaymentInsert> e)
{
e.Cancel = true;
}
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.