Skip to main content
Solved

Bank Deposit REST API. How to add payments?


Forum|alt.badge.img

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.

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.

 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;
 }

 

View original
Did this topic help you find an answer to your question?

11 replies

Yuri Karpenko
Captain II
Forum|alt.badge.img+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.


Forum|alt.badge.img
  • Author
  • Varsity I
  • 23 replies
  • February 1, 2024

@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
Captain II
Forum|alt.badge.img+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


Forum|alt.badge.img
  • Author
  • Varsity I
  • 23 replies
  • February 1, 2024

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

 


Yuri Karpenko
Captain II
Forum|alt.badge.img+6

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


Forum|alt.badge.img
  • Author
  • Varsity I
  • 23 replies
  • February 1, 2024

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

 


RohitRattan88
Acumatica Moderator
Forum|alt.badge.img+4
  • Acumatica Moderator
  • 253 replies
  • February 5, 2024

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


Yuri Karpenko
Captain II
Forum|alt.badge.img+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.


Forum|alt.badge.img
  • Author
  • Varsity I
  • 23 replies
  • February 6, 2024

@RohitRattan88 @Yuri Karpenko , Thanks guys,

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


Forum|alt.badge.img
  • Author
  • Varsity I
  • 23 replies
  • Answer
  • February 9, 2024

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;
 }

 


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2752 replies
  • February 9, 2024

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings