/// <summary> /// Cancels the specified scheduled transaction. /// </summary> /// <param name="scheduledTransaction">The scheduled transaction.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public bool Cancel(FinancialScheduledTransaction scheduledTransaction, out string errorMessages) { if (scheduledTransaction.GatewayEntityType != null) { var gateway = Rock.Financial.GatewayContainer.GetComponent(scheduledTransaction.GatewayEntityType.Guid.ToString()); if (gateway != null && gateway.IsActive) { if (gateway.CancelScheduledPayment(scheduledTransaction, out errorMessages)) { var noteTypeService = new NoteTypeService((RockContext)this.Context); var noteType = noteTypeService.Get(scheduledTransaction.TypeId, "Note"); var noteService = new NoteService((RockContext)this.Context); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Cancelled Transaction"; noteService.Add(note); return(true); } else { return(false); } } } errorMessages = "Gateway is invalid or not active"; return(false); }
/// <summary> /// Cancels the specified scheduled transaction. /// </summary> /// <param name="scheduledTransaction">The scheduled transaction.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public bool Cancel( FinancialScheduledTransaction scheduledTransaction, out string errorMessages ) { if ( scheduledTransaction != null && scheduledTransaction.FinancialGateway != null && scheduledTransaction.FinancialGateway.IsActive ) { if ( scheduledTransaction.FinancialGateway.Attributes == null ) { scheduledTransaction.FinancialGateway.LoadAttributes( (RockContext)this.Context ); } var gateway = scheduledTransaction.FinancialGateway.GetGatewayComponent(); if ( gateway != null ) { if ( gateway.CancelScheduledPayment( scheduledTransaction, out errorMessages ) ) { var noteTypeService = new NoteTypeService( (RockContext)this.Context ); var noteType = noteTypeService.Get( Rock.SystemGuid.NoteType.SCHEDULED_TRANSACTION_NOTE.AsGuid() ); if ( noteType != null ) { var noteService = new NoteService( (RockContext)this.Context ); var note = new Note(); note.NoteTypeId = noteType.Id; note.EntityId = scheduledTransaction.Id; note.Caption = "Cancelled Transaction"; noteService.Add( note ); } return true; } else { return false; } } } errorMessages = "Gateway is invalid or not active"; return false; }
/// <summary> /// Saves the person notes and history. /// </summary> /// <param name="registrationPersonFirstName">First name of the registration person.</param> /// <param name="registrationPersonLastName">Last name of the registration person.</param> /// <param name="currentPersonAliasId">The current person alias identifier.</param> /// <param name="previousRegistrantPersonIds">The previous registrant person ids.</param> public void SavePersonNotesAndHistory(string registrationPersonFirstName, string registrationPersonLastName, int?currentPersonAliasId, List <int> previousRegistrantPersonIds) { // Setup Note settings Registration registration = this; NoteTypeCache noteType = null; using (RockContext rockContext = new RockContext()) { RegistrationInstance registrationInstance = registration.RegistrationInstance ?? new RegistrationInstanceService(rockContext).Get(registration.RegistrationInstanceId); RegistrationTemplate registrationTemplate = registrationInstance.RegistrationTemplate ?? new RegistrationTemplateService(rockContext).Get(registrationInstance.RegistrationTemplateId); if (registrationTemplate != null && registrationTemplate.AddPersonNote) { noteType = NoteTypeCache.Get(Rock.SystemGuid.NoteType.PERSON_EVENT_REGISTRATION.AsGuid()); if (noteType != null) { var noteService = new NoteService(rockContext); var personAliasService = new PersonAliasService(rockContext); Person registrar = null; if (registration.PersonAliasId.HasValue) { registrar = personAliasService.GetPerson(registration.PersonAliasId.Value); } var registrantNames = new List <string>(); // Get each registrant foreach (var registrantPersonAliasId in registration.Registrants .Where(r => r.PersonAliasId.HasValue) .Select(r => r.PersonAliasId.Value) .ToList()) { var registrantPerson = personAliasService.GetPerson(registrantPersonAliasId); if (registrantPerson != null && (previousRegistrantPersonIds == null || !previousRegistrantPersonIds.Contains(registrantPerson.Id))) { var noteText = new StringBuilder(); noteText.AppendFormat("Registered for {0}", registrationInstance.Name); string registrarFullName = string.Empty; if (registrar != null && registrar.Id != registrantPerson.Id) { registrarFullName = string.Format(" by {0}", registrar.FullName); registrantNames.Add(registrantPerson.FullName); } if (registrar != null && (registrationPersonFirstName != registrar.NickName || registrationPersonLastName != registrar.LastName)) { registrarFullName = string.Format(" by {0}", registrationPersonFirstName + " " + registrationPersonLastName); } noteText.Append(registrarFullName); if (noteText.Length > 0) { var note = new Note(); note.NoteTypeId = noteType.Id; note.IsSystem = false; note.IsAlert = false; note.IsPrivateNote = false; note.EntityId = registrantPerson.Id; note.Caption = string.Empty; note.Text = noteText.ToString(); if (registrar == null) { note.CreatedByPersonAliasId = currentPersonAliasId; } else { note.CreatedByPersonAliasId = registrar.PrimaryAliasId; } noteService.Add(note); } var changes = new History.HistoryChangeList(); changes.AddChange(History.HistoryVerb.Registered, History.HistoryChangeType.Record, null); HistoryService.SaveChanges( rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(), registrantPerson.Id, changes, registrationInstance.Name, typeof(Registration), registration.Id, false, currentPersonAliasId, rockContext.SourceOfChange); } } if (registrar != null && registrantNames.Any()) { string namesText = string.Empty; if (registrantNames.Count >= 2) { int lessOne = registrantNames.Count - 1; namesText = registrantNames.Take(lessOne).ToList().AsDelimited(", ") + " and " + registrantNames.Skip(lessOne).Take(1).First() + " "; } else { namesText = registrantNames.First() + " "; } var note = new Note(); note.NoteTypeId = noteType.Id; note.IsSystem = false; note.IsAlert = false; note.IsPrivateNote = false; note.EntityId = registrar.Id; note.Caption = string.Empty; note.Text = string.Format("Registered {0} for {1}", namesText, registrationInstance.Name); noteService.Add(note); var changes = new History.HistoryChangeList(); changes.AddChange(History.HistoryVerb.Registered, History.HistoryChangeType.Record, namesText); HistoryService.SaveChanges( rockContext, typeof(Person), Rock.SystemGuid.Category.HISTORY_PERSON_REGISTRATION.AsGuid(), registrar.Id, changes, registrationInstance.Name, typeof(Registration), registration.Id, false, currentPersonAliasId, rockContext.SourceOfChange); } rockContext.SaveChanges(); } } } }