private void AddCustomerProcessingCenterIfNeeded(CustomerProcessingCenterID newCustomerProcessingCenterID)
		{
			CustomerProcessingCenterID customerProcessingCenter = PXSelect<CustomerProcessingCenterID,
				Where<CustomerProcessingCenterID.cCProcessingCenterID, Equal<Required<CustomerProcessingCenterID.cCProcessingCenterID>>,
					And<CustomerProcessingCenterID.bAccountID, Equal<Required<CustomerProcessingCenterID.bAccountID>>,
					And<CustomerProcessingCenterID.customerCCPID, Equal<Required<CustomerProcessingCenterID.customerCCPID>>>>>>
						.Select(this, newCustomerProcessingCenterID.CCProcessingCenterID, newCustomerProcessingCenterID.BAccountID, newCustomerProcessingCenterID.CustomerCCPID);

			if (customerProcessingCenter == null)
			{
				PXCache cache = Caches[typeof(CustomerProcessingCenterID)];
				newCustomerProcessingCenterID = cache.Insert(newCustomerProcessingCenterID) as CustomerProcessingCenterID;
				cache.PersistInserted(newCustomerProcessingCenterID);
			}
		}
Beispiel #2
0
        private void CreateCustomerProcessingCenterRecord(CustomerPaymentMethod customerPM, CCSynchronizeCard syncCard)
        {
            PXCache customerProcessingCenterCache = Caches[typeof(CustomerProcessingCenterID)];

            customerProcessingCenterCache.ClearQueryCacheObsolete();
            PXSelectBase <CustomerProcessingCenterID> checkRecordExist = new PXSelectReadonly <CustomerProcessingCenterID,
                                                                                               Where <CustomerProcessingCenterID.cCProcessingCenterID, Equal <Required <CreditCardsFilter.processingCenterId> >,
                                                                                                      And <CustomerProcessingCenterID.bAccountID, Equal <Required <CustomerProcessingCenterID.bAccountID> >,
                                                                                                           And <CustomerProcessingCenterID.customerCCPID, Equal <Required <CustomerProcessingCenterID.customerCCPID> > > > > >(this);
            CustomerProcessingCenterID cProcessingCenter = checkRecordExist.SelectSingle(syncCard.CCProcessingCenterID, syncCard.BAccountID, syncCard.CustomerCCPID);

            if (cProcessingCenter == null)
            {
                cProcessingCenter                      = customerProcessingCenterCache.CreateInstance() as CustomerProcessingCenterID;
                cProcessingCenter.BAccountID           = syncCard.BAccountID;
                cProcessingCenter.CCProcessingCenterID = syncCard.CCProcessingCenterID;
                cProcessingCenter.CustomerCCPID        = syncCard.CustomerCCPID;
                customerProcessingCenterCache.Insert(cProcessingCenter);
                customerProcessingCenterCache.Persist(PXDBOperation.Insert);
            }
        }
