Ejemplo n.º 1
0
        public static IEnumerable GetPMdetails(PXGraph graph, int?PMInstanceID, bool CCPIDCondition, bool OtherDetailsCondition)
        {
            var items = PXSelectJoin <CustomerPaymentMethodDetail, InnerJoin <PaymentMethodDetail, On <PaymentMethodDetail.paymentMethodID, Equal <CustomerPaymentMethodDetail.paymentMethodID>,
                                                                                                       And <PaymentMethodDetail.detailID, Equal <CustomerPaymentMethodDetail.detailID>,
                                                                                                            And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards> > > > >,
                                      Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(graph, PMInstanceID);

            if (PMInstanceID > 0)
            {
                PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> stored = HasSavedPaymentProfile(items);
                if (stored != null)
                {
                    yield return(stored);

                    yield break;
                }
            }

            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> item in items)
            {
                PaymentMethodDetail pmd = item;
                bool isCCPid            = pmd.IsCCProcessingID == true;
                if (CCPIDCondition && isCCPid ||
                    OtherDetailsCondition && !isCCPid)
                {
                    yield return(item);
                }
            }
        }
 private static void ImportDefaults(PaymentMethodDetail aData, ACHAttributes.AttributeName aAttr)
 {
     aData.DetailID    = ACHAttributes.GetID(aAttr);
     aData.EntryMask   = ACHAttributes.GetMask(aAttr);
     aData.ValidRegexp = ACHAttributes.GetValidationRegexp(aAttr);
     aData.IsRequired  = true;
 }
        public static void SyncDeletePMI(PXGraph graph, PXSelectBase <CustomerPaymentMethod> customerPaymentMethodView, PXSelectBase <CustomerPaymentMethodDetail> detailsView)
        {
            IEnumerator cpmEnumerator = customerPaymentMethodView.Cache.Deleted.GetEnumerator();

            if (cpmEnumerator.MoveNext())
            {
                CustomerPaymentMethod current          = (CustomerPaymentMethod)cpmEnumerator.Current;
                CCProcessingCenter    processingCenter = CCProcessingUtils.getProcessingCenter(graph, current.CCProcessingCenterID);
                if (!string.IsNullOrEmpty(current.CCProcessingCenterID) && processingCenter.SyncronizeDeletion == true)
                {
                    CCCustomerInformationManager cim = new CCCustomerInformationManager(current.CCProcessingCenterID, CCProcessingFeature.Tokenization,
                                                                                        new ProcessingContext()
                    {
                        aCustomerID = current.BAccountID, aPMInstanceID = current.PMInstanceID
                    });
                    CustomerPaymentMethodDetail ccpidCPMDet = null;
                    PaymentMethodDetail         ccpidPMDet  = PXSelect <PaymentMethodDetail,
                                                                        Where <PaymentMethodDetail.paymentMethodID, Equal <Optional <CustomerPaymentMethod.paymentMethodID> >,
                                                                               And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>, And <PaymentMethodDetail.isCCProcessingID, Equal <True> > > > > .Select(graph, current.PaymentMethodID);

                    foreach (CustomerPaymentMethodDetail deletedDet in detailsView.Cache.Deleted)
                    {
                        if (deletedDet.DetailID == ccpidPMDet.DetailID)
                        {
                            ccpidCPMDet = deletedDet;
                            break;
                        }
                    }
                    if (ccpidCPMDet != null && !string.IsNullOrEmpty(ccpidCPMDet.Value))
                    {
                        cim.DeletePaymentMethod();
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static bool IsCCPIDFilled(PXGraph graph, int?PMInstanceID)
        {
            if (PMInstanceID == null || PMInstanceID.Value < 0)
            {
                return(false);
            }

            CustomerPaymentMethod cpm = PXSelect <CustomerPaymentMethod, Where <CustomerPaymentMethod.pMInstanceID,
                                                                                Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(graph, PMInstanceID);

            if (cpm == null)
            {
                return(false);
            }

            PXResultset <PaymentMethodDetail> paymentMethodDetail = PXSelectJoin <PaymentMethodDetail, LeftJoin <CustomerPaymentMethodDetail,
                                                                                                                 On <CustomerPaymentMethodDetail.paymentMethodID, Equal <PaymentMethodDetail.paymentMethodID>,
                                                                                                                     And <CustomerPaymentMethodDetail.detailID, Equal <PaymentMethodDetail.detailID>,
                                                                                                                          And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>,
                                                                                                                               And <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > > > >,
                                                                                  Where <PaymentMethodDetail.isCCProcessingID, Equal <True>,
                                                                                         And <PaymentMethodDetail.paymentMethodID, Equal <Required <PaymentMethodDetail.paymentMethodID> > > > > .Select(graph, PMInstanceID, cpm.PaymentMethodID);

            PaymentMethodDetail         pmIDDetail  = paymentMethodDetail.Count > 0 ? paymentMethodDetail[0].GetItem <PaymentMethodDetail>() : null;
            CustomerPaymentMethodDetail ccpIDDetail = paymentMethodDetail.Count > 0 ? paymentMethodDetail[0].GetItem <CustomerPaymentMethodDetail>() : null;

            if (IsTokenizedPaymentMethod(graph, PMInstanceID) && pmIDDetail == null)
            {
                throw new PXException(Messages.PaymentMethodNotConfigured);
            }
            return(ccpIDDetail != null && !string.IsNullOrEmpty(ccpIDDetail.Value));
        }
        protected virtual void fillACHforARDefaults()
        {
            PaymentMethodDetail det = this.addDefaultsToDetails(ACHAttributes.AttributeName.BeneficiaryAccoutNo, Messages.BeneficiaryAccoutNo, PaymentMethodDetailUsage.UseForARCards);

            det.DisplayMask  = ACHAttributes.MaskDefaults.DefaultIdentifier;
            det.IsIdentifier = true;
            this.addDefaultsToDetails(ACHAttributes.AttributeName.BeneficiaryName, Messages.BeneficiaryName, PaymentMethodDetailUsage.UseForARCards);
            this.addDefaultsToDetails(ACHAttributes.AttributeName.BankRoutingNumber, Messages.BankRoutingNumber, PaymentMethodDetailUsage.UseForARCards);
            this.addDefaultsToDetails(ACHAttributes.AttributeName.BankName, Messages.BankName, PaymentMethodDetailUsage.UseForARCards);
        }
        private PaymentMethodDetail addDefaultsToDetails(ACHAttributes.AttributeName aAttr, string aDescr, string useFor)
        {
            PaymentMethodDetail det = new PaymentMethodDetail();

            ImportDefaults(det, aAttr);
            det.Descr  = aDescr;
            det.UseFor = useFor;
            det        = (PaymentMethodDetail)Base.Details.Cache.Insert(det);
            return(det);
        }
Ejemplo n.º 7
0
        public PXResultset <CustomerPaymentMethodDetail, PaymentMethodDetail> Select(params object[] argumetns)
        {
            PXResultset <T> resultSet = dataView.Select(argumetns);
            PXResultset <CustomerPaymentMethodDetail, PaymentMethodDetail> retResultSet = new PXResultset <CustomerPaymentMethodDetail, PaymentMethodDetail>();

            foreach (PXResult <T, PaymentMethodDetail> result in resultSet)
            {
                CustomerPaymentMethodDetail cpmd = result;
                PaymentMethodDetail         pmd  = (PaymentMethodDetail)result;
                retResultSet.Add(new PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail>(cpmd, pmd));
            }
            return(retResultSet);
        }
Ejemplo n.º 8
0
        protected virtual void RecalcRow(CCTransactionsHistoryFilter aRow)
        {
            if (!string.IsNullOrEmpty(aRow.PaymentMethodID))
            {
                PaymentMethodDetail def = PXSelect <PaymentMethodDetail, Where <PaymentMethodDetail.paymentMethodID,
                                                                                Equal <Optional <CCTransactionsHistoryFilter.paymentMethodID> >,
                                                                                And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>,
                                                                                     And <PaymentMethodDetail.isIdentifier, Equal <True> > > > > .Select(this, aRow.PaymentMethodID);

                if (def != null)
                {
                    aRow.MaskedCardNumber = CustomerPaymentMethodMaint.FormatDescription(aRow.PaymentMethodID, CustomerPaymentMethodMaint.IDObfuscator.RestoreToMasked(aRow.PartialCardNumber, def.DisplayMask, SqlDialect.WildcardAnySingle, false));
                }
            }
        }
Ejemplo n.º 9
0
        private static PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> HasSavedPaymentProfile(PXResultset <CustomerPaymentMethodDetail> items)
        {
            PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> ret = null;

            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> item in items)
            {
                CustomerPaymentMethodDetail det = item;
                PaymentMethodDetail         pmd = item;
                if (pmd.IsCCProcessingID == true && !string.IsNullOrEmpty(det.Value))
                {
                    ret = item;
                    break;
                }
            }
            return(ret);
        }
Ejemplo n.º 10
0
 public static IEnumerable GetPMdetails(PXGraph graph, int?PMInstanceID, bool CCPIDCondition, bool OtherDetailsCondition)
 {
     foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> res in PXSelectJoin <CustomerPaymentMethodDetail, InnerJoin <PaymentMethodDetail, On <PaymentMethodDetail.paymentMethodID, Equal <CustomerPaymentMethodDetail.paymentMethodID>,
                                                                                                                                                                And <PaymentMethodDetail.detailID, Equal <CustomerPaymentMethodDetail.detailID>,
                                                                                                                                                                     And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards> > > > >,
                                                                                               Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethod.pMInstanceID> > > > .Select(graph, PMInstanceID))
     {
         PaymentMethodDetail pmd = res;
         bool isCCPid            = pmd.IsCCProcessingID == true;
         if (CCPIDCondition && isCCPid ||
             OtherDetailsCondition && !isCCPid)
         {
             yield return(res);
         }
     }
 }
        public static void GetPaymentProfile(PXGraph graph, PXSelectBase <CustomerPaymentMethod> customerPaymentMethodView, PXSelectBase <CustomerPaymentMethodDetail> detailsView)
        {
            string CCPID = null;

            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> det in detailsView.Select())
            {
                CustomerPaymentMethodDetail cpmd = (CustomerPaymentMethodDetail)det;
                PaymentMethodDetail         pmd  = (PaymentMethodDetail)det;
                if (pmd.IsCCProcessingID == true)
                {
                    CCPID = cpmd.Value;
                    break;
                }
            }
            if (String.IsNullOrEmpty(CCPID))
            {
                throw new PXException(Messages.CreditCardTokenIDNotFound);
            }
            CCCustomerInformationManager cim = new CCCustomerInformationManager(customerPaymentMethodView.Current.CCProcessingCenterID, CCProcessingFeature.ProfileManagement)
            {
                CustomerID   = customerPaymentMethodView.Current.BAccountID,
                PMInstanceID = customerPaymentMethodView.Current.PMInstanceID,
                CallerGraph  = graph
            };
            CreditCardData cardData = cim.GetPaymentProfile();

            if (cardData == null)
            {
                throw new PXException(Messages.CreditCardNotFoundInProcCenter, CCPID, customerPaymentMethodView.Current.CCProcessingCenterID);
            }
            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> det in detailsView.Select())
            {
                CustomerPaymentMethodDetail cpmd = (CustomerPaymentMethodDetail)det;
                PaymentMethodDetail         pmd  = (PaymentMethodDetail)det;
                if (pmd.IsCCProcessingID != true && pmd.IsIdentifier == true && !string.IsNullOrEmpty(cardData.CardNumber))
                {
                    cpmd.Value = cardData.CardNumber;
                    detailsView.Update(cpmd);
                }
            }
            if (cardData.CardExpirationDate != null)
            {
                CustomerPaymentMethod cpm = (CustomerPaymentMethod)customerPaymentMethodView.Cache.CreateCopy(customerPaymentMethodView.Current);
                customerPaymentMethodView.Cache.SetValueExt <CustomerPaymentMethod.expirationDate>(cpm, cardData.CardExpirationDate);
                customerPaymentMethodView.Update(cpm);
            }
        }
        public static void SyncExistingPMI(PXGraph graph, PXSelectBase <CustomerPaymentMethod> customerPaymentMethodView, PXSelectBase <CustomerPaymentMethodDetail> detailsView)
        {
            string CCPID = null;

            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> det in detailsView.Select())
            {
                CustomerPaymentMethodDetail cpmd = (CustomerPaymentMethodDetail)det;
                PaymentMethodDetail         pmd  = (PaymentMethodDetail)det;
                if (pmd.IsCCProcessingID == true)
                {
                    CCPID = cpmd.Value;
                    break;
                }
            }
            if (String.IsNullOrEmpty(CCPID))
            {
                throw new PXException(Messages.CreditCardTokenIDNotFound);
            }
            CCCustomerInformationManager cim = new CCCustomerInformationManager(customerPaymentMethodView.Current.CCProcessingCenterID, CCProcessingFeature.Tokenization,
                                                                                new ProcessingContext()
            {
                aCustomerID   = customerPaymentMethodView.Current.BAccountID,
                aPMInstanceID = customerPaymentMethodView.Current.PMInstanceID,
                callerGraph   = graph
            });
            SyncPMResponse response = cim.GetPaymentMethod();

            if (response.PMList.Count == 0)
            {
                throw new PXException(Messages.CreditCardNotFoundInProcCenter, CCPID, customerPaymentMethodView.Current.CCProcessingCenterID);
            }
            foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> det in detailsView.Select())
            {
                CustomerPaymentMethodDetail cpmd = (CustomerPaymentMethodDetail)det;
                PaymentMethodDetail         pmd  = (PaymentMethodDetail)det;
                if (pmd.IsCCProcessingID != true && response.PMList.First().Value.ContainsKey(cpmd.DetailID))
                {
                    cpmd.Value = response.PMList.First().Value[cpmd.DetailID];
                    detailsView.Update(cpmd);
                }
            }
        }
Ejemplo n.º 13
0
        public static void DeletePaymentProfile(PXGraph graph, ICCPaymentProfileAdapter payment, ICCPaymentProfileDetailAdapter paymentDetail)
        {
            IEnumerator cpmEnumerator = payment.Cache.Deleted.GetEnumerator();

            if (cpmEnumerator.MoveNext())
            {
                ICCPaymentProfile            current          = (ICCPaymentProfile)cpmEnumerator.Current;
                ProcessingCardsPluginFactory pluginFactory    = GetProcessingCardsPluginFactory(current.CCProcessingCenterID);
                CCProcessingCenter           processingCenter = pluginFactory.GetProcessingCenter();
                if (!string.IsNullOrEmpty(current.CCProcessingCenterID) && processingCenter.SyncronizeDeletion == true)
                {
                    CCCustomerInformationManager  cim             = GetCustomerInformationManager(pluginFactory);
                    CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(new CCProcessingContext()
                    {
                        processingCenter = pluginFactory.GetProcessingCenter(),
                        aCustomerID      = current.BAccountID,
                        aPMInstanceID    = current.PMInstanceID,
                        callerGraph      = pluginFactory.GetPaymentProcessingRepository().Graph
                    });
                    cim.SetReadersProvider(readersProvider);
                    ICCPaymentProfileDetail ccpidCPMDet = null;
                    PaymentMethodDetail     ccpidPMDet  = PXSelect <PaymentMethodDetail,
                                                                    Where <PaymentMethodDetail.paymentMethodID, Equal <Optional <CustomerPaymentMethod.paymentMethodID> >,
                                                                           And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>, And <PaymentMethodDetail.isCCProcessingID, Equal <True> > > > > .Select(graph, current.PaymentMethodID);

                    foreach (ICCPaymentProfileDetail deletedDet in paymentDetail.Cache.Deleted)
                    {
                        if (deletedDet.DetailID == ccpidPMDet.DetailID)
                        {
                            ccpidCPMDet = deletedDet;
                            break;
                        }
                    }
                    if (ccpidCPMDet != null && !string.IsNullOrEmpty(ccpidCPMDet.Value))
                    {
                        cim.DeletePaymentProfile();
                    }
                }
            }
        }
Ejemplo n.º 14
0
        void ICreditCardDataReader.ReadData(Dictionary <string, string> aData)
        {
            PXResultset <CustomerPaymentMethodDetail> PMDselect = null;

            PMDselect = PXSelectJoin <CustomerPaymentMethodDetail,
                                      InnerJoin <PaymentMethodDetail, On <CustomerPaymentMethodDetail.detailID, Equal <PaymentMethodDetail.detailID>,
                                                                          And <CustomerPaymentMethodDetail.paymentMethodID, Equal <PaymentMethodDetail.paymentMethodID> > > >,
                                      Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethodDetail.pMInstanceID> > > >
                        .Select(_graph, _pminstanceID);

            if (PMDselect != null)
            {
                foreach (PXResult <CustomerPaymentMethodDetail, PaymentMethodDetail> dets in PMDselect)
                {
                    PaymentMethodDetail         pmd  = dets;
                    CustomerPaymentMethodDetail cpmd = dets;
                    if (pmd.IsCCProcessingID == true)
                    {
                        aData[CreditCardAttributes.CCPID] = cpmd.Value;
                    }
                    if (pmd.IsIdentifier == true)
                    {
                        aData[CreditCardAttributes.CardNumber] = cpmd.Value;
                    }
                    if (pmd.IsExpirationDate == true)
                    {
                        aData[CreditCardAttributes.ExpirationDate] = cpmd.Value;
                    }
                    if (pmd.IsCVV == true)
                    {
                        aData[CreditCardAttributes.CVV] = cpmd.Value;
                    }
                    if (pmd.IsOwnerName == true)
                    {
                        aData[CreditCardAttributes.NameOnCard] = cpmd.Value;
                    }
                }
            }
        }
