/// <summary> /// Binds the saved accounts. /// </summary> private void BindSavedAccounts( RockContext rockContext, bool oneTime ) { rblSavedAccount.Items.Clear(); if ( _targetPerson != null ) { // Get the saved accounts for the currently logged in user var savedAccounts = new FinancialPersonSavedAccountService( rockContext ) .GetByPersonId( _targetPerson.Id ) .ToList(); // Find the saved accounts that are valid for the selected CC gateway var ccSavedAccountIds = new List<int>(); var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ); if ( _ccGateway != null && _ccGatewayComponent != null && _ccGatewayComponent.SupportsSavedAccount( !oneTime ) && _ccGatewayComponent.SupportsSavedAccount( ccCurrencyType ) ) { ccSavedAccountIds = savedAccounts .Where( a => a.FinancialGatewayId == _ccGateway.Id && a.FinancialPaymentDetail != null && a.FinancialPaymentDetail.CurrencyTypeValueId == ccCurrencyType.Id ) .Select( a => a.Id ) .ToList(); } // Find the saved accounts that are valid for the selected ACH gateway var achSavedAccountIds = new List<int>(); var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ); if ( _achGateway != null && _achGatewayComponent != null && _achGatewayComponent.SupportsSavedAccount( !oneTime ) && _achGatewayComponent.SupportsSavedAccount( achCurrencyType ) ) { achSavedAccountIds = savedAccounts .Where( a => a.FinancialGatewayId == _achGateway.Id && a.FinancialPaymentDetail != null && a.FinancialPaymentDetail.CurrencyTypeValueId == achCurrencyType.Id ) .Select( a => a.Id ) .ToList(); } // Bind the accounts rblSavedAccount.DataSource = savedAccounts .Where( a => ccSavedAccountIds.Contains( a.Id ) || achSavedAccountIds.Contains( a.Id ) ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.FinancialPaymentDetail.AccountNumberMasked + ")" } ).ToList(); rblSavedAccount.DataBind(); if ( rblSavedAccount.Items.Count > 0 ) { rblSavedAccount.Items.Add( new ListItem( "Use a different payment method", "0" ) ); if ( rblSavedAccount.SelectedValue == "" ) { rblSavedAccount.Items[0].Selected = true; } } } }
/// <summary> /// Binds the saved accounts. /// </summary> private void SetSavedAccounts() { rblSavedCC.Items.Clear(); if ( TargetPersonId.HasValue && TargetPersonId == CurrentPersonId ) { // Get the saved accounts for the target person var savedAccounts = new FinancialPersonSavedAccountService() .GetByPersonId( TargetPersonId.Value ); if ( Gateway != null ) { var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ); rblSavedCC.DataSource = savedAccounts .Where( a => a.GatewayEntityTypeId == Gateway.TypeId && a.CurrencyTypeValueId == ccCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.MaskedAccountNumber + ")" } ).ToList(); rblSavedCC.DataBind(); if ( rblSavedCC.Items.Count > 0 ) { rblSavedCC.Items.Add( new ListItem( "Use a different card", "0" ) ); } var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ); rblSavedAch.DataSource = savedAccounts .Where( a => a.GatewayEntityTypeId == Gateway.TypeId && a.CurrencyTypeValueId == achCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.MaskedAccountNumber + ")" } ).ToList(); rblSavedAch.DataBind(); if ( rblSavedAch.Items.Count > 0 ) { rblSavedAch.Items.Add( new ListItem( "Use a different bank account", "0" ) ); } } } if ( rblSavedCC.Items.Count > 0 ) { rblSavedCC.Items[0].Selected = true; rblSavedCC.Visible = true; divNewCard.Style[HtmlTextWriterStyle.Display] = "none"; } else { rblSavedCC.Visible = false; divNewCard.Style[HtmlTextWriterStyle.Display] = "block"; } if ( rblSavedAch.Items.Count > 0 ) { rblSavedAch.Items[0].Selected = true; rblSavedAch.Visible = true; divNewBank.Style[HtmlTextWriterStyle.Display] = "none"; } else { rblSavedAch.Visible = false; divNewCard.Style[HtmlTextWriterStyle.Display] = "block"; } }
private void BindSavedAccounts( GatewayComponent component ) { var currentValue = rblSavedCC.SelectedValue; rblSavedCC.Items.Clear(); if ( CurrentPerson != null ) { // Get the saved accounts for the currently logged in user var savedAccounts = new FinancialPersonSavedAccountService( new RockContext() ) .GetByPersonId( CurrentPerson.Id ); // Verify component is valid and that it supports using saved accounts for one-time, credit card transactions var ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ); if ( component != null && component.SupportsSavedAccount( false ) && component.SupportsSavedAccount( ccCurrencyType ) ) { rblSavedCC.DataSource = savedAccounts .Where( a => a.FinancialGatewayId == RegistrationTemplate.FinancialGateway.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" ) ); rblSavedCC.SetValue( currentValue ); } } } }
/// <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 ccCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD ) ); rblSavedCC.DataSource = savedAccounts .Where( a => a.GatewayEntityTypeId == _ccGateway.TypeId && a.CurrencyTypeValueId == ccCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.MaskedAccountNumber + ")" } ).ToList(); rblSavedCC.DataBind(); if ( rblSavedCC.Items.Count > 0 ) { rblSavedCC.Items.Add( new ListItem( "Use a different card", "0" ) ); } } if ( _achGateway != null ) { var achCurrencyType = DefinedValueCache.Read( new Guid( Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_ACH ) ); rblSavedAch.DataSource = savedAccounts .Where( a => a.GatewayEntityTypeId == _achGateway.TypeId && a.CurrencyTypeValueId == achCurrencyType.Id ) .OrderBy( a => a.Name ) .Select( a => new { Id = a.Id, Name = "Use " + a.Name + " (" + a.MaskedAccountNumber + ")" } ).ToList(); rblSavedAch.DataBind(); if ( rblSavedAch.Items.Count > 0 ) { rblSavedAch.Items.Add( new ListItem( "Use a different bank account", "0" ) ); } } } }
/// <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"; } } }