예제 #1
0
 /// <summary>
 /// Create Auth Email Content
 /// </summary>
 /// <param name="data">
 /// Auth Email Notification Data
 /// </param>
 /// <param name="subjectLine">
 /// Email subect
 /// </param>
 /// <param name="templatePath">Template Path</param>
 /// <returns>
 /// Notification content
 /// </returns>
 public async Task <NotificationContent> CreateAuthEmailContentAsync(AuthEmailNotificationData data, string subjectLine, string templatePath = authEmailTemplatePathClo)
 {
     try
     {
         return(await CreateEmailContentAsync(
                    JsonConvert.SerializeObject(data),
                    TemplateServiceBaseAddress + templatePath,
                    subjectLine).ConfigureAwait(false));
     }
     catch (Exception exception)
     {
         Logger.Warning("Unable to create content for Auth Email \r\n" +
                        "Data : \r\n" +
                        "{0}", data, exception);
         throw;
     }
 }
예제 #2
0
        /// <summary>
        /// Send email and sms
        /// </summary>
        /// <param name="userId">
        /// User Id to send notification to
        /// </param>
        /// <param name="environment">
        /// Environment for which notification needs to be sent
        /// </param>
        internal void Send(Guid userId, string environment)
        {
            try
            {
                Users.Dal.DataModel.User user = RetrieveUser(userId);

                //By default, enable both email and phone notification
                TransactionNotificationPreference transactionNotificationPreference =
                    TransactionNotificationPreference.Email | TransactionNotificationPreference.Phone;

                if (user.Info != null && user.Info.Preferences != null)
                {
                    transactionNotificationPreference = user.Info.Preferences.TransactionNotificationMedium;
                }


                if (transactionNotificationPreference == TransactionNotificationPreference.None)
                {
                    Context.Log.Verbose("User has turned off both SMS & Email auth notification");
                    return;
                }

                INotificationContentCreator creator          = NotificationContentCreatorFactory.NotificationContentCreator(Context);
                RedeemedDealInfo            redeemedDealInfo = (RedeemedDealInfo)Context[Key.RedeemedDealInfo];
                Context.Log.Verbose("Credit Amount : {0}", redeemedDealInfo.DiscountText);
                Context.Log.Verbose("DiscountSummary : {0}", redeemedDealInfo.DiscountSummary);
                Context.Log.Verbose("LastFourDigits : {0}", redeemedDealInfo.LastFourDigits);
                Context.Log.Verbose("MerchantName : {0}", redeemedDealInfo.MerchantName);
                Context.Log.Verbose("UserName : {0}", SalutationName);
                Context.Log.Verbose("ReimbursementTender : {0}", redeemedDealInfo.ReimbursementTenderId);

                AuthEmailNotificationData authEmailNotificationData = new AuthEmailNotificationData()
                {
                    CreditAmount      = redeemedDealInfo.DiscountText,
                    DiscountSummary   = redeemedDealInfo.DiscountSummary,
                    LastFourDigits    = redeemedDealInfo.LastFourDigits,
                    MerchantName      = redeemedDealInfo.MerchantName,
                    UserName          = SalutationName,
                    UserId            = userId.ToString(),
                    DealId            = redeemedDealInfo.ParentDealId.ToString(),
                    DiscountId        = redeemedDealInfo.GlobalId.ToString(),
                    TransactionDate   = redeemedDealInfo.TransactionDate.ToLongDateString(),
                    TransactionId     = redeemedDealInfo.TransactionId,
                    PartnerId         = redeemedDealInfo.PartnerId.ToString(CultureInfo.InvariantCulture),
                    PartnerMerchantId = redeemedDealInfo.PartnerMerchantId,
                    Percent           = (float)Math.Round(redeemedDealInfo.Percent, 2)
                };

                NotificationContent content;
                if ((transactionNotificationPreference & TransactionNotificationPreference.Email) == TransactionNotificationPreference.Email)
                {
                    EnvironmentType environmentType;
                    if (Enum.TryParse(environment, true, out environmentType))
                    {
                        authEmailNotificationData.PopulateAuthStatusAndEmailLink(user, UsersDal, environmentType);
                    }


                    bool isEarn = true;
                    if (redeemedDealInfo.ReimbursementTenderId == (int)ReimbursementTender.MicrosoftEarn)
                    {
                        content =
                            creator.CreateAuthEmailContentAsync(authEmailNotificationData, authEmailSubjectEarn,
                                                                authEmailTemplatePathEarn).Result;
                    }
                    else if (redeemedDealInfo.ReimbursementTenderId == (int)ReimbursementTender.MicrosoftBurn)
                    {
                        content =
                            creator.CreateAuthEmailContentAsync(authEmailNotificationData, authEmailSubjectBurn,
                                                                authEmailTemplatePathBurn).Result;
                    }
                    else
                    {
                        isEarn  = false;
                        content =
                            creator.CreateAuthEmailContentAsync(authEmailNotificationData, authEmailSubjectClo).Result;
                    }

                    Context.Log.Verbose("About to send Email Auth notification");
                    SendEmailNotification(user.Email, content, isEarn);
                    Context.Log.Verbose("Email notification sent");
                }
                else
                {
                    Context.Log.Verbose("User has turned off Email Auth notification");
                }

                if ((transactionNotificationPreference & TransactionNotificationPreference.Phone) ==
                    TransactionNotificationPreference.Phone)
                {
                    AuthSmsNotificationData authSmsNotificationData = new AuthSmsNotificationData()
                    {
                        DiscountSummary = redeemedDealInfo.DiscountSummary,
                        MerchantName    = redeemedDealInfo.MerchantName,
                        Percent         = (float)Math.Round(redeemedDealInfo.Percent, 2),
                        CreditAmount    = redeemedDealInfo.DiscountText
                    };

                    if (redeemedDealInfo.ReimbursementTenderId == (int)ReimbursementTender.MicrosoftEarn)
                    {
                        content =
                            creator.CreateAuthSmsContentAsync(authSmsNotificationData, authSmsTemplatePathEarn).Result;
                    }
                    else if (redeemedDealInfo.ReimbursementTenderId == (int)ReimbursementTender.MicrosoftBurn)
                    {
                        content =
                            creator.CreateAuthSmsContentAsync(authSmsNotificationData, authSmsTemplatePathBurn).Result;
                    }
                    else
                    {
                        content = creator.CreateAuthSmsContentAsync(authSmsNotificationData).Result;
                    }

                    Context.Log.Verbose("About to send SMS Auth notification");
                    SendSmsNotification(userId, content.TextBody);
                    Context.Log.Verbose("SMS Notification sent");
                }
                else
                {
                    Context.Log.Verbose("User has turned off SMS Auth notification");
                }
            }
            catch (Exception exception)
            {
                // catch all exception, log them as warning.
                // but continue sending other notifications if needed
                Context.Log.Warning("Sending notification resulted in error. User Id : {0}", exception, userId);
            }
        }