public GetStatus ( FinancialScheduledTransaction scheduledTransaction, string &errorMessages ) : bool | ||
scheduledTransaction | FinancialScheduledTransaction | The scheduled transaction. |
errorMessages | string | The error messages. |
리턴 | bool |
protected void bbtnDelete_Click( object sender, EventArgs e ) { BootstrapButton bbtnDelete = (BootstrapButton)sender; RepeaterItem riItem = (RepeaterItem)bbtnDelete.NamingContainer; HiddenField hfScheduledTransactionId = (HiddenField)riItem.FindControl( "hfScheduledTransactionId" ); Literal content = (Literal)riItem.FindControl( "lLiquidContent" ); Button btnEdit = (Button)riItem.FindControl( "btnEdit" ); using ( var rockContext = new Rock.Data.RockContext() ) { FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService( rockContext ); var currentTransaction = fstService.Get( Int32.Parse( hfScheduledTransactionId.Value ) ); if ( currentTransaction != null && currentTransaction.FinancialGateway != null ) { currentTransaction.FinancialGateway.LoadAttributes( rockContext ); } string errorMessage = string.Empty; if ( fstService.Cancel( currentTransaction, out errorMessage ) ) { try { fstService.GetStatus( currentTransaction, out errorMessage ); } catch { } rockContext.SaveChanges(); content.Text = String.Format( "<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue( "TransactionLabel" ).ToLower() ); } else { content.Text = String.Format( "<div class='alert alert-danger'>An error occured while deleting your scheduled transation. Message: {0}</div>", errorMessage ); } } bbtnDelete.Visible = false; btnEdit.Visible = false; }
private void DeleteOldTransaction( int scheduledTransactionId ) { using ( var rockContext = new Rock.Data.RockContext() ) { FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService( rockContext ); var currentTransaction = fstService.Get( scheduledTransactionId ); if ( currentTransaction != null && currentTransaction.FinancialGateway != null ) { currentTransaction.FinancialGateway.LoadAttributes( rockContext ); } string errorMessage = string.Empty; if ( fstService.Cancel( currentTransaction, out errorMessage ) ) { try { fstService.GetStatus( currentTransaction, out errorMessage ); } catch { } rockContext.SaveChanges(); //content.Text = String.Format( "<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue( "TransactionLabel" ).ToLower() ); } else { //content.Text = String.Format( "<div class='alert alert-danger'>An error occured while deleting your scheduled transation. Message: {0}</div>", errorMessage ); } } }
// helper functional methods (like BindGrid(), etc.) private void ShowContent() { List<Dictionary<string, object>> scheduleSummaries = new List<Dictionary<string, object>>(); // get scheduled transactions for current user if ( CurrentPerson != null ) { var rockContext = new RockContext(); FinancialScheduledTransactionService transactionService = new FinancialScheduledTransactionService( rockContext ); var schedules = transactionService.Queryable( "ScheduledTransactionDetails.Account" ) .Where( s => s.AuthorizedPersonAlias.Person.GivingId == CurrentPerson.GivingId && s.IsActive == true ); foreach ( FinancialScheduledTransaction schedule in schedules ) { string errorMsgs = string.Empty; transactionService.GetStatus( schedule, out errorMsgs ); decimal totalAmount = 0; Dictionary<string, object> scheduleSummary = new Dictionary<string, object>(); scheduleSummary.Add("Id", schedule.Id); scheduleSummary.Add("Guid", schedule.Guid); scheduleSummary.Add("StartDate", schedule.StartDate); scheduleSummary.Add("EndDate", schedule.EndDate); scheduleSummary.Add("NextPaymentDate", schedule.NextPaymentDate); if ( schedule.NextPaymentDate.HasValue ) { scheduleSummary.Add( "DaysTillNextPayment", (schedule.NextPaymentDate.Value - DateTime.Now).Days ); } else { scheduleSummary.Add( "DaysTillNextPayment", null ); } DateTime? lastPaymentDate = schedule.Transactions.Max(t => t.TransactionDateTime); scheduleSummary.Add("LastPaymentDate", lastPaymentDate); if ( lastPaymentDate.HasValue ) { scheduleSummary.Add("DaysSinceLastPayment", (DateTime.Now - lastPaymentDate.Value).Days); } else { scheduleSummary.Add( "DaysSinceLastPayment", null ); } scheduleSummary.Add("CurrencyType", ( schedule.FinancialPaymentDetail != null && schedule.FinancialPaymentDetail.CurrencyTypeValue != null ) ? schedule.FinancialPaymentDetail.CurrencyTypeValue.Value : "" ); scheduleSummary.Add( "CreditCardType", ( schedule.FinancialPaymentDetail != null && schedule.FinancialPaymentDetail.CreditCardTypeValue != null) ? schedule.FinancialPaymentDetail.CreditCardTypeValue.Value : "" ); scheduleSummary.Add("UrlEncryptedKey", schedule.UrlEncodedKey); scheduleSummary.Add("Frequency", schedule.TransactionFrequencyValue.Value); scheduleSummary.Add("FrequencyDescription", schedule.TransactionFrequencyValue.Description); List<Dictionary<string, object>> summaryDetails = new List<Dictionary<string,object>>(); foreach ( FinancialScheduledTransactionDetail detail in schedule.ScheduledTransactionDetails ) { Dictionary<string, object> detailSummary = new Dictionary<string,object>(); detailSummary.Add("AccountId", detail.Id); detailSummary.Add("AccountName", detail.Account.Name); detailSummary.Add("Amount", detail.Amount); detailSummary.Add("Summary", detail.Summary); summaryDetails.Add( detailSummary ); totalAmount += detail.Amount; } scheduleSummary.Add("ScheduledAmount", totalAmount); scheduleSummary.Add( "TransactionDetails", summaryDetails ); scheduleSummaries.Add( scheduleSummary ); } rockContext.SaveChanges(); } // added linked pages to mergefields Dictionary<string, object> linkedPages = new Dictionary<string, object>(); linkedPages.Add( "ManageScheduledTransactionsPage", LinkedPageRoute( "ManageScheduledTransactionsPage" ) ); linkedPages.Add( "TransactionHistoryPage", LinkedPageRoute( "TransactionHistoryPage" ) ); linkedPages.Add( "TransactionEntryPage", LinkedPageRoute( "TransactionEntryPage" ) ); var scheduleValues = new Dictionary<string, object>(); scheduleValues.Add( "ScheduledTransactions", scheduleSummaries.ToList() ); scheduleValues.Add( "LinkedPages", linkedPages ); // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line scheduleValues.Add( "Person", CurrentPerson ); scheduleValues.Add( "CurrentPerson", CurrentPerson ); string content = GetAttributeValue( "Template" ).ResolveMergeFields( scheduleValues ); // show merge fields if needed if ( GetAttributeValue( "EnableDebug" ).AsBoolean() && IsUserAuthorized( Authorization.EDIT ) ) { // TODO: When support for "Person" is not supported anymore (should use "CurrentPerson" instead), remove this line scheduleValues.Remove( "Person" ); content += scheduleValues.lavaDebugInfo(); } lContent.Text = content; }
/// <summary> /// Handles the Click event of the lbCancelSchedule control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbCancelSchedule_Click( object sender, EventArgs e ) { int? txnId = PageParameter( "ScheduledTransactionId" ).AsIntegerOrNull(); if ( txnId.HasValue ) { using ( var rockContext = new RockContext() ) { var txnService = new FinancialScheduledTransactionService( rockContext ); var txn = txnService .Queryable( "AuthorizedPersonAlias.Person,FinancialGateway" ) .FirstOrDefault( t => t.Id == txnId.Value ); if ( txn != null ) { if ( txn.FinancialGateway != null ) { txn.FinancialGateway.LoadAttributes( rockContext ); } string errorMessage = string.Empty; if ( txnService.Cancel( txn, out errorMessage ) ) { txnService.GetStatus( txn, out errorMessage ); rockContext.SaveChanges(); } else { ShowErrorMessage( errorMessage ); } ShowView( txn ); } } } }
/// <summary> /// Processes the confirmation. /// </summary> /// <param name="errorMessage">The error message.</param> /// <returns></returns> private bool ProcessConfirmation( out string errorMessage ) { var rockContext = new RockContext(); errorMessage = string.Empty; if ( string.IsNullOrWhiteSpace( TransactionCode ) ) { if ( Gateway == null ) { errorMessage = "There was a problem creating the payment gateway information"; return false; } var personService = new PersonService( rockContext ); var transactionService = new FinancialScheduledTransactionService( rockContext ); var transactionDetailService = new FinancialScheduledTransactionDetailService( rockContext ); FinancialScheduledTransaction scheduledTransaction = null; if ( ScheduledTransactionId.HasValue ) { scheduledTransaction = transactionService.Get( ScheduledTransactionId.Value ); } if ( scheduledTransaction == null ) { errorMessage = "There was a problem getting the transaction information"; return false; } if ( scheduledTransaction.AuthorizedPerson == null ) { errorMessage = "There was a problem determining the person associated with the transaction"; return false; } var changeSummary = new StringBuilder(); // Get the payment schedule scheduledTransaction.TransactionFrequencyValueId = btnFrequency.SelectedValueAsId().Value; changeSummary.Append( DefinedValueCache.Read( scheduledTransaction.TransactionFrequencyValueId, rockContext ) ); if ( dtpStartDate.SelectedDate.HasValue && dtpStartDate.SelectedDate > RockDateTime.Today ) { scheduledTransaction.StartDate = dtpStartDate.SelectedDate.Value; changeSummary.AppendFormat( " starting {0}", scheduledTransaction.StartDate.ToShortDateString() ); } else { scheduledTransaction.StartDate = DateTime.MinValue; } changeSummary.AppendLine(); PaymentInfo paymentInfo = GetPaymentInfo( personService, scheduledTransaction ); if ( paymentInfo == null ) { errorMessage = "There was a problem creating the payment information"; return false; } else { } // If transaction is not active, attempt to re-activate it first if ( !scheduledTransaction.IsActive ) { if ( !transactionService.Reactivate( scheduledTransaction, out errorMessage ) ) { return false; } } if ( Gateway.UpdateScheduledPayment( scheduledTransaction, paymentInfo, out errorMessage ) ) { if ( paymentInfo.CurrencyTypeValue != null ) { changeSummary.Append( paymentInfo.CurrencyTypeValue.Value ); scheduledTransaction.CurrencyTypeValueId = paymentInfo.CurrencyTypeValue.Id; DefinedValueCache creditCardTypeValue = paymentInfo.CreditCardTypeValue; if ( creditCardTypeValue != null ) { changeSummary.AppendFormat( " - {0}", creditCardTypeValue.Value ); scheduledTransaction.CreditCardTypeValueId = creditCardTypeValue.Id; } else { scheduledTransaction.CreditCardTypeValueId = null; } changeSummary.AppendFormat( " {0}", paymentInfo.MaskedNumber ); changeSummary.AppendLine(); } var selectedAccountIds = SelectedAccounts .Where( a => a.Amount > 0 ) .Select( a => a.Id ).ToList(); var deletedAccounts = scheduledTransaction.ScheduledTransactionDetails .Where( a => !selectedAccountIds.Contains( a.AccountId ) ).ToList(); foreach ( var deletedAccount in deletedAccounts ) { scheduledTransaction.ScheduledTransactionDetails.Remove( deletedAccount ); transactionDetailService.Delete( deletedAccount ); } foreach ( var account in SelectedAccounts ) { var detail = scheduledTransaction.ScheduledTransactionDetails .Where( d => d.AccountId == account.Id ).FirstOrDefault(); if ( detail == null ) { detail = new FinancialScheduledTransactionDetail(); detail.AccountId = account.Id; scheduledTransaction.ScheduledTransactionDetails.Add( detail ); } detail.Amount = account.Amount; changeSummary.AppendFormat( "{0}: {1:C2}", account.Name, account.Amount ); changeSummary.AppendLine(); } rockContext.SaveChanges(); // Add a note about the change var noteTypeService = new NoteTypeService( rockContext ); var noteType = noteTypeService.Get( scheduledTransaction.TypeId, "Note" ); var noteService = new NoteService( rockContext ); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Updated Transaction"; note.Text = changeSummary.ToString(); noteService.Add( note ); rockContext.SaveChanges(); ScheduleId = scheduledTransaction.GatewayScheduleId; TransactionCode = scheduledTransaction.TransactionCode; if (transactionService.GetStatus( scheduledTransaction, out errorMessage )) { rockContext.SaveChanges(); } } else { return false; } tdTransactionCode.Description = TransactionCode; tdTransactionCode.Visible = !string.IsNullOrWhiteSpace( TransactionCode ); tdScheduleId.Description = ScheduleId; tdScheduleId.Visible = !string.IsNullOrWhiteSpace( ScheduleId ); return true; } else { pnlDupWarning.Visible = true; return false; } }
/// <summary> /// Gets the scheduled transaction. /// </summary> /// <param name="refresh">if set to <c>true</c> [refresh].</param> /// <returns></returns> private FinancialScheduledTransaction GetScheduledTransaction( bool refresh = false ) { Person targetPerson = null; var rockContext = new RockContext(); // If impersonation is allowed, and a valid person key was used, set the target to that person bool allowImpersonation = false; if ( bool.TryParse( GetAttributeValue( "Impersonation" ), out allowImpersonation ) && allowImpersonation ) { string personKey = PageParameter( "Person" ); if ( !string.IsNullOrWhiteSpace( personKey ) ) { targetPerson = new PersonService( rockContext ).GetByUrlEncodedKey( personKey ); } } if ( targetPerson == null ) { targetPerson = CurrentPerson; } // Verify that transaction id is valid for selected person if ( targetPerson != null ) { int txnId = int.MinValue; if ( int.TryParse( PageParameter( "ScheduledTransactionId" ), out txnId ) ) { var service = new FinancialScheduledTransactionService( rockContext ); var scheduledTransaction = service.Queryable( "ScheduledTransactionDetails,GatewayEntityType,CurrencyTypeValue,CreditCardTypeValue" ) .Where( t => t.Id == txnId && ( t.AuthorizedPersonId == targetPerson.Id || t.AuthorizedPerson.GivingGroupId == targetPerson.GivingGroupId ) ) .FirstOrDefault(); if ( scheduledTransaction != null ) { TargetPersonId = scheduledTransaction.AuthorizedPersonId; ScheduledTransactionId = scheduledTransaction.Id; if ( refresh ) { string errorMessages = string.Empty; service.GetStatus( scheduledTransaction, out errorMessages ); rockContext.SaveChanges(); } return scheduledTransaction; } } } return null; }
/// <summary> /// Gets the scheduled transaction. /// </summary> /// <param name="refresh">if set to <c>true</c> [refresh].</param> /// <returns></returns> private FinancialScheduledTransaction GetScheduledTransaction( bool refresh = false ) { Person targetPerson = null; using ( var rockContext = new RockContext() ) { // If impersonation is allowed, and a valid person key was used, set the target to that person bool allowImpersonation = GetAttributeValue( "Impersonation" ).AsBoolean(); if ( allowImpersonation ) { string personKey = PageParameter( "Person" ); if ( !string.IsNullOrWhiteSpace( personKey ) ) { targetPerson = new PersonService( rockContext ).GetByUrlEncodedKey( personKey ); } } if ( targetPerson == null ) { targetPerson = CurrentPerson; } // Verify that transaction id is valid for selected person if ( targetPerson != null ) { int txnId = int.MinValue; if ( int.TryParse( PageParameter( "ScheduledTransactionId" ), out txnId ) ) { var personService = new PersonService( rockContext ); var validGivingIds = new List<string> { targetPerson.GivingId }; validGivingIds.AddRange( personService.GetBusinesses( targetPerson.Id ).Select( b => b.GivingId ) ); var service = new FinancialScheduledTransactionService( rockContext ); var scheduledTransaction = service .Queryable( "AuthorizedPersonAlias.Person,ScheduledTransactionDetails,FinancialGateway,FinancialPaymentDetail.CurrencyTypeValue,FinancialPaymentDetail.CreditCardTypeValue" ) .Where( t => t.Id == txnId && t.AuthorizedPersonAlias != null && t.AuthorizedPersonAlias.Person != null && validGivingIds.Contains( t.AuthorizedPersonAlias.Person.GivingId ) ) .FirstOrDefault(); if ( scheduledTransaction != null ) { if ( scheduledTransaction.AuthorizedPersonAlias != null ) { TargetPersonId = scheduledTransaction.AuthorizedPersonAlias.PersonId; } ScheduledTransactionId = scheduledTransaction.Id; if ( scheduledTransaction.FinancialGateway != null ) { scheduledTransaction.FinancialGateway.LoadAttributes( rockContext ); } if ( refresh ) { string errorMessages = string.Empty; service.GetStatus( scheduledTransaction, out errorMessages ); rockContext.SaveChanges(); } return scheduledTransaction; } } } } return null; }
/// <summary> /// Handles the Click event of the lbCancel control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void lbCancel_Click( object sender, EventArgs e ) { int? txnId = PageParameter( "ScheduledTransactionId" ).AsIntegerOrNull(); if ( txnId.HasValue ) { var rockContext = new RockContext(); var txnService = new FinancialScheduledTransactionService( rockContext ); var txn = txnService.Get( txnId.Value ); if ( txn != null ) { string errorMessage = string.Empty; if ( txnService.Cancel( txn, out errorMessage ) ) { txnService.GetStatus( txn, out errorMessage ); rockContext.SaveChanges(); } else { ShowErrorMessage( errorMessage ); } ShowView( txn ); } } }