示例#1
0
        public static TranProfile GetOrCreatePaymentProfileByTran(PXGraph graph, ICCPaymentProfileAdapter adapter, string tranId)
        {
            ICCPaymentProfile            paymentProfile   = adapter.Current;
            ProcessingCardsPluginFactory pluginFactory    = GetProcessingCardsPluginFactory(paymentProfile.CCProcessingCenterID);
            CCProcessingCenter           processingCenter = pluginFactory.GetProcessingCenter();
            CCCustomerInformationManager cim = GetCustomerInformationManager(pluginFactory);

            CardProcessingReadersProvider readersProvider = new CardProcessingReadersProvider(new CCProcessingContext()
            {
                processingCenter = processingCenter,
                aCustomerID      = paymentProfile.BAccountID,
                aPMInstanceID    = paymentProfile.PMInstanceID,
                callerGraph      = graph
            });

            cim.SetReadersProvider(readersProvider);

            Customer    customer = new PXSelect <Customer, Where <Customer.bAccountID, Equal <Required <Customer.bAccountID> > > >(graph).Select(paymentProfile.BAccountID);
            TranProfile ret      = null;

            if (paymentProfile.CustomerCCPID == null)
            {
                ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                {
                    LocalCustomerId = customer.AcctCD
                });
                return(ret);
            }
            var cardLimit = processingCenter.CreditCardLimit;

            if (processingCenter.CreateAdditionalCustomerProfiles == true && cardLimit != null && cardLimit > 0)
            {
                int customerProfileCount = CCProcessingHelper.CustomerProfileCountPerCustomer(graph,
                                                                                              paymentProfile.BAccountID,
                                                                                              paymentProfile.CCProcessingCenterID);

                int allPaymentProfileCount = cim.GetAllPaymentProfiles().Count();
                if (CCProcessingHelper.IsCreditCardCountEnough(allPaymentProfileCount, cardLimit.Value))
                {
                    var prefix = CCProcessingHelper.BuildPrefixForCustomerCD(customerProfileCount, processingCenter);
                    ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                    {
                        LocalCustomerId = prefix + customer.AcctCD
                    });
                }
                else
                {
                    ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                    {
                        PCCustomerId = paymentProfile.CustomerCCPID
                    });
                }
            }
            else
            {
                ret = cim.GetOrCreateCustomerProfileFromTransaction(tranId, new CreateTranPaymentProfileParams()
                {
                    PCCustomerId = paymentProfile.CustomerCCPID
                });
            }
            return(ret);
        }