How To Call Recordccpayment Action From Screen Based Web Api Call In Acumatica For Payments And Applications Screen
Hello everybody,
today I want to write a few words with code samples on how to work with Screen based web API in Acumatica.
Stage preparation
Before you go, first step that is needed is to have Acumatica instance ready. So install Acumatica with sales demo database.
As mentioned in the title of the article, I'm going to work with "Payments and Applications" screen ( AR302000 ) and with Action Record CC Payment:
As usually in cases of WEB API calls in .Net, you'll need somehow to create Web Reference.
For Record CC Payment following sequence of Actions is needed.
- In Acumatica instance navigate to page AR302000, and click there on Help -> Web Service:
2. Copy into clipboard url, of the opened window.
3. Go to Visual Studio and create there some Application. For example console app.
4. Then click on References with right mouse click and in pop up choose Add Service Reference:
5. In window that will appear click on Advanced
6. In next window click on "Add Web Reference... " which will cause appearing one more window:
Initially left window will be opened, and then window at the right will be opened.
After all of those steps, you can type following code for your Main function:
static void Main(string[] args) { ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback( (s, c, ch, pe) => { return true; }); using (Screen scr = new Screen()) { scr.CookieContainer = new CookieContainer(); var lr = scr.Login("admin", "123"); if (lr.Code == ErrorCode.OK) { try { var schema = scr.GetSchema(); var commands = new Command[] { schema.Actions.Insert, new Value() { Value = "BESTYPEIMG", LinkedCommand = schema.PaymentSummary.Customer }, new Value() { Value = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"), LinkedCommand = schema.PaymentSummary.Description }, new Value() { Value = "770", LinkedCommand = schema.PaymentSummary.PaymentAmount }, // if configured to prompt, then must set DialogAnswer new Value() { Value = "paymentreffdsafas", LinkedCommand = schema.PaymentSummary.PaymentRef }, new Value() { Value = "xxx", LinkedCommand = schema.RecordCCPaymentCCPaymentData.PCTranNumber }, new Value() { Value = "xxx", LinkedCommand = schema.RecordCCPaymentCCPaymentData.AuthNumber }, new Value() { Value = "OK", LinkedCommand = schema.PaymentSummary.ServiceCommands.DialogAnswer, // Base code shows that it is PaymentSummary (Document.Ask()) Commit = true }, schema.Actions.RecordCCPayment }; scr.Submit(commands); var status = scr.GetProcessStatus(); while (status.Status == ProcessStatus.InProcess) { System.Threading.Thread.Sleep(1000); status = scr.GetProcessStatus(); } if (status.Status == ProcessStatus.Completed) { commands = new Command[] { schema.CreditCardProcessingInfo.TranNbr, schema.CreditCardProcessingInfo.ProcCenter, schema.CreditCardProcessingInfo.TranType, schema.CreditCardProcessingInfo.TranStatus, schema.CreditCardProcessingInfo.PCResponseReason, schema.CreditCardProcessingInfo.TranTime, schema.CreditCardProcessingInfo.ProcStatus, schema.PaymentSummary.ReferenceNbr }; var data = scr.Submit(commands); } } finally { scr.Logout(); } } } }
Summary
In presented code I want to point your attention to those details:
1. This line Snippet
using (Screen scr = new Screen())
will help you to make efficient memory usage, especially for cases when you need to submit a lot of payments
2. try/finally combination or try/catch/finally combination will help you to track error messages
3. This line
Snippet
while (status.Status == ProcessStatus.InProcess)
will help you necessary amount of time for request result.
4. In case if status.Status will be equal to aborted, or something similar, you can use status.Message and check what is there.
5. Quite often it is needed to know some values, that was created during process. For this purpose you may use commands list one more time with sycn request as done in the block
Snippet
if (status.Status == ProcessStatus.Completed)
6. Always, I repeat always call Logout method. Otherwise you'll get error message that you've riched maximum allowed connections for your account.