public static void Copy(ProcessingInput aDst, CCProcTran aSrc)
        {
            aDst.TranID       = aSrc.TranNbr.Value;
            aDst.PMInstanceID = aSrc.PMInstanceID.Value;
            bool useOrigDoc = String.IsNullOrEmpty(aSrc.DocType);

            aDst.DocType   = useOrigDoc ? aSrc.OrigDocType : aSrc.DocType;
            aDst.DocRefNbr = useOrigDoc ? aSrc.OrigRefNbr : aSrc.RefNbr;
            aDst.Amount    = aSrc.Amount.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);
        }
Esempio n. 3
0
 public override bool DoTransaction(CCTranType aType, ProcessingInput aInputData, ProcessingResult aResult)
 {
     return(false);
 }