protected virtual void RecordTransaction(ref int?aTranNbr, CCTranType aTranType, CCProcTran aTran, CCProcessingCenter aProcCenter)
        {
            //Add later - use ProcessCenter to fill ExpirationDate
            aTran.ProcessingCenterID    = aProcCenter.ProcessingCenterID;
            aTran.TranType              = CCTranTypeCode.GetTypeCode(aTranType);
            aTran.CVVVerificationStatus = CVVVerificationStatusCode.RelyOnPriorVerification;
            bool cvvVerified         = false;
            bool needCvvVerification = isCvvVerificationRequired(aTranType);

            if (needCvvVerification)
            {
                bool       isStored;
                CCProcTran verifyTran = this.findCVVVerifyingTran(aTran.PMInstanceID, out isStored);
                if (verifyTran != null)
                {
                    cvvVerified = true;
                }
                if (!cvvVerified)
                {
                    aTran.CVVVerificationStatus = CVVVerificationStatusCode.NotVerified;
                }
            }
            aTran.TranNbr   = null;
            aTran.StartTime = aTran.EndTime = PXTimeZoneInfo.Now;
            if (aTranType != CCTranType.AuthorizeOnly)
            {
                aTran.ExpirationDate = null;
            }
            aTran.TranStatus = CCTranStatusCode.Approved;
            aTran.ProcStatus = CCProcStatus.Finalized;
            aTran            = _repository.InsertCCProcTran(aTran);
            _repository.Save();
            aTranNbr = aTran.TranNbr;
        }
