Hi,
I’m creating the payment programmatically but payment status is showing Pending Processing.Even tried setting the status to balanced and it didn't worked.
Payment is captured in the External system so we are filling the ExtranalTrsnaction table and below is the code that we used create the payment.
ARPaymentEntry docgraph = PXGraph.CreateInstance<ARPaymentEntry>();
ARPayment objPayment = new ARPayment();
objPayment.DocType = ARDocType.Payment;
objPayment.Status = ARDocStatus.Balanced;
objPayment.CustomerID = order.CustomerID;
objPayment.PaymentMethodID = filter?.PaymentMethod;
// objPayment.CuryID = order.CuryID;
objPayment.ExtRefNbr = filter?.PaymentRefNbr;
objPayment.CuryOrigDocAmt = filter?.PaymentTotal;
docgraph.Document.Cache.Insert(objPayment);
SOAdjust adjnew = new SOAdjust();
adjnew.AdjdOrderNbr = order.OrderNbr;
adjnew.AdjdOrderType = order.OrderType;
adjnew.CuryAdjgAmt = filter?.PaymentTotal;
docgraph.SOAdjustments.Insert(adjnew);
docgraph.Actions.PressSave();
CCProcessingCenter objProcessingCenter = PXSelectJoin<CCProcessingCenter,
InnerJoin<CCProcessingCenterPmntMethod, On<CCProcessingCenter.processingCenterID, Equal<CCProcessingCenterPmntMethod.processingCenterID>>,
InnerJoin<PaymentMethod, On<PaymentMethod.paymentMethodID, Equal<CCProcessingCenterPmntMethod.paymentMethodID>>>>,
Where<CCProcessingCenterPmntMethod.paymentMethodID, Equal<Required<SOOrder.paymentMethodID>>,
And<PaymentMethod.paymentType, Equal<PaymentMethodType.creditCard>,
And<CCProcessingCenter.isActive, Equal<True>>>>>.Select(this, filter.PaymentMethod);
if (objProcessingCenter != null)
{
InsertRecords(docgraph);
docgraph.Document.Current.CCActualExternalTransactionID = docgraph.ExternalTran.Current?.TransactionID;
docgraph.Document.Current.IsCCCaptured = true;
docgraph.Document.Cache.Update(docgraph.Document.Current);
docgraph.Actions.PressSave();
}
private void InsertRecords(ARPaymentEntry docgraph)
{
CCProcTran tran = PXSelectReadonly<CCProcTran, Where<CCProcTran.origRefNbr, Equal<Required<SOOrder.orderNbr>>, And<CCProcTran.origDocType, Equal<Required<SOOrder.orderType>>,
And<CCProcTran.refNbr, Equal<Required<ARPayment.refNbr>>,And< CCProcTran.pCTranNumber ,Equal<Required<CCProcTran.pCTranNumber>>>>>>>.Select(this, docgraph.SOAdjustments.Current?.AdjdOrderNbr, docgraph.SOAdjustments.Current?.AdjdOrderType, docgraph.Document.Current.RefNbr, docgraph.Document.Current.ExtRefNbr);
if (tran == null)
{
ExternalTransaction objExternalTransaction = new ExternalTransaction();
objExternalTransaction.ProcessingCenterID = docgraph.Document.Current.ProcessingCenterID;
objExternalTransaction.PMInstanceID = docgraph.Document.Current.PMInstanceID;
objExternalTransaction.ProcStatus = "CAS";
objExternalTransaction.DocType = ARDocType.Payment;
objExternalTransaction.RefNbr = docgraph.Document.Current.RefNbr;
//objExternalTransaction.OrigDocType = docgraph.SOAdjustments.Current?.AdjdOrderType;
//objExternalTransaction.OrigRefNbr = docgraph.SOAdjustments.Current?.AdjdOrderNbr;
objExternalTransaction.TranNumber = docgraph.Document.Current.ExtRefNbr;
objExternalTransaction.Completed = true;
objExternalTransaction.Amount = docgraph.SOAdjustments.Current?.CuryAdjdAmt;
objExternalTransaction.Active = true;
objExternalTransaction.Direction = "D";
docgraph.ExternalTran.Insert(objExternalTransaction);
//Record Inserting in CCProcTran table to refund
CCProcTran objCCProcTran = new CCProcTran();
objCCProcTran.PMInstanceID = docgraph.Document.Current.PMInstanceID;
objCCProcTran.ProcessingCenterID = docgraph.Document.Current.ProcessingCenterID;
objCCProcTran.DocType = ARDocType.Payment;
objCCProcTran.RefNbr = docgraph.Document.Current.RefNbr;
//objCCProcTran.OrigDocType = docgraph.SOAdjustments.Current?.AdjdOrderType;
//objCCProcTran.OrigRefNbr = docgraph.SOAdjustments.Current?.AdjdOrderNbr;
objCCProcTran.TranType = CCTranTypeCode.PriorAuthorizedCapture;
objCCProcTran.ProcStatus = CCProcStatus.Finalized;
objCCProcTran.CuryID = docgraph.Document.Current.CuryID;
objCCProcTran.TranStatus = CCTranStatusCode.Approved;
objCCProcTran.Amount = docgraph.SOAdjustments.Current?.CuryAdjdAmt;
objCCProcTran.PCTranNumber = docgraph.Document.Current.ExtRefNbr;
objCCProcTran.StartTime = docgraph.Accessinfo.BusinessDate;
objCCProcTran.PCResponseCode = Convert.ToString(1);
objCCProcTran.PCResponseReasonText = KNMCMessages.TransactionApproved;
docgraph.ccProcTran.Insert(objCCProcTran);
docgraph.Actions.PressSave();
}
}