Ejemplo n.º 15
0
        private void GetInternalData(string paymentMethodID)
        {
            PaymentMethodDetail paymentMethodDetail = PXSelectReadonly <PaymentMethodDetail,
                                                                        Where <PaymentMethodDetail.paymentMethodID, Equal <Required <PaymentMethodDetail.paymentMethodID> >,
                                                                               And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>,
                                                                                    And <PaymentMethodDetail.isIdentifier, Equal <True> > > > > .Select(this, paymentMethodID);

            if (paymentMethodDetail != null)
            {
                CardNumber_DetailID = paymentMethodDetail.DetailID;
                //CardNumber_IsEncrypted = (paymentMethodDetail.IsEncrypted == true);
            }

            paymentMethodDetail = PXSelectReadonly <PaymentMethodDetail,
                                                    Where <PaymentMethodDetail.paymentMethodID, Equal <Required <PaymentMethodDetail.paymentMethodID> >,
                                                           And <PaymentMethodDetail.useFor, Equal <PaymentMethodDetailUsage.useForARCards>,
                                                                And <PaymentMethodDetail.isOwnerName, Equal <True> > > > > .Select(this, paymentMethodID);

            if (paymentMethodDetail != null)
            {
                NameOnCard_DetailID = paymentMethodDetail.DetailID;
                //NameOnCard_IsEncrypted = (paymentMethodDetail.IsEncrypted == true);
            }
        }
        public static void GetNewPaymentProfiles <TPaymentMethodType, TDetialsType>(PXGraph graph,
                                                                                    PXSelectBase <TPaymentMethodType> customerPaymentMethodView,
                                                                                    PXSelectBase <TDetialsType> detailsView,
                                                                                    TPaymentMethodType currentCustomerPaymentMethod)
            where TPaymentMethodType : CustomerPaymentMethod, new()
            where TDetialsType : CustomerPaymentMethodDetail, new()
        {
            if (graph == null || customerPaymentMethodView == null || detailsView == null || currentCustomerPaymentMethod == null)
            {
                return;
            }
            CCCustomerInformationManager cim = new CCCustomerInformationManager(currentCustomerPaymentMethod.CCProcessingCenterID, CCProcessingFeature.HostedForm)
            {
                CustomerID   = currentCustomerPaymentMethod.BAccountID,
                PMInstanceID = currentCustomerPaymentMethod.PMInstanceID,
                CallerGraph  = graph
            };

            int            attempt = 1;
            CreditCardData newCard = null;

            //AuthorizeNet sometimes failes to process new card in time when using Hosted Form Method
            while ((attempt <= (cim._context.processingCenter.SyncRetryAttemptsNo ?? 0) + 1) && newCard == null)
            {
                Thread.Sleep(cim._context.processingCenter.SyncRetryDelayMs ?? 0);
                List <CreditCardData> newCards = null;

                try
                {
                    newCards = cim.GetMissingPaymentProfiles().ToList();
                }
                catch (Exception e)
                {
                    throw new PXException(e.Message + ". " + Messages.FailedToSyncCC);
                }

                TPaymentMethodType customerPaymentMethod = customerPaymentMethodView.Current;

                if (newCards != null && newCards.Count > 1)
                {
                    newCards.Sort(new InterfaceExtensions.CreditCardDataComparer());
                    newCard = newCards[0];
                }
                else if (newCards != null && newCards.Count == 1)
                {
                    newCard = newCards[0];
                }

                if (newCard != null)
                {
                    foreach (PXResult <TDetialsType, PaymentMethodDetail> det in detailsView.Select())
                    {
                        TDetialsType        cpmd = det;
                        PaymentMethodDetail pmd  = (PaymentMethodDetail)det;
                        if (pmd.IsCCProcessingID == true)
                        {
                            cpmd.Value = newCard.PaymentProfileID;
                            detailsView.Update(cpmd);
                        }
                        else if (pmd.IsIdentifier == true)
                        {
                            cpmd.Value = newCard.CardNumber;
                            detailsView.Update(cpmd);
                        }
                    }
                    //getting unmasked expiration date
                    newCard = cim.GetPaymentProfile();
                    if (newCard.CardExpirationDate != null)
                    {
                        customerPaymentMethodView.Cache.SetValueExt <CustomerPaymentMethod.expirationDate>(customerPaymentMethod, newCard.CardExpirationDate);
                        customerPaymentMethodView.Update(customerPaymentMethod);
                    }
                }
                attempt++;
            }
            if (newCard == null)
            {
                throw new PXException(Messages.FailedToSyncCC);
            }
        }
        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);
                }
            }
        }
        public static void SyncNewPMI <TPaymentMethodType, TDetialsType>(PXGraph graph, PXSelectBase <TPaymentMethodType> customerPaymentMethodView, PXSelectBase <TDetialsType> detailsView)
            where TPaymentMethodType : CustomerPaymentMethod, new()
            where TDetialsType : CustomerPaymentMethodDetail, new()
        {
            bool isHF         = CCProcessingUtils.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.Tokenization,
                                                                                    new ProcessingContext()
                {
                    aCustomerID   = customerPaymentMethodView.Current.BAccountID,
                    aPMInstanceID = customerPaymentMethodView.Current.PMInstanceID,
                    callerGraph   = graph
                });
                if (customerPaymentMethodView.Current.CustomerCCPID == null)
                {
                    string             id  = cim.CreateCustomer();
                    TPaymentMethodType cpm = (TPaymentMethodType)customerPaymentMethodView.Cache.CreateCopy(customerPaymentMethodView.Current);
                    cpm.CustomerCCPID = id;
                    customerPaymentMethodView.Update(cpm);
                }
                if (isOtherDetsFilled)
                {
                    string newPMId = cim.CreatePaymentMethod();
                    CCPIDDet.Value = newPMId;
                    CCPIDDet       = detailsView.Update(CCPIDDet);
                }
                SyncPMResponse syncResponse = cim.GetPaymentMethod();
                if (syncResponse.PMList.ContainsKey(CCPIDDet.Value))
                {
                    foreach (PXResult <TDetialsType, PaymentMethodDetail> det in detailsView.Select())
                    {
                        TDetialsType cpmd = det;
                        if (cpmd.DetailID == CCPIDDet.DetailID)
                        {
                            continue;
                        }
                        string detailValue;
                        if (!syncResponse.PMList[CCPIDDet.Value].TryGetValue(cpmd.DetailID, out detailValue))
                        {
                            detailValue = null;
                        }
                        TDetialsType newcpmd = (TDetialsType)detailsView.Cache.CreateCopy(cpmd);
                        newcpmd.Value = detailValue;
                        detailsView.Update(newcpmd);
                    }
                }
                else
                {
                    throw new PXException(Messages.CouldntGetPMIDetails, customerPaymentMethodView.Current.Descr);
                }
            }
        }