/// <summary>
        /// Binds the person saved accounts.
        /// </summary>
        private void BindPersonSavedAccounts()
        {
            var rockContext = new RockContext();

            var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext);
            var targetPersonId       = scheduledTransaction.AuthorizedPersonAlias.PersonId;

            var personSavedAccountsQuery = new FinancialPersonSavedAccountService(rockContext)
                                           .GetByPersonId(targetPersonId)
                                           .Where(a => !a.IsSystem)
                                           .AsNoTracking();

            DefinedValueCache[] allowedCurrencyTypes =
            {
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH.AsGuid())
            };

            int[] allowedCurrencyTypeIds = allowedCurrencyTypes.Select(a => a.Id).ToArray();

            var financialGateway = this.FinancialGateway;

            if (financialGateway == null)
            {
                return;
            }

            personSavedAccountsQuery = personSavedAccountsQuery.Where(a =>
                                                                      a.FinancialGatewayId == financialGateway.Id &&
                                                                      (a.FinancialPaymentDetail.CurrencyTypeValueId != null) &&
                                                                      allowedCurrencyTypeIds.Contains(a.FinancialPaymentDetail.CurrencyTypeValueId.Value));

            var personSavedAccountList = personSavedAccountsQuery.OrderBy(a => a.Name).AsNoTracking().Select(a => new
            {
                a.Id,
                a.Name,
                a.GatewayPersonIdentifier,
                a.FinancialPaymentDetail.AccountNumberMasked,
            }).ToList();

            ddlPersonSavedAccount.Items.Clear();
            foreach (var personSavedAccount in personSavedAccountList)
            {
                var displayName = string.Format("{0} ({1})", personSavedAccount.Name, personSavedAccount.AccountNumberMasked);
                ddlPersonSavedAccount.Items.Add(new ListItem(displayName, personSavedAccount.Id.ToString()));
            }

            string errorMessage;
            var    financialGateComponent  = this.FinancialGatewayComponent;
            var    gatewayPersonIdentifier = (financialGateComponent as GatewayComponent).GetReferenceNumber(scheduledTransaction, out errorMessage);

            int?selectedSavedAccountId = personSavedAccountList.Where(a => a.GatewayPersonIdentifier == gatewayPersonIdentifier).Select(a => ( int? )a.Id).FirstOrDefault();

            ddlPersonSavedAccount.SetValue(selectedSavedAccountId);
        }
        /// <summary>
        /// Gets the saved accounts.
        /// </summary>
        /// <returns></returns>
        private List <FinancialPersonSavedAccount> GetSavedAccounts()
        {
            var financialGateway = this.FinancialGateway;

            if (financialGateway == null)
            {
                return(new List <FinancialPersonSavedAccount>());
            }

            var rockContext = new RockContext();

            var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext);
            var targetPersonId       = scheduledTransaction.AuthorizedPersonAlias.PersonId;

            if (targetPersonId != CurrentPersonId)
            {
                if (GetAttributeValue(AttributeKey.ImpersonatorCanSeeSavedAccounts).AsBoolean() == false)
                {
                    return(new List <FinancialPersonSavedAccount>());
                }
            }

            var personSavedAccountsQuery = new FinancialPersonSavedAccountService(rockContext)
                                           .GetByPersonId(targetPersonId)
                                           .Where(a => !a.IsSystem)
                                           .AsNoTracking();

            DefinedValueCache[] allowedCurrencyTypes =
            {
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH.AsGuid())
            };

            int[] allowedCurrencyTypeIds = allowedCurrencyTypes.Select(a => a.Id).ToArray();

            personSavedAccountsQuery = personSavedAccountsQuery.Where(a =>
                                                                      a.FinancialGatewayId == financialGateway.Id &&
                                                                      (a.FinancialPaymentDetail.CurrencyTypeValueId != null) &&
                                                                      allowedCurrencyTypeIds.Contains(a.FinancialPaymentDetail.CurrencyTypeValueId.Value));

            var personSavedAccountList = personSavedAccountsQuery.OrderBy(a => a.Name).Include(a => a.FinancialPaymentDetail).AsNoTracking().ToList();

            return(personSavedAccountList);
        }
Esempio n. 3
0
        private List <PersonSavedAccountInfo> GetSavedAccounts()
        {
            var financialGateway = this.FinancialGateway;

            if (financialGateway == null)
            {
                return(new List <PersonSavedAccountInfo>());
            }

            var rockContext = new RockContext();

            var scheduledTransaction = this.GetFinancialScheduledTransaction(rockContext);
            var targetPersonId       = scheduledTransaction.AuthorizedPersonAlias.PersonId;

            var personSavedAccountsQuery = new FinancialPersonSavedAccountService(rockContext)
                                           .GetByPersonId(targetPersonId)
                                           .Where(a => !a.IsSystem)
                                           .AsNoTracking();

            DefinedValueCache[] allowedCurrencyTypes =
            {
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid()),
                DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH.AsGuid())
            };

            int[] allowedCurrencyTypeIds = allowedCurrencyTypes.Select(a => a.Id).ToArray();

            personSavedAccountsQuery = personSavedAccountsQuery.Where(a =>
                                                                      a.FinancialGatewayId == financialGateway.Id &&
                                                                      (a.FinancialPaymentDetail.CurrencyTypeValueId != null) &&
                                                                      allowedCurrencyTypeIds.Contains(a.FinancialPaymentDetail.CurrencyTypeValueId.Value));

            List <PersonSavedAccountInfo> personSavedAccountList = personSavedAccountsQuery.OrderBy(a => a.Name).AsNoTracking().Select(a => new PersonSavedAccountInfo
            {
                Id   = a.Id,
                Name = a.Name,
                GatewayPersonIdentifier = a.GatewayPersonIdentifier,
                AccountNumberMasked     = a.FinancialPaymentDetail.AccountNumberMasked,
            }).ToList();

            return(personSavedAccountList);
        }