Solved

Bank Deposit REST API. How to add payments?

  • 1 February 2024
  • 11 replies
  • 111 views

Userlevel 2
Badge

Hi Everyone,

 

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.

icon

Best answer by matthewgerdan 9 February 2024, 02:58

View original

11 replies

Userlevel 7
Badge +6

@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.

Userlevel 2
Badge

@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.

 

Userlevel 7
Badge +6

@matthewgerdan , I would try with Postman (vs. testing through Celigo).

This is how we have it set up:

 

 

Our payload simply includes (for Payments object) an array of objects with these fields: DocModule, Type, and ReferenceNbrOrigRefNbr

Userlevel 2
Badge

@Yuri Karpenko , I adjusted my endpoint to match yours however I’m still getting the same results.

 

Userlevel 7
Badge +6

@matthewgerdan , let me ask you this: can you create this bank deposits with the exact same info manually in MYOB?

Userlevel 2
Badge

@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.

 

Userlevel 7
Badge +4

@matthewgerdan 

last time I worked on something similar, it was not supported. Following are the details from that time:

Seems like engineering does not allow to add payments via API. Here's engineering comments regarding the issue in the past:

"Unfortunately, we cannot work with modal windows through the API."

This functionality is currently not supported.

 

Not sure if things have changed since.

Userlevel 7
Badge +6

@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.

Userlevel 2
Badge

@RohitRattan88 @Yuri Karpenko , Thanks guys,

I have a little experience developing customizations, so I’ll give that a crack.

Userlevel 2
Badge

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.

 public delegate void PersistDelegate();
[PXOverride]
public void Persist(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 PaymentFilter
var 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);
throw new 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();
}


protected void _(Events.RowPersisting<BCCAPaymentInsert> e)
{
e.Cancel = true;
}

 

Userlevel 7
Badge

Thank you for sharing your solution with the community @matthewgerdan!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved