/// <summary> /// Executes the specified context. /// </summary> /// <param name="context">The context.</param> public void Execute(IJobExecutionContext context) { var rockContext = new RockContext(); var transactionService = new FinancialTransactionService(rockContext); var futureTransactions = transactionService.GetFutureTransactions().Where(ft => ft.FutureProcessingDateTime <= RockDateTime.Now).ToList(); var errors = new List <string>(); var successCount = 0; foreach (var futureTransaction in futureTransactions) { var automatedPaymentProcessor = new AutomatedPaymentProcessor(futureTransaction, rockContext); automatedPaymentProcessor.ProcessCharge(out var errorMessage); if (!string.IsNullOrEmpty(errorMessage)) { errors.Add(errorMessage); } else { successCount++; } } context.Result = string.Format("{0} future transactions charged", successCount); if (errors.Any()) { var sb = new StringBuilder(); sb.AppendLine(); sb.AppendLine(string.Format("{0} Errors: ", errors.Count())); errors.ForEach(e => sb.AppendLine(e)); var errorMessage = sb.ToString(); context.Result += errorMessage; var exception = new Exception(errorMessage); var context2 = HttpContext.Current; ExceptionLogService.LogException(exception, context2); throw exception; } }