コード例 #1
0
        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 static void GetCreatePaymentProfileForm <TPaymentMethodType>(PXGraph graph,
                                                                            PXSelectBase <TPaymentMethodType> customerPaymentMethodView,
                                                                            TPaymentMethodType currentCustomerPaymentMethod)
            where TPaymentMethodType : CustomerPaymentMethod, new()
        {
            if (graph == null || customerPaymentMethodView == null || currentCustomerPaymentMethod == null)
            {
                return;
            }
            CCCustomerInformationManager cim = new CCCustomerInformationManager(currentCustomerPaymentMethod.CCProcessingCenterID, CCProcessingFeature.HostedForm)
            {
                CustomerID   = currentCustomerPaymentMethod.BAccountID,
                PMInstanceID = currentCustomerPaymentMethod.PMInstanceID,
                CallerGraph  = graph
            };

            string id = currentCustomerPaymentMethod.CustomerCCPID;

            if (currentCustomerPaymentMethod.CustomerCCPID == null)
            {
                id = cim.CreateCustomerProfile();
                TPaymentMethodType cpm = (TPaymentMethodType)customerPaymentMethodView.Cache.CreateCopy(currentCustomerPaymentMethod);
                cpm.CustomerCCPID = id;
                customerPaymentMethodView.Update(cpm);
            }
            var processingCenter = cim._context.processingCenter;

            if (processingCenter.CreateAdditionalCustomerProfiles == true)
            {
                int customerProfileCount = CCProcessingHelper.CustomerProfileCountPerCustomer(graph,
                                                                                              currentCustomerPaymentMethod.BAccountID,
                                                                                              currentCustomerPaymentMethod.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))
                    {
                        cim.PrefixForCustomerCD = CCProcessingHelper.BuildPrefixForCustomerCD(customerProfileCount, processingCenter);
                        id = cim.CreateCustomerProfile();
                        TPaymentMethodType cpm = (TPaymentMethodType)customerPaymentMethodView.Cache.CreateCopy(currentCustomerPaymentMethod);
                        cpm.CustomerCCPID = id;
                        customerPaymentMethodView.Update(cpm);
                    }
                }
            }
            cim.GetCreatePaymentProfileForm();
        }
コード例 #3
0
        public static TranProfile GetOrCreatePaymentProfileByTran(PXGraph graph, ICCPaymentProfileAdapter adapter, string tranId)
        {
            ICCPaymentProfile            paymentProfile   = adapter.Current;
            ProcessingCardsPluginFactory pluginFactory    = GetProcessingCardsPluginFactory(paymentProfile.CCProcessingCenterID);
            CCProcessingCenter           processingCenter = pluginFactory.GetProcessingCenter();
            CCCustomerInformationManager cim = GetCustomerInformationManager(pluginFactory);

            CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(new CCProcessingContext()
            {
                processingCenter = processingCenter,
                aCustomerID      = paymentProfile.BAccountID,
                aPMInstanceID    = paymentProfile.PMInstanceID,
                callerGraph      = graph
            });

            cim.SetReadersProvider(readersProvider);

            Customer    customer = new PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >(graph).Select(paymentProfile.BAccountID);
            TranProfile ret      = null;

            if (paymentProfile.CustomerCCPID == null)
            {
                ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                {
                    LocalCustomerId = customer.AcctCD
                });
                return(ret);
            }
            var cardLimit = processingCenter.CreditCardLimit;

            if (processingCenter.CreateAdditionalCustomerProfiles == true && cardLimit != null && cardLimit > 0)
            {
                int customerProfileCount = CCProcessingHelper.CustomerProfileCountPerCustomer(graph,
                                                                                              paymentProfile.BAccountID,
                                                                                              paymentProfile.CCProcessingCenterID);

                int allPaymentProfileCount = cim.GetAllPaymentProfiles().Count();
                if (CCProcessingHelper.IsCreditCardCountEnough(allPaymentProfileCount, cardLimit.Value))
                {
                    var prefix = CCProcessingHelper.BuildPrefixForCustomerCD(customerProfileCount, processingCenter);
                    ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                    {
                        LocalCustomerId = prefix + customer.AcctCD
                    });
                }
                else
                {
                    ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                    {
                        PCCustomerId = paymentProfile.CustomerCCPID
                    });
                }
            }
            else
            {
                ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                {
                    PCCustomerId = paymentProfile.CustomerCCPID
                });
            }
            return(ret);
        }
コード例 #4
0
        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);
                }
            }
        }