示例#2
0
        protected string GetProcessingStatus(V2.TransactionData tranData)
        {
            string tranStatusCode = CCTranStatusCode.GetCode(V2Converter.ConvertTranStatus(tranData.TranStatus));
            string tranTypeCode   = CCTranTypeCode.GetTypeCode(V2Converter.ConvertTranType(tranData.TranType.Value));
            string procStatus     = ExtTransactionProcStatusCode.GetStatusByTranStatusTranType(tranStatusCode, tranTypeCode);

            return(procStatus);
        }
 protected virtual void ProcessTranResult(CCProcTran aTran, CCProcTran aRefTran, ProcessingResult aResult)
 {
     if (aTran.TranType == CCTranTypeCode.GetTypeCode(CCTranType.Void) &&
         aRefTran.IsManuallyEntered())
     {
         if (aResult.TranStatus != CCTranStatus.Approved &&
             ((aResult.ResultFlag & (CCResultFlag.OrigTransactionNotFound | CCResultFlag.OrigTransactionExpired)) != CCResultFlag.None))
         {
             //Force Void over Missed of Expired Authorization transaction;
             int voidingTranNbr;
             RecordVoidingTran(aRefTran, null, out voidingTranNbr);
             aResult.isAuthorized = true;
         }
     }
 }
        public virtual bool RecordCredit(ICCPayment aPmtInfo, string aRefPCTranNbr, string aExtTranRef, string aExtAuthNbr, out int?aTranNbr)
        {
            aTranNbr = null;
            if (!IsCCValidForProcessing(aPmtInfo.PMInstanceID))
            {
                return(false);
            }
            CCProcTran tran = new CCProcTran();

            tran.Copy(aPmtInfo);
            CCProcTran origCCTran = null;

            if (!String.IsNullOrEmpty(aRefPCTranNbr))
            {
                origCCTran = _repository.FindReferencedCCProcTran(aPmtInfo.PMInstanceID, aRefPCTranNbr);
            }

            if (origCCTran != null && (aPmtInfo.PMInstanceID == origCCTran.PMInstanceID))
            {
                //Override Orig Doc Ref by those from orig CC Tran if any
                tran.RefTranNbr         = origCCTran.TranNbr;
                tran.ProcessingCenterID = origCCTran.ProcessingCenterID;
            }
            else
            {
                CCProcessingCenter procCenter = _repository.FindProcessingCenter(aPmtInfo.PMInstanceID, aPmtInfo.CuryID);
                if (procCenter == null || string.IsNullOrEmpty(procCenter.ProcessingTypeName))
                {
                    throw new PXException(Messages.ERR_ProcessingCenterForCardNotConfigured);
                }
                CashAccount cashAccount = _repository.GetCashAccount(procCenter.CashAccountID);
                if (cashAccount.CuryID != aPmtInfo.CuryID)
                {
                    throw new PXException(Messages.ProcessingCenterCurrencyDoesNotMatch, aPmtInfo.CuryID, cashAccount.CuryID);
                }
                tran.ProcessingCenterID = procCenter.ProcessingCenterID;
                tran.RefPCTranNumber    = aRefPCTranNbr;
            }
            tran.PCTranNumber = aExtTranRef;
            tran.AuthNumber   = aExtAuthNbr;
            tran.TranType     = CCTranTypeCode.GetTypeCode(CCTranType.Credit);
            FillRecordedTran(tran);
            tran = _repository.InsertCCProcTran(tran);
            _repository.Save();
            aTranNbr = tran.TranNbr;
            return(true);
        }
        public virtual void RecordVoidingTran(CCProcTran aOrigTran, string aExtTranRef, out int aTranNbr)
        {
            CCProcTran tran = new CCProcTran
            {
                PMInstanceID       = aOrigTran.PMInstanceID,
                ProcessingCenterID = aOrigTran.ProcessingCenterID,
                OrigDocType        = aOrigTran.OrigDocType,
                OrigRefNbr         = aOrigTran.OrigRefNbr,
                DocType            = aOrigTran.DocType,
                RefNbr             = aOrigTran.RefNbr,
                CuryID             = aOrigTran.CuryID,
                Amount             = aOrigTran.Amount,
                RefTranNbr         = aOrigTran.TranNbr,
                PCTranNumber       = aExtTranRef,
                TranType           = CCTranTypeCode.GetTypeCode(CCTranType.Void)
            };

            FillRecordedTran(tran, Messages.LostExpiredTranVoided);
            tran = _repository.InsertCCProcTran(tran);
            _repository.Save();
            aTranNbr = tran.TranNbr.Value;
        }
        protected virtual bool DoTransaction(ref int aTranNbr, CCTranType aTranType, CCProcTran aTran, CCProcTran aRefTran, string aCustomerCD, CCProcessingCenter aProcCenter)
        {
            if (aProcCenter == null)
            {
                aProcCenter = _repository.FindProcessingCenter(aTran.PMInstanceID, aTran.CuryID);
            }

            if (aProcCenter == null || string.IsNullOrEmpty(aProcCenter.ProcessingTypeName))
            {
                throw new PXException(Messages.ERR_ProcessingCenterForCardNotConfigured);
            }
            CashAccount cashAccount = _repository.GetCashAccount(aProcCenter.CashAccountID);

            if (cashAccount.CuryID != aTran.CuryID)
            {
                throw new PXException(Messages.ProcessingCenterCurrencyDoesNotMatch, aTran.CuryID, cashAccount.CuryID);
            }

            aTran.ProcessingCenterID = aProcCenter.ProcessingCenterID;
            aTran.TranType           = CCTranTypeCode.GetTypeCode(aTranType);

            aTran.CVVVerificationStatus = CVVVerificationStatusCode.RelyOnPriorVerification;
            bool cvvVerified         = false;
            bool needCvvVerification = isCvvVerificationRequired(aTranType);

            if (needCvvVerification)
            {
                bool       isStored;
                CCProcTran verifyTran = this.findCVVVerifyingTran(aTran.PMInstanceID, out isStored);
                if (verifyTran != null)
                {
                    cvvVerified = true;
                    if (!isStored)
                    {
                        this.UpdateCvvVerificationStatus(verifyTran);
                    }
                }
                if (!cvvVerified)
                {
                    aTran.CVVVerificationStatus = CVVVerificationStatusCode.NotVerified;
                }
            }
            aTran    = this.StartTransaction(aTran, aProcCenter.OpenTranTimeout);
            aTranNbr = aTran.TranNbr.Value;

            ProcessingInput inputData = new ProcessingInput();

            Copy(inputData, aTran);
            if (!string.IsNullOrEmpty(aCustomerCD))
            {
                inputData.CustomerCD = aCustomerCD;
            }
            if (aRefTran != null)
            {
                inputData.OrigRefNbr = (aTranType == CCTranType.CaptureOnly) ? aRefTran.AuthNumber : aRefTran.PCTranNumber;
            }

            if (needCvvVerification)
            {
                inputData.VerifyCVV = !cvvVerified;
            }

            CCProcessingContext context = new CCProcessingContext()
            {
                callerGraph      = _repository.Graph,
                processingCenter = aProcCenter,
                aCustomerCD      = aCustomerCD,
                aPMInstanceID    = inputData.PMInstanceID,
                aDocType         = inputData.DocType,
                aRefNbr          = inputData.DocRefNbr,
            };
            var processor             = GetProcessingWrapper(context);
            ProcessingResult result   = new ProcessingResult();
            bool             hasError = false;

            try
            {
                result = processor.DoTransaction(aTranType, inputData);
                PXTrace.WriteInformation($"CCPaymentProcessing.DoTransaction. PCTranNumber:{result.PCTranNumber}; PCResponseCode:{result.PCResponseCode}; PCResponseReasonCode:{result.PCResponseReasonCode}; PCResponseReasonText:{result.PCResponseReasonText}; ErrorText:{result.ErrorText}");
            }
            catch (V2.CCProcessingException procException)
            {
                hasError           = true;
                result.ErrorSource = CCErrors.CCErrorSource.ProcessingCenter;
                string errorMessage = String.Empty;
                if (procException.Message.Equals(procException?.InnerException?.Message))
                {
                    errorMessage = procException.Message;
                }
                else
                {
                    errorMessage = procException.Message + "; " + procException?.InnerException?.Message;
                }
                result.ErrorText             = errorMessage;
                result.PCResponseReasonText += errorMessage;
                PXTrace.WriteInformation($"CCPaymentProcessing.DoTransaction.V2.CCProcessingException. ErrorSource:{result.ErrorSource}; ErrorText:{result.ErrorText}");
            }
            catch (WebException webExn)
            {
                hasError           = true;
                result.ErrorSource = CCErrors.CCErrorSource.Network;
                result.ErrorText   = webExn.Message;
                PXTrace.WriteInformation($"CCPaymentProcessing.DoTransaction.WebException. ErrorSource:{result.ErrorSource}; ErrorText:{result.ErrorText}");
            }
            catch (Exception exn)
            {
                hasError           = true;
                result.ErrorSource = CCErrors.CCErrorSource.Internal;
                result.ErrorText   = exn.Message;
                throw new PXException(Messages.ERR_CCPaymentProcessingInternalError, aTranNbr, exn.Message);
            }
            finally
            {
                CCProcTran tran = this.EndTransaction(aTranNbr, result, (hasError ? CCProcStatus.Error : CCProcStatus.Finalized));
                if (!hasError)
                {
                    this.ProcessTranResult(tran, aRefTran, result);
                }
            }
            return(result.isAuthorized);
        }