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();
        }
Exemple #2
0
        private void ClearWorkTypes(RUTROT rutrot)
        {
            foreach (Tran line in Transactions.Select())
            {
                TranExt        lineRR   = RUTROTHelper.GetExtensionNullable <Tran, TranExt>(line);
                RUTROTWorkType workType = PXSelect <RUTROTWorkType, Where <RUTROTWorkType.workTypeID, Equal <Required <RUTROTWorkType.workTypeID> > > > .Select(this.Base, lineRR.RUTROTWorkTypeID);

                if (workType?.RUTROTType != rutrot.RUTROTType)
                {
                    lineRR.RUTROTWorkTypeID = null;
                    Transactions.Update(line);
                }
            }
        }
        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);
            }
        }
        private void SetNoDropshipAttribute(bool value)
        {
            string stringValue = value ? "1" : "0";

            foreach (CSAnswers attr in _answers.Select())
            {
                if (attr.AttributeID == "NODROPSHIP")
                {
                    if (attr.Value != stringValue)
                    {
                        attr.Value = stringValue;
                        _answers.Update(attr);
                        _answers.View.RequestRefresh();
                    }
                    break;
                }
            }
        }
        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);
                }
            }
        }
        public static void CreatePaymentMethodHF <TPaymentMethodType>(PXGraph graph, PXSelectBase <TPaymentMethodType> customerPaymentMethodView, TPaymentMethodType currentCutomerPaymenMethod)
            where TPaymentMethodType : CustomerPaymentMethod, new()
        {
            if (graph == null || customerPaymentMethodView == null || currentCutomerPaymenMethod == null)
            {
                return;
            }
            CCCustomerInformationManager cim = new CCCustomerInformationManager(currentCutomerPaymenMethod.CCProcessingCenterID, CCProcessingFeature.HostedForm,
                                                                                new ProcessingContext()
            {
                aCustomerID = currentCutomerPaymenMethod.BAccountID, aPMInstanceID = currentCutomerPaymenMethod.PMInstanceID, callerGraph = graph
            });

            if (currentCutomerPaymenMethod.CustomerCCPID == null)
            {
                string             id  = cim.CreateCustomer();
                TPaymentMethodType cpm = (TPaymentMethodType)customerPaymentMethodView.Cache.CreateCopy(currentCutomerPaymenMethod);
                cpm.CustomerCCPID = id;
                customerPaymentMethodView.Update(cpm);
            }
            cim.CreatePaymentMethodHostedForm();
        }
        public virtual void UnlockInventory(bool deleteLock = true)
        {
            _inPIStatusItem.Cache.Clear();
            foreach (PXResult <INPIStatusItem> it in PXSelect <INPIStatusItem,
                                                               Where <INPIStatusItem.pIID, Equal <Required <INPIStatusItem.pIID> > > > .Select(_graph, _piId))
            {
                if (deleteLock)
                {
                    _inPIStatusItem.Delete(it);
                }
                else
                {
                    INPIStatusItem upd = PXCache <INPIStatusItem> .CreateCopy(it);

                    upd.Active = false;
                    _inPIStatusItem.Update(upd);
                }
            }

            _inPIStatusLocation.Cache.Clear();
            foreach (PXResult <INPIStatusLoc> it in PXSelect <INPIStatusLoc,
                                                              Where <INPIStatusLoc.pIID, Equal <Required <INPIStatusLoc.pIID> > > > .Select(_graph, _piId))
            {
                if (deleteLock)
                {
                    _inPIStatusLocation.Delete(it);
                }
                else
                {
                    INPIStatusLoc upd = PXCache <INPIStatusLoc> .CreateCopy(it);

                    upd.Active = false;
                    _inPIStatusLocation.Update(upd);
                }
            }
        }
