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);
            }
        }
示例#2
0
        public static void GetNewPaymentProfiles(PXGraph graph,
                                                 ICCPaymentProfileAdapter payment,
                                                 ICCPaymentProfileDetailAdapter paymentDetail
                                                 )
        {
            if (graph == null || payment == null || paymentDetail == null)
            {
                return;
            }
            ICCPaymentProfile             currentPaymentProfile = payment.Current;
            ProcessingCardsPluginFactory  pluginFactory         = GetProcessingCardsPluginFactory(currentPaymentProfile.CCProcessingCenterID);
            CCCustomerInformationManager  cim             = GetCustomerInformationManager(pluginFactory);
            CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(new CCProcessingContext()
            {
                processingCenter = pluginFactory.GetProcessingCenter(),
                aCustomerID      = currentPaymentProfile.BAccountID,
                aPMInstanceID    = currentPaymentProfile.PMInstanceID,
                callerGraph      = graph
            });

            cim.SetReadersProvider(readersProvider);

            int            attempt = 1;
            CreditCardData newCard = null;
            //AuthorizeNet sometimes failes to process new card in time when using Hosted Form Method
            CCProcessingCenter procCenter = pluginFactory.GetProcessingCenter();

            while ((attempt <= (procCenter.SyncRetryAttemptsNo ?? 0) + 1) && newCard == null)
            {
                Thread.Sleep(procCenter.SyncRetryDelayMs ?? 0);
                List <CreditCardData> newCards = null;

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

                ICCPaymentProfile customerPaymentMethod = payment.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 (Tuple <ICCPaymentProfileDetail, ICCPaymentMethodDetail> det in paymentDetail.Select())
                    {
                        ICCPaymentProfileDetail cpmd = det.Item1;
                        ICCPaymentMethodDetail  pmd  = det.Item2;
                        if (pmd.IsCCProcessingID == true)
                        {
                            cpmd.Value = newCard.PaymentProfileID;
                            paymentDetail.Cache.Update(cpmd);
                        }
                        else if (pmd.IsIdentifier == true)
                        {
                            cpmd.Value = newCard.CardNumber;
                            paymentDetail.Cache.Update(cpmd);
                        }
                    }
                    //getting unmasked expiration date
                    newCard = cim.GetPaymentProfile();
                    if (newCard.CardExpirationDate != null)
                    {
                        payment.Cache.SetValueExt <CustomerPaymentMethod.expirationDate>(customerPaymentMethod, newCard.CardExpirationDate);
                        payment.Cache.Update(customerPaymentMethod);
                    }
                }
                attempt++;
            }
            if (newCard == null)
            {
                throw new PXException(Messages.FailedToSyncCC);
            }
        }