public void ProcessNotification(Core.Models.Messaging.Queue.BaseNotification notification)
        {
            try {
                if (notification.NotificationType != Core.Enumerations.Messaging.NotificationType.HasNews)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                var hasNewsNotification = (HasNewsNotification)notification;

                Svc.Core.Models.Profile.Customer customer = customerRepository.GetCustomerByCustomerNumber(notification.CustomerNumber, hasNewsNotification.BranchId);

                if (customer == null)
                {
                    System.Text.StringBuilder warningMessage = new StringBuilder();
                    warningMessage.AppendFormat("Could not find customer({0}-{1}) to send Has News notification.", notification.BranchId, hasNewsNotification.CustomerNumber);
                    warningMessage.AppendLine();
                    warningMessage.AppendLine();
                    warningMessage.AppendLine("Notification:");
                    warningMessage.AppendLine(notification.ToJson());

                    eventLogRepository.WriteWarningLog(warningMessage.ToString());
                }
                else
                {
                    List <Recipient> recipients = base.LoadRecipients(notification.NotificationType, customer, notification.DSRDSMOnly);

                    if (recipients != null && recipients.Count > 0)
                    {
                        // send messages to providers...
                        Message msg = new Message()
                        {
                            CustomerName     = customer.CustomerName,
                            CustomerNumber   = customer.CustomerNumber,
                            BranchId         = customer.CustomerBranch,
                            MessageSubject   = hasNewsNotification.Subject,
                            MessageBody      = hasNewsNotification.Notification,
                            NotificationType = NotificationType.HasNews
                        };
                        msg.BodyIsHtml = true;

                        base.SendMessage(recipients, msg);
                    }
                }
            } catch (Exception ex) {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "HasNews:ProcessNotification", "Sending HasNews notification", "There was an error sending a HasNews notification", ex);
            }
        }
Exemplo n.º 2
0
        private Message GetEmailMessageForMultipleAccountSummaryNotification
            (List <PaymentTransactionModel> payments, List <UserSelectedContext> customers)
        {
            StringBuilder orderDetails = new StringBuilder();

            int      confirmationId = 0, customerNumber = 0;
            string   payer         = null;
            decimal  grandSum      = 0;
            DateTime submittedDate = DateTime.MinValue;

            foreach (var customer in customers.OrderBy(ctx => ctx.CustomerId))
            { // the start of each customer
                ++customerNumber;

                Svc.Core.Models.Profile.Customer cust =
                    _customerRepo.GetCustomerByCustomerNumber(customer.CustomerId, customer.BranchId);

                int     paymentNumber = 0;
                decimal paymentSum    = 0;
                Core.Models.OnlinePayments.Customer.EF.CustomerBank bankUsed = null;

                foreach (var payment in payments.Where(p => p.CustomerNumber == customer.CustomerId &&
                                                       p.BranchId == customer.BranchId)
                         .OrderBy(p => p.AccountNumber))
                {
                    paymentNumber++;

                    Core.Models.OnlinePayments.Customer.EF.CustomerBank bank = _bankRepo.GetBankAccount
                                                                                   (DivisionHelper.GetDivisionFromBranchId(customer.BranchId),
                                                                                   customer.CustomerId, payment.AccountNumber);
                    bankUsed = BuildPaymentSummaryBankUsed(orderDetails, paymentSum, bankUsed, bank);

                    paymentSum = paymentSum + payment.PaymentAmount;
                    grandSum   = grandSum + payment.PaymentAmount;

                    confirmationId = payment.ConfirmationId;
                    payer          = payment.UserName;
                    submittedDate  = payment.PaymentDate.Value;

                    BuildPaymentSummaryPaymentDetails(orderDetails, customer, cust, paymentNumber, payment);
                }
                BuildPaymentSummaryFooter(orderDetails, cust, paymentSum, bankUsed);
            }
            ApplyGrandPaymentSummaryTemplate(orderDetails, grandSum, submittedDate);

            return(AssembleMessageForPayerSummary(orderDetails, confirmationId, payer));
        }
