mirror of
https://github.com/bitwarden/server
synced 2026-01-17 16:03:49 +00:00
[PM-28100] families 2019 email (#6645)
* [PM-28100] families 2019 email * pr feedback
This commit is contained in:
@@ -18,6 +18,7 @@ public class StripeFacade : IStripeFacade
|
||||
private readonly DiscountService _discountService = new();
|
||||
private readonly SetupIntentService _setupIntentService = new();
|
||||
private readonly TestClockService _testClockService = new();
|
||||
private readonly CouponService _couponService = new();
|
||||
|
||||
public async Task<Charge> GetCharge(
|
||||
string chargeId,
|
||||
@@ -143,4 +144,11 @@ public class StripeFacade : IStripeFacade
|
||||
RequestOptions requestOptions = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
_testClockService.GetAsync(testClockId, testClockGetOptions, requestOptions, cancellationToken);
|
||||
|
||||
public Task<Coupon> GetCoupon(
|
||||
string couponId,
|
||||
CouponGetOptions couponGetOptions = null,
|
||||
RequestOptions requestOptions = null,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
_couponService.GetAsync(couponId, couponGetOptions, requestOptions, cancellationToken);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using Bit.Core.Billing.Extensions;
|
||||
using Bit.Core.Billing.Payment.Queries;
|
||||
using Bit.Core.Billing.Pricing;
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Models.Mail.Billing.Renewal.Families2019Renewal;
|
||||
using Bit.Core.Models.Mail.Billing.Renewal.Families2020Renewal;
|
||||
using Bit.Core.OrganizationFeatures.OrganizationSponsorships.FamiliesForEnterprise.Interfaces;
|
||||
using Bit.Core.Platform.Mail.Mailer;
|
||||
@@ -284,7 +285,7 @@ public class UpcomingInvoiceHandler(
|
||||
{
|
||||
await organizationRepository.ReplaceAsync(organization);
|
||||
await stripeFacade.UpdateSubscription(subscription.Id, options);
|
||||
await SendFamiliesRenewalEmailAsync(organization, familiesPlan);
|
||||
await SendFamiliesRenewalEmailAsync(organization, familiesPlan, plan);
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
@@ -546,7 +547,18 @@ public class UpcomingInvoiceHandler(
|
||||
|
||||
private async Task SendFamiliesRenewalEmailAsync(
|
||||
Organization organization,
|
||||
Plan familiesPlan)
|
||||
Plan familiesPlan,
|
||||
Plan planBeforeAlignment)
|
||||
{
|
||||
await (planBeforeAlignment switch
|
||||
{
|
||||
{ Type: PlanType.FamiliesAnnually2025 } => SendFamilies2020RenewalEmailAsync(organization, familiesPlan),
|
||||
{ Type: PlanType.FamiliesAnnually2019 } => SendFamilies2019RenewalEmailAsync(organization, familiesPlan),
|
||||
_ => throw new InvalidOperationException("Unsupported families plan in SendFamiliesRenewalEmailAsync().")
|
||||
});
|
||||
}
|
||||
|
||||
private async Task SendFamilies2020RenewalEmailAsync(Organization organization, Plan familiesPlan)
|
||||
{
|
||||
var email = new Families2020RenewalMail
|
||||
{
|
||||
@@ -560,6 +572,36 @@ public class UpcomingInvoiceHandler(
|
||||
await mailer.SendEmail(email);
|
||||
}
|
||||
|
||||
private async Task SendFamilies2019RenewalEmailAsync(Organization organization, Plan familiesPlan)
|
||||
{
|
||||
var coupon = await stripeFacade.GetCoupon(CouponIDs.Milestone3SubscriptionDiscount);
|
||||
if (coupon == null)
|
||||
{
|
||||
throw new InvalidOperationException($"Coupon for sending families 2019 email id:{CouponIDs.Milestone3SubscriptionDiscount} not found");
|
||||
}
|
||||
|
||||
if (coupon.PercentOff == null)
|
||||
{
|
||||
throw new InvalidOperationException($"coupon.PercentOff for sending families 2019 email id:{CouponIDs.Milestone3SubscriptionDiscount} is null");
|
||||
}
|
||||
|
||||
var discountedAnnualRenewalPrice = familiesPlan.PasswordManager.BasePrice * (100 - coupon.PercentOff.Value) / 100;
|
||||
|
||||
var email = new Families2019RenewalMail
|
||||
{
|
||||
ToEmails = [organization.BillingEmail],
|
||||
View = new Families2019RenewalMailView
|
||||
{
|
||||
BaseMonthlyRenewalPrice = (familiesPlan.PasswordManager.BasePrice / 12).ToString("C", new CultureInfo("en-US")),
|
||||
BaseAnnualRenewalPrice = familiesPlan.PasswordManager.BasePrice.ToString("C", new CultureInfo("en-US")),
|
||||
DiscountAmount = $"{coupon.PercentOff}%",
|
||||
DiscountedAnnualRenewalPrice = discountedAnnualRenewalPrice.ToString("C", new CultureInfo("en-US"))
|
||||
}
|
||||
};
|
||||
|
||||
await mailer.SendEmail(email);
|
||||
}
|
||||
|
||||
private async Task SendPremiumRenewalEmailAsync(
|
||||
User user,
|
||||
PremiumPlan premiumPlan)
|
||||
|
||||
Reference in New Issue
Block a user