public CustomerDataReader(CCProcessingContext context) { PXGraph graph = context.callerGraph; int? customerId = context.aCustomerID; string customerCD = context.aCustomerCD; int? pminstanceID = context.aPMInstanceID; if (graph == null) { throw new ArgumentNullException(nameof(graph)); } if (customerId == null && String.IsNullOrEmpty(customerCD)) { throw new ArgumentNullException(nameof(customerId), $"Either {nameof(customerId)} or {nameof(customerCD)} must be not null"); } if (pminstanceID == null) { throw new ArgumentNullException(nameof(pminstanceID)); } _graph = graph; _customerID = customerId; _customerCD = customerCD; _pminstanceID = pminstanceID; _prefixForCustomerCD = context.PrefixForCustomerCD; }
public static void GetManagePaymentProfileForm(PXGraph graph, ICCPaymentProfile paymentProfile) { if (graph == null || paymentProfile == null) { return; } CustomerPaymentMethodDetail ccpID = PXSelectJoin <CustomerPaymentMethodDetail, InnerJoin <PaymentMethodDetail, On <CustomerPaymentMethodDetail.paymentMethodID, Equal <PaymentMethodDetail.paymentMethodID>, And <CustomerPaymentMethodDetail.detailID, Equal <PaymentMethodDetail.detailID>, And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards> > > > >, Where <PaymentMethodDetail.isCCProcessingID, Equal <True>, And <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > > .SelectWindowed(graph, 0, 1, paymentProfile.PMInstanceID); if (ccpID != null && !string.IsNullOrEmpty(ccpID.Value)) { ProcessingCardsPluginFactory pluginFactory = GetProcessingCardsPluginFactory(paymentProfile.CCProcessingCenterID); CCCustomerInformationManager cim = GetCustomerInformationManager(pluginFactory); CCProcessingCenter processingCenter = pluginFactory.GetProcessingCenter(); CCProcessingContext context = new CCProcessingContext() { processingCenter = pluginFactory.GetProcessingCenter(), aCustomerID = paymentProfile.BAccountID, aPMInstanceID = paymentProfile.PMInstanceID, callerGraph = graph }; CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(context); cim.SetReadersProvider(readersProvider); cim.GetManagePaymentProfileForm(); } }
public static ICardProcessingReadersProvider GetCardProcessingProvider(CCProcessingContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(new CardProcessingReadersProvider(context)); }
private void InitializeContext() { context = new CCProcessingContext(); ICCPaymentProcessingRepository repository = CCPaymentProcessingRepository.GetCCPaymentProcessingRepository(); CCProcessingCenter processingCenter = repository.GetCCProcessingCenter(processingCenterId); context.processingCenter = processingCenter; context.callerGraph = graph; }
protected CCCustomerInformationManager(string processingCenterID, CCProcessingFeature feature) { _feature = feature; _context = new CCProcessingContext(); _repository = CCPaymentProcessingRepository.GetCCPaymentProcessingRepository(); CCProcessingCenter processingCenter = _repository.GetCCProcessingCenter(processingCenterID); CCProcessingFeatureHelper.CheckProcessing(processingCenter, _feature, _context); _pluginObject = InitializePlugin(_repository.GetCCProcessingCenter(processingCenterID)); }
public static void GetCreatePaymentProfileForm(PXGraph graph, ICCPaymentProfileAdapter paymentProfileAdapter) { if (graph == null || paymentProfileAdapter == null) { return; } ICCPaymentProfile ccPaymentProfile = paymentProfileAdapter.Current; PXCache cache = paymentProfileAdapter.Cache; ProcessingCardsPluginFactory pluginFactory = GetProcessingCardsPluginFactory(ccPaymentProfile.CCProcessingCenterID); CCCustomerInformationManager cim = GetCustomerInformationManager(pluginFactory); CCProcessingContext context = new CCProcessingContext() { processingCenter = pluginFactory.GetProcessingCenter(), aCustomerID = ccPaymentProfile.BAccountID, aPMInstanceID = ccPaymentProfile.PMInstanceID, callerGraph = graph }; CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(context); cim.SetReadersProvider(readersProvider); string id = ccPaymentProfile.CustomerCCPID; if (id == null) { id = cim.CreateCustomerProfile(); ICCPaymentProfile cpm = cache.CreateCopy(ccPaymentProfile) as ICCPaymentProfile; cpm.CustomerCCPID = id; cache.Update(cpm); } var processingCenter = pluginFactory.GetProcessingCenter(); if (processingCenter.CreateAdditionalCustomerProfiles == true) { int customerProfileCount = CCProcessingHelper.CustomerProfileCountPerCustomer(graph, ccPaymentProfile.BAccountID, ccPaymentProfile.CCProcessingCenterID); // Total customer profile count per customer var cardLimit = processingCenter.CreditCardLimit; if (cardLimit != null && cardLimit > 0) { int allPaymentProfileCount = cim.GetAllPaymentProfiles().Count(); if (CCProcessingHelper.IsCreditCardCountEnough(allPaymentProfileCount, cardLimit.Value)) { context.PrefixForCustomerCD = CCProcessingHelper.BuildPrefixForCustomerCD(customerProfileCount, processingCenter); id = cim.CreateCustomerProfile(); ICCPaymentProfile cpm = cache.CreateCopy(ccPaymentProfile) as ICCPaymentProfile; cpm.CustomerCCPID = id; cache.Update(cpm); } } } cim.GetCreatePaymentProfileForm(); }
public virtual IList <ISettingsDetail> ExportSettings(PXGraph callerGraph, string processingCenterID) { CCProcessingContext context = new CCProcessingContext() { callerGraph = callerGraph }; CCProcessingCenter processingCenter = _repository.GetCCProcessingCenter(processingCenterID); CCProcessingFeatureHelper.CheckProcessing(processingCenter, CCProcessingFeature.Base, context); if (context.processingCenter == null) { throw new PXException(Messages.ERR_CCProcessingCenterNotFound); } var processor = GetProcessingWrapper(context); List <ISettingsDetail> processorSettings = new List <ISettingsDetail>(); processor.ExportSettings(processorSettings); return(processorSettings); }
public virtual bool TestCredentials(PXGraph callerGraph, string processingCenterID) { CCProcessingContext context = new CCProcessingContext() { callerGraph = callerGraph }; CCProcessingCenter processingCenter = _repository.GetCCProcessingCenter(processingCenterID); CCProcessingFeatureHelper.CheckProcessing(processingCenter, CCProcessingFeature.Base, context); if (context.processingCenter == null) { throw new PXException(Messages.ERR_CCProcessingCenterNotFound); } var processor = GetProcessingWrapper(context); APIResponse apiResponse = new APIResponse(); processor.TestCredentials(apiResponse); ProcessAPIResponse(apiResponse); return(apiResponse.isSucess); }
public virtual void ValidateSettings(PXGraph callerGraph, string processingCenterID, ISettingsDetail settingDetail) { CCProcessingContext context = new CCProcessingContext() { callerGraph = callerGraph }; CCProcessingCenter processingCenter = _repository.GetCCProcessingCenter(processingCenterID); CCProcessingFeatureHelper.CheckProcessing(processingCenter, CCProcessingFeature.Base, context); if (context.processingCenter == null) { throw new PXException(Messages.ERR_CCProcessingCenterNotFound); } var processor = GetProcessingWrapper(context); CCErrors result = processor.ValidateSettings(settingDetail); if (result.source != CCErrors.CCErrorSource.None) { throw new PXSetPropertyException(result.ErrorMessage, PXErrorLevel.Error); } }
protected ICardTransactionProcessingWrapper GetProcessingWrapper(CCProcessingContext context) { if (context.processingCenter == null) { throw new PXException(Messages.ERR_CCProcessingCenterNotFound); } object processor; try { Type processorType = PXBuildManager.GetType(context.processingCenter.ProcessingTypeName, true); processor = Activator.CreateInstance(processorType); } catch (Exception) { throw new PXException(Messages.ERR_ProcessingCenterTypeInstanceCreationFailed, context.processingCenter.ProcessingTypeName, context.processingCenter.ProcessingCenterID); } return(_processingWrapper(processor, context)); }
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); }
public static IHostedFromProcessingWrapper GetBaseProfileProcessingWrapper(object pluginObject, CCProcessingContext context) { if (pluginObject is V1.ICCPaymentProcessing) { return(new V1HostedFormProcessor((V1.ICCPaymentProcessing)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } if (pluginObject is V2.ICCProcessingPlugin) { return(new V2HostedFormProcessor((V2.ICCProcessingPlugin)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } throw new PXException(V1.Messages.UnknownPluginType, pluginObject.GetType().Name); }
protected CardProcessingReadersProvider(CCProcessingContext context) { _context = context; _string2DateConverter = _context.expirationDateConverter; }
public static IExtendedProfileProcessingWrapper GetExtendedProfileProcessingWrapper(object pluginObject, CCProcessingContext context) { if (HttpContext.Current?.Request?.Url.Scheme != null && HttpContext.Current.Request.Url.Scheme != System.Uri.UriSchemeHttps) { throw new PXException(CCProcessingBase.Messages.MustUseHttps); } if (pluginObject is V1.ICCPaymentProcessing) { string errorMessage = PXMessages.LocalizeFormatNoPrefixNLA( Messages.FeatureNotSupportedByProcessing, CCProcessingFeature.ExtendedProfileManagement); throw new PXException(errorMessage); } if (pluginObject is V2.ICCProcessingPlugin) { return(new V2ExtendedProfileProcessor((V2.ICCProcessingPlugin)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } throw new PXException(V1.Messages.UnknownPluginType, pluginObject.GetType().Name); }
public static IExtendedProfileProcessingWrapper GetExtendedProfileProcessingWrapper(object pluginObject, CCProcessingContext context) { if (pluginObject is V1.ICCPaymentProcessing) { string errorMessage = PXMessages.LocalizeFormatNoPrefixNLA( Messages.FeatureNotSupportedByProcessing, CCProcessingFeature.ExtendedProfileManagement); throw new PXException(errorMessage); } if (pluginObject is V2.ICCProcessingPlugin) { return(new V2ExtendedProfileProcessor((V2.ICCProcessingPlugin)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } throw new PXException(V1.Messages.UnknownPluginType, pluginObject.GetType().Name); }
public static void GetOrCreatePaymentProfile(PXGraph graph , ICCPaymentProfileAdapter payment , ICCPaymentProfileDetailAdapter paymentDetail) { ICCPaymentProfile paymentProfile = payment.Current; bool isHF = CCProcessingHelper.IsHFPaymentMethod(graph, payment.Current.PMInstanceID); bool isConverting = false; if (paymentProfile is CustomerPaymentMethod) { isConverting = ((CustomerPaymentMethod)paymentProfile).Selected == true; } isHF = isHF && !isConverting; ICCPaymentProfileDetail CCPIDDet = null; bool isIDFilled = false; bool isOtherDetsFilled = false; foreach (Tuple <ICCPaymentProfileDetail, ICCPaymentMethodDetail> det in paymentDetail.Select()) { ICCPaymentProfileDetail ppd = det.Item1; ICCPaymentMethodDetail pmd = det.Item2; if (pmd.IsCCProcessingID == true) { isIDFilled = ppd.Value != null; CCPIDDet = ppd; } else { isOtherDetsFilled = ppd.Value != null || isOtherDetsFilled; } } if (CCPIDDet == null) { //something's very wrong throw new PXException(Messages.NOCCPID, payment.Current.Descr); } if (isIDFilled && isOtherDetsFilled) { return; } bool tryGetProfile = isIDFilled && !isOtherDetsFilled; if ((isIDFilled || isOtherDetsFilled) && !isHF || tryGetProfile) { var currCpm = payment.Current; ProcessingCardsPluginFactory pluginFactory = GetProcessingCardsPluginFactory(currCpm.CCProcessingCenterID); CCCustomerInformationManager cim = GetCustomerInformationManager(pluginFactory); CCProcessingCenter processingCenter = pluginFactory.GetProcessingCenter(); CCProcessingContext context = new CCProcessingContext() { processingCenter = pluginFactory.GetProcessingCenter(), aCustomerID = currCpm.BAccountID, aPMInstanceID = currCpm.PMInstanceID, callerGraph = graph, expirationDateConverter = s => CustomerPaymentMethodMaint.ParseExpiryDate(graph, currCpm, s) }; CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(context); cim.SetReadersProvider(readersProvider); string id = currCpm.CustomerCCPID; if (currCpm.CustomerCCPID == null) { id = cim.CreateCustomerProfile(); paymentProfile.CustomerCCPID = id; payment.Cache.Update(paymentProfile); } if (processingCenter.CreateAdditionalCustomerProfiles == true && !tryGetProfile) { int customerProfileCount = CCProcessingHelper.CustomerProfileCountPerCustomer(graph, currCpm.BAccountID, currCpm.CCProcessingCenterID); // Total customer profile count per customer var cardLimit = processingCenter.CreditCardLimit; if (cardLimit != null && cardLimit > 0) { int allPaymentProfileCount = cim.GetAllPaymentProfiles().Count(); if (CCProcessingHelper.IsCreditCardCountEnough(allPaymentProfileCount, cardLimit.Value)) { context.PrefixForCustomerCD = CCProcessingHelper.BuildPrefixForCustomerCD(customerProfileCount, processingCenter); id = cim.CreateCustomerProfile(); paymentProfile.CustomerCCPID = id; payment.Cache.Update(paymentProfile); } } } if (isOtherDetsFilled) { string newPMId = cim.CreatePaymentProfile(); CCPIDDet.Value = newPMId; CCPIDDet = paymentDetail.Cache.Update(CCPIDDet) as ICCPaymentProfileDetail; } CreditCardData cardData = cim.GetPaymentProfile(); if (cardData != null && !string.IsNullOrEmpty(cardData.PaymentProfileID)) { foreach (Tuple <ICCPaymentProfileDetail, ICCPaymentMethodDetail> det in paymentDetail.Select()) { ICCPaymentProfileDetail ppd = det.Item1; ICCPaymentMethodDetail pmd = det.Item2; if (ppd.DetailID == CCPIDDet.DetailID) { continue; } string detailValue = null; if (pmd.IsCCProcessingID != true && pmd.IsIdentifier == true && !string.IsNullOrEmpty(cardData.CardNumber)) { detailValue = cardData.CardNumber; } ppd.Value = detailValue; paymentDetail.Cache.Update(ppd); } if (cardData.CardExpirationDate != null) { payment.Cache.SetValueExt(paymentProfile, nameof(paymentProfile.ExpirationDate), cardData.CardExpirationDate); payment.Cache.Update(paymentProfile); } } else { throw new PXException(Messages.CouldntGetPMIDetails, payment.Current.Descr); } } }
public static IBaseProfileProcessingWrapper GetBaseProfileProcessingWrapper(object pluginObject, CCProcessingContext context) { if (HttpContext.Current?.Request?.Url.Scheme != null && HttpContext.Current.Request.Url.Scheme != System.Uri.UriSchemeHttps) { throw new PXException(CCProcessingBase.Messages.MustUseHttps); } if (pluginObject is V1.ICCPaymentProcessing) { return(new V1BaseProfileProcessor((V1.ICCPaymentProcessing)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } if (pluginObject is V2.ICCProcessingPlugin) { return(new V2BaseProfileProcessor((V2.ICCProcessingPlugin)pluginObject, Repositories.CardProcessingReadersProvider.GetCardProcessingProvider(context))); } throw new PXException(V1.Messages.UnknownPluginType, pluginObject.GetType().Name); }
public static void CheckProcessing(CCProcessingCenter processingCenter, CCProcessingFeature feature, CCProcessingContext newContext) { CheckProcessingCenter(processingCenter); newContext.processingCenter = processingCenter; if (feature != CCProcessingFeature.Base && !CCProcessingFeatureHelper.IsFeatureSupported(processingCenter, feature)) { throw new PXException(Messages.FeatureNotSupportedByProcessing, feature.ToString()); } }
public static IHostedPaymentFormProcessingWrapper GetPaymentFormProcessingWrapper(object pluginObject, ICardProcessingReadersProvider provider, CCProcessingContext context) { CCProcessingHelper.CheckHttpsConnection(); var isV1Interface = CCProcessingHelper.IsV1ProcessingInterface(pluginObject.GetType()); if (isV1Interface) { throw new PXException(Messages.TryingToUseNotSupportedPlugin); } var v2ProcessingInterface = CCProcessingHelper.IsV2ProcessingInterface(pluginObject); if (v2ProcessingInterface != null) { V2HostedFormProcessor wrapper = new V2HostedFormProcessor(v2ProcessingInterface); wrapper.ProcessingCenterId = context?.processingCenter.ProcessingCenterID; wrapper.CompanyName = context?.callerGraph.Accessinfo.CompanyName; ISetCardProcessingReadersProvider setProviderBehaviour = wrapper as ISetCardProcessingReadersProvider; if (setProviderBehaviour == null) { throw new PXException(NotLocalizableMessages.ERR_CardProcessingReadersProviderSetting); } setProviderBehaviour.SetProvider(provider); return(wrapper); } throw new PXException(V1.Messages.UnknownPluginType, pluginObject.GetType().Name); }
public CardProcessingReadersProvider(CCProcessingContext context) { _context = context ?? throw new ArgumentNullException(nameof(context)); _string2DateConverter = _context.expirationDateConverter; }