Example #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();
        }
        public static void GetOrCreatePaymentProfile <TPaymentMethodType, TDetialsType>(PXGraph graph
                                                                                        , PXSelectBase <TPaymentMethodType> customerPaymentMethodView
                                                                                        , PXSelectBase <TDetialsType> detailsView)
            where TPaymentMethodType : CustomerPaymentMethod, new()
            where TDetialsType : CustomerPaymentMethodDetail, new()
        {
            bool isHF         = CCProcessingHelper.IsHFPaymentMethod(graph, customerPaymentMethodView.Current.PMInstanceID);
            bool isConverting = customerPaymentMethodView.Current.Selected == true;

            isHF = isHF && !isConverting;
            TDetialsType CCPIDDet          = null;
            bool         isIDFilled        = false;
            bool         isOtherDetsFilled = false;

            foreach (PXResult <TDetialsType, PaymentMethodDetail> det in detailsView.Select())
            {
                TDetialsType        cpmd = det;
                PaymentMethodDetail cmd  = det;
                if (cmd.IsCCProcessingID == true)
                {
                    isIDFilled = cpmd.Value != null;
                    CCPIDDet   = (TDetialsType)detailsView.Cache.CreateCopy(cpmd);
                }
                else
                {
                    isOtherDetsFilled = cpmd.Value != null || isOtherDetsFilled;
                }
            }
            if (CCPIDDet == null)
            {
                //something's very wrong
                throw new PXException(Messages.NOCCPID, customerPaymentMethodView.Current.Descr);
            }
            if (isIDFilled && isOtherDetsFilled)
            {
                return;
            }

            if ((isIDFilled || isOtherDetsFilled) && !isHF || isIDFilled && !isOtherDetsFilled)
            {
                CCCustomerInformationManager cim =
                    new CCCustomerInformationManager(customerPaymentMethodView.Current.CCProcessingCenterID,
                                                     CCProcessingFeature.ProfileManagement)
                {
                    CustomerID           = customerPaymentMethodView.Current.BAccountID,
                    PMInstanceID         = customerPaymentMethodView.Current.PMInstanceID,
                    CallerGraph          = graph,
                    String2DateConverter =
                        s => CustomerPaymentMethodMaint.ParseExpiryDate(graph, customerPaymentMethodView.Current, s),
                };

                var    currentCustomerPaymentMethod = customerPaymentMethodView.Current;
                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);
                        }
                    }
                }


                if (isOtherDetsFilled)
                {
                    string newPMId = cim.CreatePaymentProfile();
                    CCPIDDet.Value = newPMId;
                    CCPIDDet       = detailsView.Update(CCPIDDet);
                }
                CreditCardData cardData = cim.GetPaymentProfile();
                if (cardData != null && !string.IsNullOrEmpty(cardData.PaymentProfileID))
                {
                    foreach (PXResult <TDetialsType, PaymentMethodDetail> det in detailsView.Select())
                    {
                        TDetialsType        cpmd = det;
                        PaymentMethodDetail pmd  = (PaymentMethodDetail)det;
                        if (cpmd.DetailID == CCPIDDet.DetailID)
                        {
                            continue;
                        }
                        string detailValue = null;
                        if (pmd.IsCCProcessingID != true && pmd.IsIdentifier == true && !string.IsNullOrEmpty(cardData.CardNumber))
                        {
                            detailValue = cardData.CardNumber;
                        }
                        TDetialsType newcpmd = (TDetialsType)detailsView.Cache.CreateCopy(cpmd);
                        newcpmd.Value = detailValue;
                        detailsView.Update(newcpmd);
                    }
                    if (cardData.CardExpirationDate != null)
                    {
                        TPaymentMethodType cpm = (TPaymentMethodType)customerPaymentMethodView.Cache.CreateCopy(customerPaymentMethodView.Current);
                        customerPaymentMethodView.Cache.SetValueExt <CustomerPaymentMethod.expirationDate>(cpm, cardData.CardExpirationDate);
                        customerPaymentMethodView.Update(cpm);
                    }
                }
                else
                {
                    throw new PXException(Messages.CouldntGetPMIDetails, customerPaymentMethodView.Current.Descr);
                }
            }
        }
Example #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);
                }
            }
        }