Exemple #1
0
        public static void GetCreatePaymentProfileForm(PXGraph graph, ICustomerPaymentMethodAdapter customerPaymentMethodAdapter)
        {
            if (graph == null || customerPaymentMethodAdapter == null)
            {
                return;
            }
            CustomerPaymentMethod        customerPaymentMethod = customerPaymentMethodAdapter.Current;
            CCCustomerInformationManager cim = new CCCustomerInformationManager(customerPaymentMethod.CCProcessingCenterID, CCProcessingFeature.HostedForm)
            {
                CustomerID   = customerPaymentMethod.BAccountID,
                PMInstanceID = customerPaymentMethod.PMInstanceID,
                CallerGraph  = graph
            };

            string id = customerPaymentMethod.CustomerCCPID;

            if (id == 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,
                                                                                              customerPaymentMethod.BAccountID,
                                                                                              customerPaymentMethod.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);
                    }
                }
            }
            cim.GetCreatePaymentProfileForm();
        }
 public virtual void GetNewPaymentProfiles(PXGraph graph,
                                           ICustomerPaymentMethodAdapter customerPaymentMethodAdapter,
                                           ICustomerPaymentMethodDetailAdapter customerPaymentMethodDetailAdapter)
 {
     CCCustomerInformationManager.GetNewPaymentProfiles(graph, customerPaymentMethodAdapter, customerPaymentMethodDetailAdapter);
 }
 public virtual void GetCreatePaymentProfileForm(PXGraph graph, ICustomerPaymentMethodAdapter customerPaymentMethodAdapter)
 {
     CCCustomerInformationManager.GetCreatePaymentProfileForm(graph, customerPaymentMethodAdapter);
 }
Exemple #4
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);
                }
            }
        }
Exemple #5
0
        public static void GetNewPaymentProfiles(PXGraph graph,
                                                 ICustomerPaymentMethodAdapter customerPaymentMethodAdapter,
                                                 ICustomerPaymentMethodDetailAdapter customerPaymentMethodDetailAdapter
                                                 )
        {
            if (graph == null || customerPaymentMethodAdapter == null || customerPaymentMethodDetailAdapter == null)
            {
                return;
            }
            CustomerPaymentMethod        currentCustomerPaymentMethod = customerPaymentMethodAdapter.Current;
            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);
                }

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