Пример #1
0
        public void ProcessCreditsPurchase(PurchaseModel purchaseModel, int?userId = null, PromoCode promoCode = null)
        {
            try
            {
                var numberOfCredits = purchaseModel.Quantity;
                var creditsModel    = new PurchaseCreditsViewModel
                {
                    NumberOfCredits = numberOfCredits
                };

                var userCreditPack = new UserCreditPack
                {
                    UserId          = userId ?? _authentication.CurrentUserId,
                    NumberOfCredits = numberOfCredits,
                    TotalPrice      = promoCode?.TotalPrice ?? creditsModel.TotalPrice
                };

                _userCreditPacksRepository.Create(userCreditPack);
                userCreditPack.User = _usersRepository.Find(_authentication.CurrentUserId);

                var contact = _contactService.Find(purchaseModel.ContactId);

                SendEmailToVibrantHealth(userCreditPack, promoCode);
                SendEmailToCustomer(userCreditPack, contact, promoCode);
            }
            catch (Exception ex)
            {
                _logger.Error($"MembershipService => ProcessPurchase => Purchase failed: {ex.GetFullErrorMessage()}");
                SendEmailToVibrantHealthAboutFailure(purchaseModel, ex.GetFullErrorMessage());
                throw ex;
            }
        }
Пример #2
0
        private void SendEmailToVibrantHealth(UserCreditPack userCreditPack, PromoCode promoCode)
        {
            var template = Dictionary.CreditPackPurchased;
            var title    = "We have received a new credit pack purchase!";

            _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new
            {
                Title         = title,
                Customer      = userCreditPack.User.FullName,
                CustomerEmail = userCreditPack.User.EmailAddress,
                userCreditPack.NumberOfCredits,
                TotalPrice        = promoCode?.FormattedPrice ?? userCreditPack.FormattedPrice,
                LinkToCreditPacks = _urlHelper.AbsoluteAction("Index", "UserCreditPacks"),
                Company           = _config.CompanyName,
                ImageUrl          = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl)
            }), _config.SupportEmailAddress, _config.CompanyName, _config.SupportEmailAddress, _config.CompanyName);
        }
Пример #3
0
        public void AssignCreditsToUser(int numberOfCredits, int?userId = null)
        {
            try
            {
                var userCreditPack = new UserCreditPack
                {
                    UserId          = userId ?? _authentication.CurrentUserId,
                    NumberOfCredits = numberOfCredits
                };

                _userCreditPacksRepository.Create(userCreditPack);
                userCreditPack.User = _usersRepository.Find(_authentication.CurrentUserId);
            }
            catch (Exception ex)
            {
                _logger.Error($"MembershipService => AssignCreditsToUser => AssignCreditsToUser failed: {ex.GetFullErrorMessage()}");
                throw ex;
            }
        }
Пример #4
0
        private void SendEmailToCustomer(UserCreditPack userCreditPack, Contact contact, PromoCode promoCode = null)
        {
            var template = Dictionary.NewCreditPackThankYouEmail;
            var title    = Dictionary.ThankyouForCreditPackPurchaseEmailTitle;

            if (contact != null && !contact.IsUnsubscribed)
            {
                _mailer.SendEmail(title, TemplateProcessor.PopulateTemplate(template, new
                {
                    Title                    = title,
                    CustomerName             = userCreditPack.User.FirstName,
                    NumberOfCreditsPurchased = userCreditPack.NumberOfCredits,
                    TotalPrice               = promoCode?.FormattedPrice ?? userCreditPack.FormattedPrice,
                    ImageUrl                 = _urlHelper.AbsoluteContent(_config.CompanyLogoUrl),
                    PrivacyPolicyLink        = _urlHelper.AbsoluteAction("PrivacyPolicy", "Home"),
                    UnsubscribeLink          = _urlHelper.AbsoluteAction("Unsubscribe", "Account", new { code = contact.Name }),
                    DateTime.Now.Year
                }), userCreditPack.User.EmailAddress, userCreditPack.User.FirstName, _config.SupportEmailAddress,
                                  _config.CompanyName);
            }
        }