/// <summary> /// Binds the saved accounts. /// </summary> private void BindSavedAccounts() { rblSavedCC.Items.Clear(); if ( TargetPerson != null ) { // Get the saved accounts for the currently logged in user var savedAccounts = new FinancialPersonSavedAccountService( new RockContext() ) .GetByPersonId( TargetPerson.Id ); if ( _ccGateway != null ) { var ccGatewayComponent = _ccGateway.GetGatewayComponent(); var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ); if ( ccGatewayComponent != null && ccGatewayComponent.SupportsSavedAccount( ccCurrencyType ) ) { rblSavedCC.DataSource = savedAccounts .Where( a => a.FinancialGatewayId == _ccGateway.Id && a.FinancialPaymentDetail != null && a.FinancialPaymentDetail.CurrencyTypeValueId == ccCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.FinancialPaymentDetail.AccountNumberMasked + ")" } ).ToList(); rblSavedCC.DataBind(); if ( rblSavedCC.Items.Count > 0 ) { rblSavedCC.Items.Add( new ListItem( "Use a different card", "0" ) ); CollapseCardData.Value = "true"; } } } if ( _achGateway != null ) { var achGatewayComponent = _ccGateway.GetGatewayComponent(); var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ); if ( achGatewayComponent != null && achGatewayComponent.SupportsSavedAccount( achCurrencyType ) ) { rblSavedAch.DataSource = savedAccounts .Where( a => a.FinancialGatewayId == _achGateway.Id && a.FinancialPaymentDetail != null && a.FinancialPaymentDetail.CurrencyTypeValueId == achCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.FinancialPaymentDetail.AccountNumberMasked + ")" } ).ToList(); rblSavedAch.DataBind(); } divRecentCheck.Style[HtmlTextWriterStyle.Display] = "none"; var aliasIds = TargetPerson.Aliases.Select( y => y.Id ).ToList(); var prevChecks = new FinancialTransactionService( new RockContext() ).Queryable().Where( x => aliasIds.Contains( x.AuthorizedPersonAliasId ?? -1 ) ).Where( x => x.CheckMicrParts != null ).SortBy( "CreatedDateTime Desc" ).Take( 3 ).ToList().Select( x => (Rock.Security.Encryption.DecryptString( x.CheckMicrParts ) ?? "").Split( '_' ) ).Select( x => x.ElementAtOrDefault( 0 ) + "_" + x.ElementAtOrDefault( 1 ) ); if ( prevChecks.Distinct().Count() == 1 && prevChecks.FirstOrDefault() != "_" ) { rblSavedAch.Items.Add( new ListItem( "Use recent check", "-1" ) ); var achDat = prevChecks.FirstOrDefault().Split( '_' ); if ( achDat.Count() == 2 ) { if ( !IsPostBack ) { txtCheckRoutingNumber.Text = achDat[0]; txtCheckAccountNumber.Text = achDat[1]; } } if ( PageParameter( "flc" ) == "1" && !IsPostBack ) { hfPaymentTab.Value = "ACH"; rblSavedAch.SelectedValue = "-1"; } } if ( rblSavedAch.Items.Count > 0 ) { rblSavedAch.Items.Add( new ListItem( "Use a different bank account", "0" ) ); CollapseCardData.Value = "true"; } } if ( rblSavedCC.Items.Count <= 0 && rblSavedAch.Items.Count > 0 ) { hfPaymentTab.Value = "ACH"; } } }