Beispiel #1
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);
                }
            }
        }
Beispiel #2
0
        public static void GetOrCreatePaymentProfile(PXGraph graph
                                                     , ICustomerPaymentMethodAdapter customerPaymentMethodAdapter
                                                     , ICustomerPaymentMethodDetailAdapter customerPaymentMethodDetailAdapter)
        {
            bool isHF         = CCProcessingHelper.IsHFPaymentMethod(graph, customerPaymentMethodAdapter.Current.PMInstanceID);
            bool isConverting = customerPaymentMethodAdapter.Current.Selected == true;

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

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

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

                var currentCustomerPaymentMethod = customerPaymentMethodAdapter.Current;
                cim.String2DateConverter = s => CustomerPaymentMethodMaint.ParseExpiryDate(graph, customerPaymentMethodAdapter.Current, s);
                string id = currentCustomerPaymentMethod.CustomerCCPID;
                if (currentCustomerPaymentMethod.CustomerCCPID == null)
                {
                    id = cim.CreateCustomerProfile();
                    CustomerPaymentMethod cpm = customerPaymentMethodAdapter.Current.CreateCopy(customerPaymentMethodAdapter.Cache);
                    cpm.CustomerCCPID = id;
                    customerPaymentMethodAdapter.Cache.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();
                            CustomerPaymentMethod cpm = customerPaymentMethodAdapter.Current.CreateCopy(customerPaymentMethodAdapter.Cache);
                            cpm.CustomerCCPID = id;
                            customerPaymentMethodAdapter.Cache.Update(cpm);
                        }
                    }
                }

                if (isOtherDetsFilled)
                {
                    string newPMId = cim.CreatePaymentProfile();
                    CCPIDDet.Value = newPMId;
                    CCPIDDet       = customerPaymentMethodDetailAdapter.Cache.Update(CCPIDDet) as CustomerPaymentMethodDetail;
                }
                CreditCardData cardData = cim.GetPaymentProfile();
                if (cardData != null && !string.IsNullOrEmpty(cardData.PaymentProfileID))
                {
                    foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> det in customerPaymentMethodDetailAdapter.Select())
                    {
                        CustomerPaymentMethodDetail 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;
                        }
                        CustomerPaymentMethodDetail newcpmd = (CustomerPaymentMethodDetail)cpmd.CreateCopy(customerPaymentMethodDetailAdapter.Cache);
                        newcpmd.Value = detailValue;
                        customerPaymentMethodDetailAdapter.Cache.Update(newcpmd);
                    }
                    if (cardData.CardExpirationDate != null)
                    {
                        CustomerPaymentMethod cpm = customerPaymentMethodAdapter.Current.CreateCopy(customerPaymentMethodAdapter.Cache);
                        customerPaymentMethodAdapter.Cache.SetValueExt <CustomerPaymentMethod.expirationDate>(cpm, cardData.CardExpirationDate);
                        customerPaymentMethodAdapter.Cache.Update(cpm);
                    }
                }
                else
                {
                    throw new PXException(Messages.CouldntGetPMIDetails, customerPaymentMethodAdapter.Current.Descr);
                }
            }
        }