Beispiel #1
0
        public static DataAccessResponseType ClearCreditCardExpirationRemindersLog()
        {
            var response = new DataAccessResponseType();

            try
            {
                //Clear the CreditCardExpirationRemindersLog log for records older than X days
                response.isSuccess = CardExpirationReminderEmailsLogManager.ClearReminderEmailsLog(Sahara.Core.Settings.Platform.GarbageCollection.CreditCardExpirationReminderEmailsLogDaysToPurge);
            }
            catch (Exception e)
            {
                //Log exception and email platform admins
                PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                    e,
                    "attempting to clear credit card expiration reminders log",
                    System.Reflection.MethodBase.GetCurrentMethod()
                    );

                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            return(response);
        }
Beispiel #2
0
        public static DataAccessResponseType SendCreditCardExpirationReminders()
        {
            var response = new DataAccessResponseType();

            try
            {
                foreach (int daysTillExpiration in Sahara.Core.Settings.Platform.Custodian.Dunning.ReminderDaysTillCardExpiration)
                {
                    var timeLeftDescription = string.Empty;

                    // 1. Get list of AccountID's that have a credit card within the window of time for this expiration reminder:
                    var accountsToRemind = Sql.Statements.SelectStatements.SelectAccountIDsForCreditCardExpirationReminders(daysTillExpiration);

                    if (accountsToRemind.Count > 0)
                    {
                        foreach (string accountID in accountsToRemind)
                        {
                            //Check email reminders log to see if this reminder epiration has already been sent to the account:
                            bool emailReminderSent = CardExpirationReminderEmailsLogManager.HasEmailBeenSent(accountID, daysTillExpiration);

                            if (!emailReminderSent)
                            {
                                //Get the account
                                //var account = AccountManager.GetAccountByID(accountID, false);
                                var account = AccountManager.GetAccount(accountID);

                                #region Generate Time Left Description

                                if (daysTillExpiration < 0)
                                {
                                    // description not used
                                }
                                else if (daysTillExpiration > 0 && daysTillExpiration <= 1)
                                {
                                    timeLeftDescription = "in about a day";
                                }
                                else if (daysTillExpiration > 1 && daysTillExpiration <= 2)
                                {
                                    timeLeftDescription = "in a couple of days";
                                }
                                else if (daysTillExpiration > 2 && daysTillExpiration <= 3)
                                {
                                    timeLeftDescription = "in a few days";
                                }
                                else if (daysTillExpiration > 3 && daysTillExpiration <= 5)
                                {
                                    timeLeftDescription = "this week";
                                }
                                else if (daysTillExpiration > 5 && daysTillExpiration <= 12)
                                {
                                    timeLeftDescription = "next week";
                                }
                                else if (daysTillExpiration > 12 && daysTillExpiration <= 15)
                                {
                                    timeLeftDescription = "in a couple of weeks";
                                }
                                else if (daysTillExpiration > 15 && daysTillExpiration <= 30)
                                {
                                    timeLeftDescription = "this month";
                                }
                                else if (daysTillExpiration > 30 && daysTillExpiration <= 62)
                                {
                                    timeLeftDescription = "next month";
                                }
                                else if (daysTillExpiration > 62 && daysTillExpiration <= 92)
                                {
                                    timeLeftDescription = "in a couple of months";
                                }
                                else if (daysTillExpiration > 92 && daysTillExpiration <= 180)
                                {
                                    timeLeftDescription = "in a few months";
                                }
                                else
                                {
                                    timeLeftDescription = "soon";
                                }

                                #endregion

                                if (daysTillExpiration < 0)
                                {
                                    //After the expiration occurs we send a more alarming message from ALERTS
                                    AccountManager.SendEmailToAccount(
                                        accountID,
                                        Settings.Endpoints.Emails.FromAlerts,
                                        Settings.Copy.EmailMessages.CreditCardExpirationMessage.FromName,
                                        Settings.Copy.EmailMessages.CreditCardExpirationMessage.Subject,
                                        String.Format(Settings.Copy.EmailMessages.CreditCardExpirationMessage.Body, account.AccountName, account.AccountNameKey),
                                        true,
                                        true
                                        );

                                    //We also send platform admins an email
                                    EmailManager.Send(
                                        Sahara.Core.Settings.Endpoints.Emails.PlatformEmailAddresses,
                                        Sahara.Core.Settings.Endpoints.Emails.FromPlatform,
                                        "Account Credit Card Expired",
                                        "An accounts credit card has expired!",
                                        "The <b>" + account.AccountName + "</b> account has an expired credit card. Please reach out to them manually to avoid potential billing issues.",
                                        true,
                                        true
                                        );
                                }
                                else
                                {
                                    //If time remains we send a friendly reminder from REMINDERS
                                    AccountManager.SendEmailToAccount(
                                        accountID,
                                        Settings.Endpoints.Emails.FromReminders,
                                        Settings.Copy.EmailMessages.CreditCardExpirationReminder.FromName,
                                        Settings.Copy.EmailMessages.CreditCardExpirationReminder.Subject,
                                        String.Format(Settings.Copy.EmailMessages.CreditCardExpirationReminder.Body, account.AccountName, timeLeftDescription, account.AccountNameKey),
                                        true,
                                        true
                                        );
                                }



                                //Log activity

                                /*
                                 * PlatformLogManager.LogActivity(CategoryType.Custodian, ActivityType.Custodian_CardExpirationReminder_EmailSent,
                                 *  account.AccountName +
                                 *  " (" + account.AccountID.ToString() +
                                 *  ") was sent a " + daysTillExpiration + " day credit card expiration reminder.",
                                 *  "",account.AccountID.ToString(), account.AccountName);*/
                            }
                        }

                        response.isSuccess = true;
                    }
                    else
                    {
                        // No accounts to email...
                        response.isSuccess      = true;
                        response.SuccessMessage = "No accounts to remind for ";
                    }
                }

                response.isSuccess = true;
            }
            catch (Exception e)
            {
                //Log exception and email platform admins
                PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                    e,
                    "attempting to send credit card expiration reminders",
                    System.Reflection.MethodBase.GetCurrentMethod()
                    );

                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
            }

            return(response);
        }