Exemplo n.º 3
0
        public void ProcessNotification(BaseNotification notification)
        {
            try {
                if (notification.NotificationType != NotificationType.PaymentConfirmation)
                {
                    throw new ApplicationException("notification/handler type mismatch");
                }

                // had to setup a translation for this type in Svc.Core.Extensions to deserialize the message with the concrete type
                PaymentConfirmationNotification confirmation = (PaymentConfirmationNotification)notification;

                // UserContextEqualityComparer discriminates usercontext's to allow distinct to weed out duplicates
                List <UserSelectedContext> customerCtxs = confirmation.Payments
                                                          .Select(p => new UserSelectedContext()
                {
                    CustomerId = p.CustomerNumber, BranchId = p.BranchId
                })
                                                          .Distinct(new UserContextEqualityComparer())
                                                          .ToList();

                bool             complexPayment = customerCtxs.Count > 1;
                string           payerEmail     = confirmation.SubmittedBy;
                List <Recipient> payerRecipient = null;

                foreach (UserSelectedContext customerCtx in customerCtxs)
                {
                    // load up recipients, customer and message
                    Svc.Core.Models.Profile.Customer customer = _customerRepo.GetCustomerByCustomerNumber(customerCtx.CustomerId, customerCtx.BranchId);

                    if (customer == null)
                    {
                        StringBuilder warningMessage = new StringBuilder();
                        warningMessage.AppendFormat("Could not find customer({0}-{1}) to send Payment Confirmation notification.", customerCtx.BranchId, customerCtx.CustomerId);
                        warningMessage.AppendLine();
                        warningMessage.AppendLine();
                        warningMessage.AppendLine("Notification:");
                        warningMessage.AppendLine(notification.ToJson());

                        _log.WriteWarningLog(warningMessage.ToString());
                    }
                    else
                    {
                        List <Recipient> recipients = LoadRecipients(confirmation.NotificationType, customer);
                        Message          message    = GetEmailMessageForNotification(confirmation.Payments
                                                                                     .Where(p => p.CustomerNumber == customerCtx.CustomerId && p.BranchId == customerCtx.BranchId)
                                                                                     .ToList(),
                                                                                     customer);

                        // send messages to providers...
                        if (recipients != null && recipients.Count > 0)
                        {
                            if (complexPayment) // mask out payeremail recipient from the regular recipients
                            {
                                payerRecipient = recipients.Where(r => r.UserEmail.ToLower() == payerEmail.ToLower()).ToList();
                                recipients     = recipients.Where(r => r.UserEmail.ToLower() != payerEmail.ToLower()).ToList();
                            }

                            if (recipients.Count > 0)
                            {
                                SendMessage(recipients, message);
                            }
                        }
                    }
                }

                if (complexPayment && payerRecipient != null)
                {
                    SendMessage(payerRecipient,
                                GetEmailMessageForMultipleAccountSummaryNotification(confirmation.Payments, customerCtxs));
                }
            }
            catch (Exception ex) {
                throw new Core.Exceptions.Queue.QueueDataError <BaseNotification>(notification, "PaymentConfirmation:ProcessNotification", "Sending PaymentConfirmation notification", "An error occured processing a payment confirmation", ex);
            }
        }
Exemplo n.º 4
0
        protected Message GetEmailMessageForNotification(IEnumerable <OrderEta> orderEtas, IEnumerable <OrderHistoryHeader> orders, Svc.Core.Models.Profile.Customer customer)
        {
            // TODO: Add logic for delivered orders (actualtime) - not needed now, but maybe in the future.
            StringBuilder        orderInfoDetails     = new StringBuilder();
            MessageTemplateModel orderEtaLineTemplate = messageTemplateLogic.ReadForKey("OrderEtaLine");
            string timeZoneName = string.Empty;

            foreach (var o in orders)
            {
                OrderEta eta = orderEtas.Where(ordereta => ordereta.OrderId == o.InvoiceNumber).FirstOrDefault();
                DateTime?estimatedDelivery = DateTime.Parse(eta.EstimatedTime).ToCentralTime();  // will parse into local time, then convert to central
                DateTime?scheduledDelivery = DateTime.Parse(eta.ScheduledTime).ToCentralTime();
                DateTime?actualDelivery    = DateTime.Parse(eta.ActualTime).ToCentralTime();
                object   orderLineDetails  =
                    new {
                    InvoiceNumber         = o.InvoiceNumber,
                    ProductCount          = o.OrderDetails.Count.ToString(),
                    ShippedQuantity       = o.OrderDetails.Sum(od => od.ShippedQuantity).ToString(),
                    ScheduledDeliveryDate = scheduledDelivery.Value.ToShortDateString(),
                    ScheduledDeliveryTime = scheduledDelivery.Value.ToShortTimeString(),
                    EstimatedDeliveryDate = estimatedDelivery.Value.ToShortDateString(),
                    EstimatedDeliveryTime = estimatedDelivery.Value.ToShortTimeString()
                };
                orderInfoDetails.Append(orderEtaLineTemplate.Body.Inject(orderLineDetails));

                if (timeZoneName == string.Empty)
                {
                    TimeZoneInfo centralTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
                    timeZoneName = (centralTimeZone.IsDaylightSavingTime(scheduledDelivery.Value) ? centralTimeZone.DaylightName : centralTimeZone.StandardName);
                }
            }

            MessageTemplateModel orderEtaMainTemplate = messageTemplateLogic.ReadForKey("OrderEtaMain");

            Message message = new Message();

            //message.MessageSubject = orderEtaMainTemplate.Subject.Inject(new { CustomerName = string.Format("{0-{1}", customer.CustomerNumber, customer.CustomerName) });
            message.MessageSubject   = orderEtaMainTemplate.Subject.Inject(customer);
            message.MessageBody      = orderEtaMainTemplate.Body.Inject(new { TimeZoneName = timeZoneName, EtaOrderLines = orderInfoDetails.ToString() });
            message.CustomerNumber   = customer.CustomerNumber;
            message.CustomerName     = customer.CustomerName;
            message.BranchId         = customer.CustomerBranch;
            message.NotificationType = NotificationType.OrderConfirmation;
            return(message);
        }