Exemple #1
0
        /// <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);
                    }
                }
            }
        }
Exemple #2
0
        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");

            var rockContext = new Rock.Data.RockContext();
            FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService(rockContext);
            var currentTransaction = fstService.Get(Int32.Parse(hfScheduledTransactionId.Value));

            string errorMessage = string.Empty;

            if (fstService.Cancel(currentTransaction, out errorMessage))
            {
                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;
        }
        /// <summary>
        /// Handles the Click event of the bbtnDelete 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 bbtnDelete_Click(object sender, EventArgs e)
        {
            /* 2021-08-27 MDP
             *
             * We really don't want to actually delete a FinancialScheduledTransaction.
             * Just inactivate it, even if there aren't FinancialTransactions associated with it.
             * It is possible the the Gateway has processed a transaction on it that Rock doesn't know about yet.
             * If that happens, Rock won't be able to match a record for that downloaded transaction!
             * We also might want to match inactive or "deleted" schedules on the Gateway to a person in Rock,
             * so we'll need the ScheduledTransaction to do that.
             *
             * So, don't delete ScheduledTransactions.
             *
             */

            BootstrapButton bbtnDelete = ( BootstrapButton )sender;
            RepeaterItem    riItem     = ( RepeaterItem )bbtnDelete.NamingContainer;

            HiddenField hfScheduledTransactionId = ( HiddenField )riItem.FindControl("hfScheduledTransactionId");
            Literal     lLavaContent             = ( Literal )riItem.FindControl("lLavaContent");
            Button      btnEdit = ( Button )riItem.FindControl("btnEdit");

            using (var rockContext = new Rock.Data.RockContext())
            {
                FinancialScheduledTransactionService fstService = new FinancialScheduledTransactionService(rockContext);
                var currentTransaction = fstService.Get(hfScheduledTransactionId.Value.AsInteger());
                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
                    {
                        // Ignore
                    }

                    rockContext.SaveChanges();
                    lLavaContent.Text = string.Format("<div class='alert alert-success'>Your scheduled {0} has been deleted.</div>", GetAttributeValue(AttributeKey.TransactionLabel).ToLower());
                }
                else
                {
                    lLavaContent.Text = string.Format("<div class='alert alert-danger'>An error occurred while deleting your scheduled transaction. Message: {0}</div>", errorMessage);
                }
            }

            bbtnDelete.Visible = false;
            btnEdit.Visible    = false;
        }
        /// <summary>
        /// Event when the user clicks to delete (but really inactivates) the scheduled transaction
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptScheduledTransaction_Inactivate(object sender, CommandEventArgs e)
        {
            var scheduledTransactionGuid = e.CommandArgument.ToStringSafe().AsGuid();
            var rockContext = new RockContext();
            var financialScheduledTransactionService = new FinancialScheduledTransactionService(rockContext);
            var financialScheduledTransaction        = financialScheduledTransactionService.Get(scheduledTransactionGuid);

            if (financialScheduledTransaction?.FinancialGateway == null)
            {
                return;
            }

            string errorMessage;

            /* 2021-08-27 MDP
             *
             * We really don't want to actually delete a FinancialScheduledTransaction.
             * Just inactivate it, even if there aren't FinancialTransactions associated with it.
             * It is possible the the Gateway has processed a transaction on it that Rock doesn't know about yet.
             * If that happens, Rock won't be able to match a record for that downloaded transaction!
             * We also might want to match inactive or "deleted" schedules on the Gateway to a person in Rock,
             * so we'll need the ScheduledTransaction to do that.
             *
             * So, don't delete ScheduledTransactions.
             *
             * However, if ScheduledTransaction does not currently have any FinancialTransactions associated with it,
             * we can *say* we are deleting it in the messages. Also, when doing a 'Show Inactive Scheduled Transactions'
             * we won't list Scheduled Transactions that are Inactive AND don't currently have financial transactions
             * associated with it. If a transactions come in later, then we'll end up showing it as an inactive scheduled
             * transaction again.
             *
             */

            if (financialScheduledTransactionService.Cancel(financialScheduledTransaction, out errorMessage))
            {
                try
                {
                    financialScheduledTransactionService.GetStatus(financialScheduledTransaction, out errorMessage);
                }
                catch
                {
                    // Ignore
                }

                rockContext.SaveChanges();
            }
            else
            {
                mdWarningAlert.Show(errorMessage, ModalAlertType.Information);
            }

            ShowDetail();
        }
Exemple #5
0
        public virtual void Execute(IJobExecutionContext context)
        {
            List <string> messages       = new List <string>();
            int           completedCount = 0;

            using (var rockContext = new RockContext())
            {
                var txnService = new FinancialScheduledTransactionService(rockContext);
                var txns       = txnService
                                 .Queryable("FinancialGateway")
                                 .Where(t => t.IsActive)
                                 .ToList();

                foreach (var txn in txns)
                {
                    txn.LoadAttributes(rockContext);

                    var maxCount = txn.GetAttributeValue("com.shepherdchurch.MaxPaymentCount").AsInteger();

                    if (maxCount <= 0 || txn.Transactions.Count < maxCount)
                    {
                        continue;
                    }

                    string errorMessage = string.Empty;
                    if (txnService.Cancel(txn, out errorMessage))
                    {
                        txnService.GetStatus(txn, out errorMessage);
                        rockContext.SaveChanges();
                        completedCount += 1;
                    }
                    else
                    {
                        messages.Add(errorMessage);
                    }
                }
            }

            if (messages.Any())
            {
                throw new Exception(string.Join("\r\n", messages));
            }

            context.Result = string.Format("Marked {0} scheduled transactions as complete.", completedCount);
        }
        /// <summary>
        /// Handles the Click event of the bbtnDelete 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 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(hfScheduledTransactionId.Value.AsInteger());
                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
                    {
                        // Ignore
                    }

                    rockContext.SaveChanges();
                    content.Text = string.Format("<div class='alert alert-success'>Your recurring {0} has been deleted.</div>", GetAttributeValue(AttributeKey.TransactionLabel).ToLower());
                }
                else
                {
                    content.Text = string.Format("<div class='alert alert-danger'>An error occurred while deleting your scheduled transaction. Message: {0}</div>", errorMessage);
                }
            }

            bbtnDelete.Visible = false;
            btnEdit.Visible    = false;
        }
Exemple #7
0
        /// <summary>
        /// Handles the Click event of the btnCancelSchedule 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 btnCancelSchedule_Click(object sender, EventArgs e)
        {
            var financialScheduledTranactionGuid = GetScheduledTransactionGuidFromUrl();

            if (!financialScheduledTranactionGuid.HasValue)
            {
                return;
            }

            using (var rockContext = new RockContext())
            {
                var financialScheduledTransactionService = new FinancialScheduledTransactionService(rockContext);
                var financialScheduledTransaction        = financialScheduledTransactionService.Queryable()
                                                           .Include(a => a.AuthorizedPersonAlias.Person)
                                                           .Include(a => a.FinancialGateway)
                                                           .FirstOrDefault(t => t.Guid == financialScheduledTranactionGuid.Value);

                if (financialScheduledTransaction == null)
                {
                    return;
                }

                if (financialScheduledTransaction.FinancialGateway != null)
                {
                    financialScheduledTransaction.FinancialGateway.LoadAttributes(rockContext);
                }

                string errorMessage = string.Empty;
                if (financialScheduledTransactionService.Cancel(financialScheduledTransaction, out errorMessage))
                {
                    financialScheduledTransactionService.GetStatus(financialScheduledTransaction, out errorMessage);
                    rockContext.SaveChanges();
                }
                else
                {
                    ShowErrorMessage(errorMessage);
                }

                ShowView(financialScheduledTransaction);
            }
        }
Exemple #8
0
        /// <summary>
        /// Handles the Click event of the btnCancelSchedule 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 btnCancelSchedule_Click(object sender, EventArgs e)
        {
            int?financialScheduledTransactionId = PageParameter(PageParameterKey.ScheduledTransactionId).AsIntegerOrNull();

            if (financialScheduledTransactionId.HasValue)
            {
                using (var rockContext = new RockContext())
                {
                    var financialScheduledTransactionService = new FinancialScheduledTransactionService(rockContext);
                    var financialScheduledTransaction        = financialScheduledTransactionService.Queryable()
                                                               .Include(a => a.AuthorizedPersonAlias.Person)
                                                               .Include(a => a.FinancialGateway)
                                                               .FirstOrDefault(t => t.Id == financialScheduledTransactionId.Value);

                    if (financialScheduledTransaction != null)
                    {
                        if (financialScheduledTransaction.FinancialGateway != null)
                        {
                            financialScheduledTransaction.FinancialGateway.LoadAttributes(rockContext);
                        }

                        string errorMessage = string.Empty;
                        if (financialScheduledTransactionService.Cancel(financialScheduledTransaction, out errorMessage))
                        {
                            financialScheduledTransactionService.GetStatus(financialScheduledTransaction, out errorMessage);
                            rockContext.SaveChanges();
                        }
                        else
                        {
                            ShowErrorMessage(errorMessage);
                        }

                        ShowView(financialScheduledTransaction);
                    }
                }
            }
        }