Automate sales order payments through x++ code

 



We all are aware of  'Complete' sales order functionality: which essentially completes a sales order by making differential payments, added to line.

It submits the command by sending out a nudge to payment lines (CustPaymTable [if any]), by checking out the changes/added/removed from sales inventory/work added and then either closes the transaction by either authorizing the transaction or by failing it by declining the same:





Suppose, you have a situation, where you need to automate this, by reading from some staging table, and then doing the needful to complete the payment.
The following code explains the process:
 MCROrderRecapStatus recapStatus =   MCREndOrder::orderRecap(_salesTable,
                                                                        mcrSalesOrderTotals);
Here you are calling the above shown form, (through code, we don't need to show it). Evidently, _salesTable is the sales table buffer with differential changes.
And then getting the status of the payment, from below:
MCRCustPaymTotals   custPaymTotals = MCRCustPaymTotals::construct(_salesTable.TableId,
                                                    _salesTable.RecId,
                                                    mcrSalesOrderTotals);

Now, you need to analyze the result:
if (recapStatus == MCROrderRecapStatus::Close)
            {
                   //The payment was successful
            }
            else if (recapStatus == MCROrderRecapStatus::CloseAuth)
            {
                   //The payment was authorized
            }
            else if (recapStatus == MCROrderRecapStatus::OpenError)
            {
                boolean  isOutOfBalance = !custPaymTotals.validateTotalPaymAmount(false);
                if (isOutOfBalance
                || custPaymTotals.getOverallPaymStatus() == MCRCustPaymStatus::Declined)
                {
                     //The payment has either been declined or  an out-of-balance situation has resulted
                }
            }

That's it guys๐Ÿ˜›๐Ÿ˜›๐Ÿ˜›

This essentially gives you the status of the transaction, which you can subsequently throw back to your staging table, for furtherances. 
Winding up for now, wishing you all a Merry Christmas and a Happy New Year 2024.

Comments

Popular posts from this blog

X++ : mistakes which developers commit the most

Make your menu items visible on main menu, conditionally,, using this cool feature of D365FO

Speed up your execution performance by using SysGlobalCaches