Пример #1
0
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            string batchNamePrefix = GetAttributeValue("BatchNamePrefix");
            Guid?  receiptEmail    = GetAttributeValue("ReceiptEmail").AsGuidOrNull();

            DateTime?startDateTime = drpDates.LowerValue;
            DateTime?endDateTime   = drpDates.UpperValue;

            if (startDateTime.HasValue && endDateTime.HasValue && endDateTime.Value.CompareTo(startDateTime.Value) >= 0)
            {
                var financialGateway = GetSelectedGateway();
                if (financialGateway != null)
                {
                    var gateway = financialGateway.GetGatewayComponent();
                    if (gateway != null)
                    {
                        DateTime start = startDateTime.Value;
                        DateTime end   = endDateTime.Value.AddDays(1);

                        string errorMessage = string.Empty;
                        var    payments     = gateway.GetPayments(financialGateway, start, end, out errorMessage);

                        if (string.IsNullOrWhiteSpace(errorMessage))
                        {
                            var qryParam = new Dictionary <string, string>();
                            qryParam.Add("batchId", "9999");
                            string batchUrlFormat = LinkedPageUrl("BatchDetailPage", qryParam).Replace("9999", "{0}");

                            string resultSummary = FinancialScheduledTransactionService.ProcessPayments(financialGateway, batchNamePrefix, payments, batchUrlFormat, receiptEmail);

                            if (!string.IsNullOrWhiteSpace(resultSummary))
                            {
                                nbSuccess.Text = string.Format("<ul>{0}</ul>", resultSummary);
                            }
                            else
                            {
                                nbSuccess.Text = string.Format("There were not any transactions downloaded.", resultSummary);
                            }
                            nbSuccess.Visible = true;
                        }
                        else
                        {
                            ShowError(errorMessage);
                        }
                    }
                    else
                    {
                        ShowError("Selected Payment Gateway does not have a valid payment processor!");
                    }
                }
                else
                {
                    ShowError("Please select a valid Payment Gateway!");
                }
            }
            else
            {
                ShowError("Please select a valid Date Range!");
            }
        }
Пример #2
0
        /// <summary>
        /// Job that updates the JobPulse setting with the current date/time.
        /// This will allow us to notify an admin if the jobs stop running.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            try
            {
                // get the job map
                JobDataMap dataMap = context.JobDetail.JobDataMap;

                using (var rockContext = new RockContext())
                {
                    foreach (var financialGateway in new FinancialGatewayService(rockContext)
                             .Queryable()
                             .Where(g => g.IsActive))
                    {
                        financialGateway.LoadAttributes(rockContext);

                        var gateway = financialGateway.GetGatewayComponent();
                        if (gateway != null)
                        {
                            int daysBack = dataMap.GetString("DaysBack").AsIntegerOrNull() ?? 1;

                            DateTime today       = RockDateTime.Today;
                            TimeSpan days        = new TimeSpan(daysBack, 0, 0, 0);
                            DateTime endDateTime = today.Add(financialGateway.GetBatchTimeOffset());
                            endDateTime = RockDateTime.Now.CompareTo(endDateTime) < 0 ? endDateTime.AddDays(-1) : today;
                            DateTime startDateTime = endDateTime.Subtract(days);

                            string errorMessage = string.Empty;
                            var    payments     = gateway.GetPayments(financialGateway, startDateTime, endDateTime, out errorMessage);

                            if (string.IsNullOrWhiteSpace(errorMessage))
                            {
                                Guid?  systemEmailGuid = dataMap.GetString("ReceiptEmail").AsGuidOrNull();
                                string batchNamePrefix = dataMap.GetString("BatchNamePrefix");
                                FinancialScheduledTransactionService.ProcessPayments(financialGateway, batchNamePrefix, payments, string.Empty, systemEmailGuid);
                            }
                            else
                            {
                                throw new Exception(errorMessage);
                            }
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }
Пример #3
0
        /// <summary>
        /// Job that updates the JobPulse setting with the current date/time.
        /// This will allow us to notify an admin if the jobs stop running.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            try
            {
                // get the job map
                JobDataMap dataMap = context.JobDetail.JobDataMap;

                string gatewayGuid = dataMap.GetString("PaymentGateway");
                if (!string.IsNullOrWhiteSpace(gatewayGuid))
                {
                    GatewayComponent gateway = GatewayContainer.GetComponent(gatewayGuid);
                    if (gateway != null)
                    {
                        int daysBack = dataMap.GetString("DaysBack").AsIntegerOrNull() ?? 1;

                        DateTime today       = RockDateTime.Today;
                        TimeSpan days        = new TimeSpan(daysBack, 0, 0, 0);
                        DateTime endDateTime = today.Add(gateway.BatchTimeOffset);
                        endDateTime = RockDateTime.Now.CompareTo(endDateTime) < 0 ? endDateTime.AddDays(-1) : today;
                        DateTime startDateTime = endDateTime.Subtract(days);

                        string errorMessage = string.Empty;
                        var    payments     = gateway.GetPayments(startDateTime, endDateTime, out errorMessage);

                        if (string.IsNullOrWhiteSpace(errorMessage))
                        {
                            string batchNamePrefix = dataMap.GetString("BatchNamePrefix");
                            FinancialScheduledTransactionService.ProcessPayments(gateway, batchNamePrefix, payments);
                        }
                        else
                        {
                            throw new Exception(errorMessage);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogService.LogException(ex, null);
            }
        }
Пример #4
0
        /// <summary>
        /// Job that updates the JobPulse setting with the current date/time.
        /// This will allow us to notify an admin if the jobs stop running.
        ///
        /// Called by the <see cref="IScheduler" /> when a
        /// <see cref="ITrigger" /> fires that is associated with
        /// the <see cref="IJob" />.
        /// </summary>
        public virtual void Execute(IJobExecutionContext context)
        {
            var exceptionMsgs = new List <string>();

            // get the job map
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            int        scheduledPaymentsProcessed = 0;

            using (var rockContext = new RockContext())
            {
                foreach (var financialGateway in new FinancialGatewayService(rockContext)
                         .Queryable()
                         .Where(g => g.IsActive))
                {
                    try
                    {
                        financialGateway.LoadAttributes(rockContext);

                        var gateway = financialGateway.GetGatewayComponent();
                        if (gateway != null)
                        {
                            int daysBack = dataMap.GetString("DaysBack").AsIntegerOrNull() ?? 1;

                            DateTime today       = RockDateTime.Today;
                            TimeSpan days        = new TimeSpan(daysBack, 0, 0, 0);
                            DateTime endDateTime = today.Add(financialGateway.GetBatchTimeOffset());

                            // If the calculated end time has not yet occurred, use the previous day.
                            endDateTime = RockDateTime.Now.CompareTo(endDateTime) >= 0 ? endDateTime : endDateTime.AddDays(-1);

                            DateTime startDateTime = endDateTime.Subtract(days);

                            string errorMessage = string.Empty;
                            var    payments     = gateway.GetPayments(financialGateway, startDateTime, endDateTime, out errorMessage);

                            if (string.IsNullOrWhiteSpace(errorMessage))
                            {
                                Guid?receiptEmail              = dataMap.GetString("ReceiptEmail").AsGuidOrNull();
                                Guid?failedPaymentEmail        = dataMap.GetString("FailedPaymentEmail").AsGuidOrNull();
                                Guid?failedPaymentWorkflowType = dataMap.GetString("FailedPaymentWorkflow").AsGuidOrNull();

                                string batchNamePrefix = dataMap.GetString("BatchNamePrefix");
                                FinancialScheduledTransactionService.ProcessPayments(financialGateway, batchNamePrefix, payments, string.Empty, receiptEmail, failedPaymentEmail, failedPaymentWorkflowType);
                                scheduledPaymentsProcessed += payments.Count();
                            }
                            else
                            {
                                throw new Exception(errorMessage);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogService.LogException(ex, null);
                        exceptionMsgs.Add(ex.Message);
                    }
                }
            }

            if (exceptionMsgs.Any())
            {
                throw new Exception("One or more exceptions occurred while downloading transactions..." + Environment.NewLine + exceptionMsgs.AsDelimited(Environment.NewLine));
            }

            context.Result = string.Format("{0} payments processed", scheduledPaymentsProcessed);
        }
Пример #5
0
        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <exception cref="Exception">
        /// One or more exceptions occurred while downloading transactions..." + Environment.NewLine + exceptionMsgs.AsDelimited( Environment.NewLine )
        /// </exception>
        public virtual void Execute(IJobExecutionContext context)
        {
            var exceptionMsgs = new List <string>();

            // get the job map
            var dataMap = context.JobDetail.JobDataMap;
            var scheduledPaymentsProcessed = 0;

            Guid?receiptEmail              = dataMap.GetString(AttributeKey.ReceiptEmail).AsGuidOrNull();
            Guid?failedPaymentEmail        = dataMap.GetString(AttributeKey.FailedPaymentEmail).AsGuidOrNull();
            Guid?failedPaymentWorkflowType = dataMap.GetString(AttributeKey.FailedPaymentWorkflow).AsGuidOrNull();
            int  daysBack = dataMap.GetString(AttributeKey.DaysBack).AsIntegerOrNull() ?? 1;

            DateTime today            = RockDateTime.Today;
            TimeSpan daysBackTimeSpan = new TimeSpan(daysBack, 0, 0, 0);

            string batchNamePrefix = dataMap.GetString(AttributeKey.BatchNamePrefix);
            Dictionary <FinancialGateway, string> processedPaymentsSummary = new Dictionary <FinancialGateway, string>();


            using (var rockContext = new RockContext())
            {
                var targetGatewayQuery = new FinancialGatewayService(rockContext).Queryable().Where(g => g.IsActive).AsNoTracking();

                var targetGatewayGuid = dataMap.GetString(AttributeKey.TargetGateway).AsGuidOrNull();
                if (targetGatewayGuid.HasValue)
                {
                    targetGatewayQuery = targetGatewayQuery.Where(g => g.Guid == targetGatewayGuid.Value);
                }

                foreach (var financialGateway in targetGatewayQuery.ToList())
                {
                    try
                    {
                        financialGateway.LoadAttributes(rockContext);

                        var gateway = financialGateway.GetGatewayComponent();
                        if (gateway == null)
                        {
                            continue;
                        }

                        DateTime endDateTime = today.Add(financialGateway.GetBatchTimeOffset());

                        // If the calculated end time has not yet occurred, use the previous day.
                        endDateTime = RockDateTime.Now.CompareTo(endDateTime) >= 0 ? endDateTime : endDateTime.AddDays(-1);

                        DateTime startDateTime = endDateTime.Subtract(daysBackTimeSpan);

                        string errorMessage = string.Empty;
                        List <Financial.Payment> payments = gateway.GetPayments(financialGateway, startDateTime, endDateTime, out errorMessage);

                        if (string.IsNullOrWhiteSpace(errorMessage))
                        {
                            var gatewayProcessPaymentsSummary = FinancialScheduledTransactionService.ProcessPayments(financialGateway, batchNamePrefix, payments, string.Empty, receiptEmail, failedPaymentEmail, failedPaymentWorkflowType);
                            processedPaymentsSummary.Add(financialGateway, gatewayProcessPaymentsSummary);
                            scheduledPaymentsProcessed += payments.Count();
                        }
                        else
                        {
                            throw new Exception(errorMessage);
                        }
                    }
                    catch (Exception ex)
                    {
                        ExceptionLogService.LogException(ex, null);
                        exceptionMsgs.Add(ex.Message);
                    }
                }
            }

            if (exceptionMsgs.Any())
            {
                throw new Exception("One or more exceptions occurred while downloading transactions..." + Environment.NewLine + exceptionMsgs.AsDelimited(Environment.NewLine));
            }

            StringBuilder summary = new StringBuilder();

            foreach (var item in processedPaymentsSummary)
            {
                summary.AppendLine($"Summary for {item.Key.Name}:<br/>{item.Value}");
            }

            context.Result = summary.ToString();
        }