Beispiel #3
0
        public virtual void CCSynchronizeCard_BAccountID_FieldDefaulting(PXCache cache, PXFieldDefaultingEventArgs e)
        {
            CCSynchronizeCard syncCard = e.Row as CCSynchronizeCard;

            if (syncCard == null)
            {
                return;
            }

            string customerCCPID = syncCard.CustomerCCPID;
            PXSelectBase <CustomerProcessingCenterID> cpcQuery = new PXSelect <CustomerProcessingCenterID,
                                                                               Where <CustomerProcessingCenterID.customerCCPID, Equal <Required <CustomerProcessingCenterID.customerCCPID> > >,
                                                                               OrderBy <Desc <CustomerProcessingCenterID.createdDateTime> > >(this);
            CustomerProcessingCenterID customerPaymentMethod = cpcQuery.SelectSingle(customerCCPID);

            if (customerPaymentMethod != null)
            {
                e.NewValue = customerPaymentMethod.BAccountID;
                return;
            }

            string customerID = syncCard.PCCustomerID;

            if (customerID == null)
            {
                return;
            }

            customerID = DeleteCustomerPrefix(customerID);
            PXSelectBase <Customer> cQuery = new PXSelect <Customer,
                                                           Where <Customer.acctCD, Equal <Required <CCSynchronizeCard.pCCustomerID> > > >(this);
            Customer customer = cQuery.SelectSingle(customerID);

            if (customer != null)
            {
                e.NewValue = customer.BAccountID;
            }
        }
		private void DoConvert(CustomerPaymentMethod cpm, CCProcessingCenter newCCPC)
		{
			CCProcessingCenterPmntMethod newProcessingCenterPM = PXSelect<CCProcessingCenterPmntMethod,
				Where<CCProcessingCenterPmntMethod.paymentMethodID, Equal<Required<CCProcessingCenterPmntMethod.paymentMethodID>>,
				And<CCProcessingCenterPmntMethod.processingCenterID, Equal<Required<CCProcessingCenterPmntMethod.processingCenterID>>>>>.Select(this, cpm.PaymentMethodID, newCCPC.ProcessingCenterID);
			if (newProcessingCenterPM == null)
			{
				newProcessingCenterPM = (CCProcessingCenterPmntMethod)ProcessingCenterPM.Cache.CreateInstance();
				newProcessingCenterPM.PaymentMethodID = cpm.PaymentMethodID;
				newProcessingCenterPM.ProcessingCenterID = newCCPC.ProcessingCenterID;
				ProcessingCenterPM.Insert(newProcessingCenterPM);
			}

			CustomerPaymentMethod currCPM = (CustomerPaymentMethod)CustomerPM.Cache.CreateCopy(cpm);
			var oldCCProcessingCenterID = currCPM.CCProcessingCenterID;
			currCPM.CCProcessingCenterID = newCCPC.ProcessingCenterID;
			if (currCPM.CustomerCCPID == null)
			{
				CustomerPM.Cache.SetDefaultExt<CustomerPaymentMethod.customerCCPID>(currCPM);
			}
			currCPM.Selected = true;
			currCPM = CustomerPM.Update(currCPM);
			CustomerPM.Current = currCPM;

			PXResultset<PaymentMethodDetail> oldDetails = PMDetails.Select(currCPM.PaymentMethodID);
			foreach (PaymentMethodDetail oldDetail in oldDetails)
			{
				PaymentMethodDetail newDetail = (PaymentMethodDetail)PMDetails.Cache.CreateCopy(oldDetail);
				newDetail.ValidRegexp = null;
				PMDetails.Update(newDetail);
			}

			PaymentMethod CurrPM = PM.Select();
			PaymentMethodDetail CCPID = FindCCPID(CurrPM);

			if (CCPID == null)
			{
				using (PXTransactionScope ts = new PXTransactionScope())
				{
					PaymentMethodDetail res;
					CCPID = (PaymentMethodDetail)PMDetails.Cache.CreateInstance();
					CCPID.PaymentMethodID = currCPM.PaymentMethodID;
					CCPID.UseFor = PaymentMethodDetailUsage.UseForARCards;
					CCPID.DetailID = "CCPID";
					CCPID.Descr = Messages.PaymentProfileID;
					CCPID.IsCCProcessingID = true;
					CCPID.IsRequired = true;
					res = PMDetails.Insert(CCPID);
					if (res == null)
					{
						throw new PXException(Messages.CouldNotInsertPMDetail);
					}
					else
					{
						PMDetails.Cache.Persist(PXDBOperation.Insert);
					}
					ts.Complete();
				}
			}

			CCProcessingCenter procCenter = PXSelect<CCProcessingCenter,
				Where<CCProcessingCenter.processingCenterID, Equal<Required<CCProcessingCenter.processingCenterID>>>>
					.Select(this, oldCCProcessingCenterID);
			bool oldProcCenterSupportTokenizing = ProcCenterSupportTokenizing(oldCCProcessingCenterID);
			bool newProcCenterSupportTokenizing = ProcCenterSupportTokenizing(newCCPC.ProcessingCenterID);

			if (!oldProcCenterSupportTokenizing && newProcCenterSupportTokenizing)
			{
				CustomerPaymentMethodDetail newCCPIDPM = PXSelect<CustomerPaymentMethodDetail,
					Where<CustomerPaymentMethodDetail.pMInstanceID, Equal<Required<CustomerPaymentMethodDetail.pMInstanceID>>,
						And<CustomerPaymentMethodDetail.paymentMethodID, Equal<Required<CustomerPaymentMethodDetail.paymentMethodID>>,
						And<CustomerPaymentMethodDetail.detailID, Equal<Required<CustomerPaymentMethodDetail.detailID>>>>>>
							.Select(this, currCPM.PMInstanceID, currCPM.PaymentMethodID, CCPID.DetailID);
				if (newCCPIDPM != null)
				{
					newCCPIDPM.Value = null;
					CustomerPMDetails.Update(newCCPIDPM);
				}
				else
				{
					newCCPIDPM = new CustomerPaymentMethodDetail
					{
						PMInstanceID = currCPM.PMInstanceID,
						PaymentMethodID = currCPM.PaymentMethodID,
						DetailID = CCPID.DetailID
					};
					CustomerPMDetails.Insert(newCCPIDPM);
				}
				var graph = PXGraph.CreateInstance<CCCustomerInformationManagerGraph>();
				ICCPaymentProfileAdapter paymentProfile = new GenericCCPaymentProfileAdapter<CustomerPaymentMethod>(CustomerPM);
				ICCPaymentProfileDetailAdapter profileDetail = new GenericCCPaymentProfileDetailAdapter<CustomerPaymentMethodDetail,
					PaymentMethodDetail>(CustomerPMDetails, PMDetails);
				DateTime expiredDate;
				if (CheckCardIsExpired(currCPM, out expiredDate))
				{
					Customer cust =  new PXSelect<Customer, 
						Where<Customer.bAccountID, Equal<Required<Customer.bAccountID>>>>(this)
							.SelectSingle(currCPM.BAccountID);
					throw new PXException(AR.Messages.ERR_CCCreditCardHasExpired, expiredDate.ToString("d"), cust.AcctCD);
				}
				graph.GetOrCreatePaymentProfile(this, paymentProfile, profileDetail);
			}

			if (newProcCenterSupportTokenizing)
			{
				if (currCPM.CustomerCCPID == null)
				{
					currCPM.CustomerCCPID = cpm.CustomerCCPID;
				}
				CustomerProcessingCenterID newCustomerProcessingCenterID = new CustomerProcessingCenterID
				{
					CCProcessingCenterID = newCCPC.ProcessingCenterID,
					BAccountID = cpm.BAccountID,
					CustomerCCPID = currCPM.CustomerCCPID
				};
				AddCustomerProcessingCenterIfNeeded(newCustomerProcessingCenterID);
			}
			currCPM = CustomerPM.Update(currCPM);
		}
        public void ConvertCustomerPaymentMethod(CustomerPaymentMethod cpm, CCProcessingCenter newCCPC)
        {
            CCProcessingCenterPmntMethod newProcessingCenterPM = PXSelect <CCProcessingCenterPmntMethod,
                                                                           Where <CCProcessingCenterPmntMethod.paymentMethodID, Equal <Required <CCProcessingCenterPmntMethod.paymentMethodID> >,
                                                                                  And <CCProcessingCenterPmntMethod.processingCenterID, Equal <Required <CCProcessingCenterPmntMethod.processingCenterID> > > > > .Select(this, cpm.PaymentMethodID, newCCPC.ProcessingCenterID);

            if (newProcessingCenterPM == null)
            {
                newProcessingCenterPM = (CCProcessingCenterPmntMethod)ProcessingCenterPM.Cache.CreateInstance();
                newProcessingCenterPM.PaymentMethodID    = cpm.PaymentMethodID;
                newProcessingCenterPM.ProcessingCenterID = newCCPC.ProcessingCenterID;
                ProcessingCenterPM.Insert(newProcessingCenterPM);
            }

            CustomerPaymentMethod currCPM = (CustomerPaymentMethod)CustomerPM.Cache.CreateCopy(cpm);
            var oldCCProcessingCenterID   = currCPM.CCProcessingCenterID;

            currCPM.CCProcessingCenterID = newCCPC.ProcessingCenterID;
            if (currCPM.CustomerCCPID == null)
            {
                CustomerPM.Cache.SetDefaultExt <CustomerPaymentMethod.customerCCPID>(currCPM);
            }
            currCPM.Selected   = true;
            currCPM            = CustomerPM.Update(currCPM);
            CustomerPM.Current = currCPM;

            PXResultset <PaymentMethodDetail> oldDetails = PMDetails.Select(currCPM.PaymentMethodID);

            foreach (PaymentMethodDetail oldDetail in oldDetails)
            {
                PaymentMethodDetail newDetail = (PaymentMethodDetail)PMDetails.Cache.CreateCopy(oldDetail);
                newDetail.ValidRegexp = null;
                PMDetails.Update(newDetail);
            }

            PaymentMethod       CurrPM = PM.Select();
            PaymentMethodDetail CCPID  = FindCCPID(CurrPM);

            if (CCPID == null)
            {
                using (PXTransactionScope ts = new PXTransactionScope())
                {
                    PaymentMethodDetail res;
                    CCPID = (PaymentMethodDetail)PMDetails.Cache.CreateInstance();
                    CCPID.PaymentMethodID  = currCPM.PaymentMethodID;
                    CCPID.UseFor           = PaymentMethodDetailUsage.UseForARCards;
                    CCPID.DetailID         = "CCPID";
                    CCPID.Descr            = Messages.PaymentProfileID;
                    CCPID.IsCCProcessingID = true;
                    CCPID.IsRequired       = true;
                    res = PMDetails.Insert(CCPID);
                    if (res == null)
                    {
                        throw new PXException(Messages.CouldNotInsertPMDetail);
                    }
                    else
                    {
                        PMDetails.Cache.Persist(PXDBOperation.Insert);
                    }
                    ts.Complete();
                }
            }

            CCProcessingCenter procCenter = PXSelect <CCProcessingCenter,
                                                      Where <CCProcessingCenter.processingCenterID, Equal <Required <CCProcessingCenter.processingCenterID> > > >
                                            .Select(this, oldCCProcessingCenterID);

            bool doesOldProcCenterSupportTokenizing = CCProcessingFeatureHelper.IsFeatureSupported(procCenter, CCProcessingFeature.ProfileManagement);
            bool doesNewProcCenterSupportTokenizing = CCProcessingFeatureHelper.IsFeatureSupported(newCCPC, CCProcessingFeature.ProfileManagement);

            if (!doesOldProcCenterSupportTokenizing && doesNewProcCenterSupportTokenizing)
            {
                CustomerPaymentMethodDetail newCCPIDPM = PXSelect <CustomerPaymentMethodDetail,
                                                                   Where <CustomerPaymentMethodDetail.pMInstanceID, Equal <Required <CustomerPaymentMethodDetail.pMInstanceID> >,
                                                                          And <CustomerPaymentMethodDetail.paymentMethodID, Equal <Required <CustomerPaymentMethodDetail.paymentMethodID> >,
                                                                               And <CustomerPaymentMethodDetail.detailID, Equal <Required <CustomerPaymentMethodDetail.detailID> > > > > >
                                                         .Select(this, currCPM.PMInstanceID, currCPM.PaymentMethodID, CCPID.DetailID);

                if (newCCPIDPM != null)
                {
                    newCCPIDPM.Value = null;
                    CustomerPMDetails.Update(newCCPIDPM);
                }
                else
                {
                    newCCPIDPM = new CustomerPaymentMethodDetail
                    {
                        PMInstanceID    = currCPM.PMInstanceID,
                        PaymentMethodID = currCPM.PaymentMethodID,
                        DetailID        = CCPID.DetailID
                    };
                    CustomerPMDetails.Insert(newCCPIDPM);
                }
                var graph = PXGraph.CreateInstance <CCCustomerInformationManagerGraph>();
                graph.GetOrCreatePaymentProfile(this, new GenericCustomerPaymentMethodAdaper <CustomerPaymentMethod>(CustomerPM),
                                                new GenericCustomerPaymentMethodDetailAdapter <CustomerPaymentMethodDetail>(CustomerPMDetails));
            }

            if (doesNewProcCenterSupportTokenizing)
            {
                if (currCPM.CustomerCCPID == null)
                {
                    currCPM.CustomerCCPID = cpm.CustomerCCPID;
                }
                CustomerProcessingCenterID newCustomerProcessingCenterID = new CustomerProcessingCenterID
                {
                    CCProcessingCenterID = newCCPC.ProcessingCenterID,
                    BAccountID           = cpm.BAccountID,
                    CustomerCCPID        = currCPM.CustomerCCPID
                };
                AddCustomerProcessingCenterIfNeeded(newCustomerProcessingCenterID);
            }
            currCPM = CustomerPM.Update(currCPM);
            this.Save.Press();
        }