protected int?CreatePaymentProfile(V2.TranProfile input)
        {
            var cpmSelect  = NewCpm;
            var cpmdSelect = NewCpmd;
            var pmdSelect  = PaymentMethodDet;

            foreach (PaymentMethodDetail item in pmdSelect.Select())
            {
                CustomerPaymentMethodDetail cpmd = new CustomerPaymentMethodDetail();
                cpmd.PaymentMethodID = SelectedPaymentMethod;
                cpmd.DetailID        = item.DetailID;
                if (item.IsCCProcessingID == true)
                {
                    cpmd.Value = input.PaymentProfileId;
                }
                cpmdSelect.Insert(cpmd);
            }

            CCCustomerInformationManagerGraph infoManagerGraph = PXGraph.CreateInstance <CCCustomerInformationManagerGraph>();
            GenericCCPaymentProfileAdapter <CustomerPaymentMethod> cpmAdapter = new GenericCCPaymentProfileAdapter <CustomerPaymentMethod>(cpmSelect);
            var cpmdAdapter = new GenericCCPaymentProfileDetailAdapter <CustomerPaymentMethodDetail, PaymentMethodDetail>(cpmdSelect, pmdSelect);

            infoManagerGraph.GetPaymentProfile(Base, cpmAdapter, cpmdAdapter);
            var   cardIdent         = pmdSelect.Select().RowCast <PaymentMethodDetail>().Where(i => i.IsIdentifier == true).First();
            var   detailWithCardNum = cpmdSelect.Select().RowCast <CustomerPaymentMethodDetail>().Where(i => i.DetailID == cardIdent.DetailID).First();
            Match match             = new Regex("[\\d]+").Match(detailWithCardNum.Value);

            CustomerPaymentMethod cpm = cpmSelect.Select();

            if (match.Success)
            {
                cpm.Descr = SelectedPaymentMethod + ":" + maskedCardTmpl + match.Value;
            }

            cpmSelect.Cache.Persist(PXDBOperation.Insert);
            cpmdSelect.Cache.Persist(PXDBOperation.Insert);
            return(cpm.PMInstanceID);
        }
        protected V2.TranProfile GetOrCreateCustomerProfileByTranId(string tranId)
        {
            PXSelectBase <CustomerPaymentMethod> query = new PXSelectReadonly <CustomerPaymentMethod,
                                                                               Where <CustomerPaymentMethod.bAccountID, Equal <Required <CustomerPaymentMethod.bAccountID> >,
                                                                                      And <CustomerPaymentMethod.cCProcessingCenterID, Equal <Required <CustomerPaymentMethod.cCProcessingCenterID> > > >,
                                                                               OrderBy <Desc <CustomerPaymentMethod.createdDateTime> > >(Base);

            IEnumerable <CustomerPaymentMethod> cpmRes = query.Select(SelectedBAccount, SelectedProcessingCenter).RowCast <CustomerPaymentMethod>();
            CustomerPaymentMethod searchCpm            = cpmRes.FirstOrDefault();
            ICCPaymentProfile     cpm = PrepeareCpmRecord();

            if (searchCpm != null)
            {
                cpm.CustomerCCPID = searchCpm.CustomerCCPID;
            }

            CCCustomerInformationManagerGraph infoManagerGraph = PXGraph.CreateInstance <CCCustomerInformationManagerGraph>();
            GenericCCPaymentProfileAdapter <CustomerPaymentMethod> cpmAdapter =
                new GenericCCPaymentProfileAdapter <CustomerPaymentMethod>(NewCpm);

            V2.TranProfile ret = infoManagerGraph.GetOrCreatePaymentProfileByTran(Base, cpmAdapter, tranId);
            cpm.CustomerCCPID = ret.CustomerProfileId;
            return(ret);
        }