Пример #1
0
        public static void GetPaymentProfile(PXGraph graph, ICCPaymentProfileAdapter payment, ICCPaymentProfileDetailAdapter paymentDetail)
        {
            string CCPID = null;

            foreach (Tuple <ICCPaymentProfileDetail, ICCPaymentMethodDetail> det in paymentDetail.Select())
            {
                ICCPaymentProfileDetail ppd = det.Item1;
                ICCPaymentMethodDetail  pmd = det.Item2;
                if (pmd.IsCCProcessingID == true)
                {
                    CCPID = ppd.Value;
                    break;
                }
            }
            if (string.IsNullOrEmpty(CCPID))
            {
                throw new PXException(Messages.CreditCardTokenIDNotFound);
            }
            ICCPaymentProfile paymentProfile   = payment.Current;
            string            custProcCenterID = paymentProfile.CCProcessingCenterID;
            int?bAccountId   = paymentProfile.BAccountID;
            int?pmInstanceId = paymentProfile.PMInstanceID;
            ProcessingCardsPluginFactory  pluginFactory   = GetProcessingCardsPluginFactory(custProcCenterID);
            CCCustomerInformationManager  cim             = GetCustomerInformationManager(pluginFactory);
            CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(new CCProcessingContext()
            {
                processingCenter = pluginFactory.GetProcessingCenter(),
                aCustomerID      = bAccountId,
                aPMInstanceID    = pmInstanceId,
                callerGraph      = graph
            });

            cim.SetReadersProvider(readersProvider);
            CreditCardData cardData = cim.GetPaymentProfile();

            if (cardData == null)
            {
                throw new PXException(Messages.CreditCardNotFoundInProcCenter, CCPID, paymentProfile.CCProcessingCenterID);
            }
            foreach (Tuple <ICCPaymentProfileDetail, ICCPaymentMethodDetail> det in paymentDetail.Select())
            {
                ICCPaymentProfileDetail ppd = det.Item1;
                ICCPaymentMethodDetail  pmd = det.Item2;
                if (pmd.IsCCProcessingID != true && pmd.IsIdentifier == true && !string.IsNullOrEmpty(cardData.CardNumber))
                {
                    ppd.Value = cardData.CardNumber;
                    paymentDetail.Cache.Update(ppd);
                }
            }
            if (cardData.CardExpirationDate != null)
            {
                payment.Cache.SetValueExt(paymentProfile, nameof(paymentProfile.ExpirationDate), cardData.CardExpirationDate);
                payment.Cache.Update(paymentProfile);
            }
        }
Пример #2
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);
                }
            }
        }
Пример #3
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);
            }
        }