public CCProcTran UpdateTransaction(CCProcTran procTran)
 {
     if (procTran.TransactionID.GetValueOrDefault() == 0)
     {
         throw new ArgumentNullException(nameof(procTran.TransactionID));
     }
     using (var scope = new PXTransactionScope())
     {
         ExternalTransaction extTran = _externalTran.GetExternalTransaction(procTran.TransactionID);
         if (extTran == null)
         {
             throw new Exception($"Could not find External transaction record by TransactionID = {procTran.TransactionID}");
         }
         if (procTran.ProcStatus != CCProcStatus.Opened)
         {
             if (procTran.AuthNumber != null)
             {
                 extTran.AuthNumber = procTran.AuthNumber;
             }
             if (procTran.ExpirationDate != null)
             {
                 extTran.ExpirationDate = procTran.ExpirationDate;
             }
             if (procTran.CVVVerificationStatus != null)
             {
                 extTran.CVVVerification = procTran.CVVVerificationStatus;
             }
             if (procTran.PCTranNumber != null)
             {
                 extTran.TranNumber = procTran.PCTranNumber;
             }
             if (procTran.Amount != null)
             {
                 extTran.Amount = procTran.Amount;
             }
             extTran.PMInstanceID     = procTran.PMInstanceID;
             extTran.ProcessingStatus = ExtTransactionProcStatusCode.GetStatusByTranStatusTranType(procTran.TranStatus, procTran.TranType);
             extTran.LastActivityDate = procTran.EndTime;
             extTran.Active           = CCProcTranHelper.IsActiveTran(procTran);
             extTran.Completed        = CCProcTranHelper.IsCompletedTran(procTran);
             _externalTran.UpdateExternalTransaction(extTran);
             UpdateParentTransaction(extTran, procTran);
         }
         procTran = _cctranRepository.UpdateCCProcTran(procTran);
         Save();
         scope.Complete();
         return(procTran);
     }
 }
 public CCProcTran InsertTransaction(CCProcTran procTran)
 {
     using (var scope = new PXTransactionScope())
     {
         ExternalTransaction extTran = new ExternalTransaction();
         extTran.DocType         = procTran.DocType;
         extTran.RefNbr          = procTran.RefNbr;
         extTran.OrigDocType     = procTran.OrigDocType;
         extTran.OrigRefNbr      = procTran.OrigRefNbr;
         extTran.Amount          = procTran.Amount;
         extTran.Direction       = ExternalTransaction.TransactionDirection.Debet;
         extTran.PMInstanceID    = procTran.PMInstanceID;
         extTran.CVVVerification = procTran.CVVVerificationStatus;
         extTran.ExpirationDate  = procTran.ExpirationDate;
         if (procTran.TranType == CCTranTypeCode.Credit)
         {
             extTran.Direction = ExternalTransaction.TransactionDirection.Credit;
             if (procTran.RefTranNbr != null)
             {
                 CCProcTran refProcTran = _cctranRepository.GetCCProcTran(procTran.RefTranNbr);
                 extTran.ParentTranID = refProcTran.TransactionID;
             }
         }
         if (procTran.ProcStatus == CCProcStatus.Opened)
         {
             extTran.ProcessingStatus = ExtTransactionProcStatusCode.Unknown;
         }
         else
         {
             extTran.ProcessingStatus = ExtTransactionProcStatusCode.GetStatusByTranStatusTranType(procTran.TranStatus, procTran.TranType);
             extTran.Active           = CCProcTranHelper.IsActiveTran(procTran);
             extTran.Completed        = CCProcTranHelper.IsCompletedTran(procTran);
             extTran.TranNumber       = procTran.PCTranNumber;
             extTran.AuthNumber       = procTran.AuthNumber;
             extTran.ExpirationDate   = procTran.ExpirationDate;
             extTran.LastActivityDate = procTran.EndTime;
         }
         extTran = _externalTran.InsertExternalTransaction(extTran);
         UpdateParentTransaction(extTran, procTran);
         procTran.TransactionID = extTran.TransactionID;
         procTran = _cctranRepository.InsertCCProcTran(procTran);
         Save();
         scope.Complete();
         return(procTran);
     }
 }