Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Learn with Subs / Automate sales order paymen...

Automate sales order payments through x++ code, for retail implementations

Subhad365 Profile Picture Subhad365 7 User Group Leader
 


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

*This post is locked for comments