/// <summary> /// Handles the Delete event of the grdFinancialTransactions control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void rGridTransactions_Delete(object sender, RowEventArgs e) { var financialTransactionService = new Rock.Model.FinancialTransactionService(); Grid grdTransactions = sender as Grid; Rock.Model.FinancialTransaction financialTransaction = financialTransactionService.Get((int)grdTransactions.DataKeys[e.RowIndex]["id"]); if (financialTransaction != null) { financialTransactionService.Delete(financialTransaction, CurrentPersonId); financialTransactionService.Save(financialTransaction, CurrentPersonId); } }
/// <summary> /// Handles the Delete event of the rGridTransactions control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param> protected void rGridTransactions_Delete(object sender, Rock.Web.UI.Controls.RowEventArgs e) { var financialTransactionService = new Rock.Model.FinancialTransactionService(); FinancialTransaction financialTransaction = financialTransactionService.Get((int)e.RowKeyValue); if (financialTransaction != null) { financialTransactionService.Delete(financialTransaction, CurrentPersonId); financialTransactionService.Save(financialTransaction, CurrentPersonId); } BindGrid(); }
/// <summary> /// Processes the confirmation. /// </summary> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessConfirmation( out string errorMessage ) { if ( string.IsNullOrWhiteSpace( TransactionCode ) ) { GatewayComponent gateway = hfPaymentTab.Value == "ACH" ? _achGateway : _ccGateway; if ( gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } Person person = GetPerson( true ); if ( person == null ) { errorMessage = "There was a problem creating the person information"; return false; } PaymentInfo paymentInfo = GetPaymentInfo(); if ( paymentInfo == null ) { errorMessage = "There was a problem creating the payment information"; return false; } else { paymentInfo.FirstName = person.FirstName; paymentInfo.LastName = person.LastName; } if ( paymentInfo.CreditCardTypeValue != null ) { CreditCardTypeValueId = paymentInfo.CreditCardTypeValue.Id; } PaymentSchedule schedule = GetSchedule(); if ( schedule != null ) { schedule.PersonId = person.Id; var scheduledTransaction = gateway.AddScheduledPayment( schedule, paymentInfo, out errorMessage ); if ( scheduledTransaction != null ) { scheduledTransaction.TransactionFrequencyValueId = schedule.TransactionFrequencyValue.Id; scheduledTransaction.AuthorizedPersonId = person.Id; scheduledTransaction.GatewayEntityTypeId = EntityTypeCache.Read( gateway.TypeGuid ).Id; foreach ( var account in SelectedAccounts.Where( a => a.Amount > 0 ) ) { var transactionDetail = new FinancialScheduledTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; scheduledTransaction.ScheduledTransactionDetails.Add( transactionDetail ); } var transactionService = new FinancialScheduledTransactionService(); transactionService.Add( scheduledTransaction, CurrentPersonId ); transactionService.Save( scheduledTransaction, CurrentPersonId ); ScheduleId = scheduledTransaction.GatewayScheduleId; TransactionCode = scheduledTransaction.TransactionCode; } else { return false; } } else { var transaction = gateway.Charge( paymentInfo, out errorMessage ); if ( transaction != null ) { transaction.TransactionDateTime = DateTime.Now; transaction.AuthorizedPersonId = person.Id; transaction.GatewayEntityTypeId = gateway.TypeId; transaction.Amount = paymentInfo.Amount; transaction.TransactionTypeValueId = DefinedValueCache.Read(new Guid(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION)).Id; transaction.CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; transaction.CreditCardTypeValueId = CreditCardTypeValueId; Guid sourceGuid = Guid.Empty; if (Guid.TryParse(GetAttributeValue("Source"), out sourceGuid)) { transaction.SourceTypeValueId = DefinedValueCache.Read(sourceGuid).Id; } foreach ( var account in SelectedAccounts.Where( a => a.Amount > 0 ) ) { var transactionDetail = new FinancialTransactionDetail(); transactionDetail.Amount = account.Amount; transactionDetail.AccountId = account.Id; transaction.TransactionDetails.Add( transactionDetail ); } // Get the batch name string ccSuffix = string.Empty; if ( paymentInfo.CreditCardTypeValue != null ) { ccSuffix = paymentInfo.CreditCardTypeValue.GetAttributeValue( "BatchNameSuffix" ); } if ( string.IsNullOrWhiteSpace( ccSuffix ) ) { ccSuffix = paymentInfo.CurrencyTypeValue.Name; } string batchName = GetAttributeValue( "BatchNamePrefix" ).Trim() + " " + ccSuffix; using ( new UnitOfWorkScope() ) { var batchService = new FinancialBatchService(); var batch = batchService.Queryable() .Where( b => b.Status == BatchStatus.Open && b.BatchStartDateTime <= transaction.TransactionDateTime && b.BatchEndDateTime > transaction.TransactionDateTime && b.Name == batchName ) .FirstOrDefault(); if ( batch == null ) { batch = new FinancialBatch(); batch.Name = batchName; batch.Status = BatchStatus.Open; batch.BatchStartDateTime = transaction.TransactionDateTime.Value.Date.Add( gateway.BatchTimeOffset ); if ( batch.BatchStartDateTime > transaction.TransactionDateTime ) { batch.BatchStartDateTime.Value.AddDays( -1 ); } batch.BatchEndDateTime = batch.BatchStartDateTime.Value.AddDays( 1 ).AddMilliseconds( -1 ); batch.CreatedByPersonId = person.Id; batchService.Add( batch, CurrentPersonId ); batchService.Save( batch, CurrentPersonId ); batch = batchService.Get( batch.Id ); } batch.ControlAmount += transaction.Amount; batchService.Save( batch, CurrentPersonId ); var transactionService = new FinancialTransactionService(); transaction.BatchId = batch.Id; transactionService.Add( transaction, CurrentPersonId ); transactionService.Save( transaction, CurrentPersonId ); } TransactionCode = transaction.TransactionCode; } else { return false; } } tdTransactionCode.Description = TransactionCode; tdTransactionCode.Visible = !string.IsNullOrWhiteSpace( TransactionCode ); tdScheduleId.Description = ScheduleId; tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId ); // If there was a transaction code returned and this was not already created from a previous saved account, // show the option to save the account. if ( !( paymentInfo is ReferencePaymentInfo ) && !string.IsNullOrWhiteSpace( TransactionCode ) ) { cbSaveAccount.Visible = true; pnlSaveAccount.Visible = true; txtSaveAccount.Visible = true; // If current person does not have a login, have them create a username and password phCreateLogin.Visible = !new UserLoginService().GetByPersonId( person.Id ).Any(); } else { pnlSaveAccount.Visible = false; } return true; } else { pnlDupWarning.Visible = true; errorMessage = string.Empty; return false; } }
/// <summary> /// Handles the Delete event of the rGridTransactions control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param> protected void rGridTransactions_Delete( object sender, Rock.Web.UI.Controls.RowEventArgs e ) { var financialTransactionService = new Rock.Model.FinancialTransactionService(); FinancialTransaction financialTransaction = financialTransactionService.Get( (int)e.RowKeyValue ); if ( financialTransaction != null ) { financialTransactionService.Delete( financialTransaction, CurrentPersonId ); financialTransactionService.Save( financialTransaction, CurrentPersonId ); } BindGrid(); }