Exemple #8
0
        public static void InsertCurrentService <ServiceDetType>(
            PXSelectBase <InventoryItem> inventoryView,
            PXSelectBase <ServiceDetType> serviceDetView)
            where ServiceDetType : class, IBqlTable, IFSSODetBase, new()
        {
            if (inventoryView.Current == null)
            {
                return;
            }

            InventoryItem inventoryItemRow = SharedFunctions.GetInventoryItemRow(serviceDetView.Cache.Graph, inventoryView.Current.InventoryID);

            SharedFunctions.ShowServiceOrderNote(PXDBOperation.Insert, serviceDetView.View, inventoryItemRow);
            serviceDetView.ClearDialog();

            var newRow = new ServiceDetType();

            newRow.LineType = ID.LineType_All.SERVICE;

            newRow = serviceDetView.Insert(newRow);

            serviceDetView.SetValueExt <FSSODetService.inventoryID>(newRow, inventoryItemRow.InventoryID);
            serviceDetView.Update(newRow);
        }
        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);
                }
            }
        }
        public static void SyncPaymentMethodsHF <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,
                                                                                new ProcessingContext()
            {
                aCustomerID = currentCustomerPaymentMethod.BAccountID, aPMInstanceID = currentCustomerPaymentMethod.PMInstanceID, callerGraph = graph
            });
            int    attempt = 1;
            string newPMID = string.Empty;

            //AuthorizeNet sometimes failes to process new card in time when using Hosted Form Method
            while ((attempt <= (cim.Context.processingCenter.SyncRetryAttemptsNo ?? 0) + 1) && string.IsNullOrEmpty(newPMID))
            {
                Thread.Sleep(cim.Context.processingCenter.SyncRetryDelayMs ?? 0);
                SyncPMResponse     syncResponse          = cim.SynchronizePaymentMethods();
                TPaymentMethodType customerPaymentMethod = customerPaymentMethodView.Current;
                if (syncResponse.PMList != null && syncResponse.PMList.Count > 0)
                {
                    var sortedPMDict = new SortedDictionary <string, Dictionary <string, string> >(syncResponse.PMList, new strComparer());
                    PXResultset <CustomerPaymentMethodDetail> otherCards = GetAllCustomersCardsInProcCenter(graph, customerPaymentMethod.BAccountID, currentCustomerPaymentMethod.CCProcessingCenterID);
                    foreach (string pmID in sortedPMDict.Keys)
                    {
                        bool detailExists = false;
                        foreach (CustomerPaymentMethodDetail detail in otherCards)
                        {
                            if (detail.Value == pmID)
                            {
                                detailExists = true;
                                break;
                            }
                        }
                        if (!detailExists)
                        {
                            newPMID = pmID;
                            break;
                        }
                    }
                    if (!string.IsNullOrEmpty(newPMID))
                    {
                        //Authorize.Net does not return unmasked dates when all customer cards are requested, only when a single card is requested by id
                        Dictionary <string, string> resultDict = new Dictionary <string, string>();
                        resultDict = sortedPMDict[newPMID];
                        string expirationDate = String.Empty;
                        if (CCProcessingUtils.isFeatureSupported(graph, customerPaymentMethod.PMInstanceID, CCProcessingFeature.UnmaskedExpirationDate) &&
                            sortedPMDict[newPMID].TryGetValue(((ICreditCardDataReader)cim._processingGraph).Key_CardExpiryDate, out expirationDate))
                        {
                            DateTime?expDate = CustomerPaymentMethodMaint.ParseExpiryDate(graph, customerPaymentMethod, expirationDate);
                            if (expDate == null)
                            {
                                string CCPID = resultDict.Where(kvp => kvp.Value == newPMID).First().Key;
                                foreach (TDetialsType det in detailsView.Select())
                                {
                                    if (det.DetailID == CCPID)
                                    {
                                        det.Value = newPMID;
                                        detailsView.Update(det);
                                    }
                                }
                                SyncPMResponse customerPaymentProfile = cim.GetPaymentMethod();
                                if (customerPaymentProfile.PMList != null && syncResponse.PMList.Count > 0)
                                {
                                    resultDict = customerPaymentProfile.PMList.FirstOrDefault().Value;
                                }
                            }
                        }
                        foreach (TDetialsType det in detailsView.Select())
                        {
                            if (resultDict.ContainsKey(det.DetailID))
                            {
                                det.Value = resultDict[det.DetailID];
                                detailsView.Update(det);
                            }
                        }
                    }
                }
                attempt++;
            }
            if (string.IsNullOrEmpty(newPMID))
            {
                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 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);
            }
        }