Skip to content

Commit 61f8188

Browse files
feat(payments-next): Update subscription reminder emails on discount change.
Because: * Currently, the SubscriptionRenewalReminder emails don't handle cases when a customer’s discount is being replaced by a different discount. This commit: * Updates subscription reminder emails to handle these situations. Closes #[PAY-3485](https://mozilla-hub.atlassian.net/browse/PAY-3485)
1 parent 8aad293 commit 61f8188

10 files changed

Lines changed: 44 additions & 9 deletions

File tree

libs/accounts/email-renderer/src/templates/subscriptionRenewalReminder/en.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ subscriptionRenewalReminder-content-greeting = Dear { $productName } customer,
88
# Variables
99
# $reminderLength (String) - The number of days until the current subscription is set to automatically renew, e.g. 14
1010
subscriptionRenewalReminder-content-intro = Your current subscription is set to automatically renew in { $reminderLength } days.
11+
subscriptionRenewalReminder-content-discount-change = Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied.
1112
subscriptionRenewalReminder-content-discount-ending = Because a previous discount has ended, your subscription will renew at the standard price.
1213
# Variables
1314
# $invoiceTotal (String) - The amount of the subscription invoice, including currency, e.g. $10.00

libs/accounts/email-renderer/src/templates/subscriptionRenewalReminder/index.mjml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
</mj-text>
2020

2121
<% if (locals.hadDiscount) { %>
22+
<% if (locals.hasRenewalDiscount) { %>
23+
<mj-text css-class="text-body">
24+
<span data-l10n-id="subscriptionRenewalReminder-content-discount-change">
25+
Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied.
26+
</span>
27+
</mj-text>
28+
<% } else { %>
2229
<mj-text css-class="text-body">
2330
<span data-l10n-id="subscriptionRenewalReminder-content-discount-ending">
2431
Because a previous discount has ended, your subscription will renew at the standard price.
2532
</span>
2633
</mj-text>
34+
<% } %>
2735
<% } %>
2836
2937
<mj-text css-class="text-body">

libs/accounts/email-renderer/src/templates/subscriptionRenewalReminder/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ export type TemplateData = SubscriptionSupportContactTemplateData &
1515
subscriptionSupportUrl: string;
1616
updateBillingUrl: string;
1717
hadDiscount?: boolean;
18+
hasRenewalDiscount?: boolean;
1819
};
1920

2021
export const template = 'subscriptionRenewalReminder';
21-
export const version = 3;
22+
export const version = 4;
2223
export const layout = 'subscription';
2324
export const includes = {
2425
subject: {

libs/accounts/email-renderer/src/templates/subscriptionRenewalReminder/index.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ subscriptionRenewalReminder-content-greeting = "Dear <%- productName %> customer
77
subscriptionRenewalReminder-content-intro = "Your current subscription is set to automatically renew in <%- reminderLength %> days."
88

99
<% if (locals.hadDiscount) { %>
10+
<% if (locals.hasRenewalDiscount) { %>
11+
subscriptionRenewalReminder-content-discount-change = "Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied."
12+
<% } else { %>
1013
subscriptionRenewalReminder-content-discount-ending = "Because a previous discount has ended, your subscription will renew at the standard price."
14+
<% } %>
15+
<% } %>
1116

1217
subscriptionRenewalReminder-content-charge = "At that time, Mozilla will renew your <%- planIntervalCount %> <%- planInterval %> subscription and a charge of <%- invoiceTotal %> will be applied to the payment method on your account."
13-
<% } else { %>
14-
subscriptionRenewalReminder-content-charge = "At that time, Mozilla will renew your <%- planIntervalCount %> <%- planInterval %> subscription and a charge of <%- invoiceTotal %> will be applied to the payment method on your account."
15-
<% } %>
1618

1719
<%- include ('/partials/subscriptionUpdateBillingEnsure/index.txt') %>
1820

packages/fxa-auth-server/lib/payments/subscription-reminders.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ export class SubscriptionReminders {
268268
/**
269269
* Determine if a discount is ending by checking that the subscription currently
270270
* has a discount but the upcoming invoice does not.
271-
* TODO in PAY-3485: Handle the case where the discount changes without ending.
272271
*/
273272
private hasDiscountEnding(
274273
subscription: Stripe.Subscription,
@@ -277,6 +276,15 @@ export class SubscriptionReminders {
277276
return !!subscription.discount && !invoicePreview.discount;
278277
}
279278

279+
/**
280+
* Determine if the upcoming invoice has a discount.
281+
*/
282+
private hasRenewalDiscount(
283+
invoicePreview: Stripe.UpcomingInvoice
284+
): boolean {
285+
return !!invoicePreview.discount;
286+
}
287+
280288
/**
281289
* Send out a renewal reminder email if we haven't already sent one.
282290
*/
@@ -341,6 +349,8 @@ export class SubscriptionReminders {
341349

342350
// Detect if discount is ending
343351
const hadDiscount = this.hasDiscountEnding(subscription, invoicePreview);
352+
// Detect if renewal has a discount
353+
const hasRenewalDiscount = this.hasRenewalDiscount(invoicePreview);
344354

345355
await this.mailer.sendSubscriptionRenewalReminderEmail(
346356
account.emails,
@@ -359,6 +369,7 @@ export class SubscriptionReminders {
359369
productMetadata: formattedSubscription.productMetadata,
360370
planConfig: formattedSubscription.planConfig,
361371
hadDiscount,
372+
hasRenewalDiscount,
362373
}
363374
);
364375
await this.updateSentEmail(

packages/fxa-auth-server/lib/senders/email.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3253,6 +3253,7 @@ module.exports = function (log, config, bounces, statsd) {
32533253
message.acceptLanguage
32543254
),
32553255
hadDiscount: message.hadDiscount || false,
3256+
hasRenewalDiscount: message.hasRenewalDiscount || false,
32563257
},
32573258
});
32583259
};

packages/fxa-auth-server/lib/senders/emails/templates/_versions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"subscriptionReactivation": 2,
3-
"subscriptionRenewalReminder": 3,
3+
"subscriptionRenewalReminder": 4,
44
"subscriptionEndingReminder": 1,
55
"subscriptionUpgrade": 7,
66
"subscriptionDowngrade": 2,

packages/fxa-auth-server/lib/senders/emails/templates/subscriptionRenewalReminder/en.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ subscriptionRenewalReminder-content-greeting = Dear { $productName } customer,
88
# Variables
99
# $reminderLength (String) - The number of days until the current subscription is set to automatically renew, e.g. 14
1010
subscriptionRenewalReminder-content-intro = Your current subscription is set to automatically renew in { $reminderLength } days.
11+
subscriptionRenewalReminder-content-discount-change = Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied.
1112
subscriptionRenewalReminder-content-discount-ending = Because a previous discount has ended, your subscription will renew at the standard price.
1213
# Variables
1314
# $invoiceTotal (String) - The amount of the subscription invoice, including currency, e.g. $10.00

packages/fxa-auth-server/lib/senders/emails/templates/subscriptionRenewalReminder/index.mjml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@
1919
</mj-text>
2020

2121
<% if (hadDiscount) { %>
22+
<% if (hasRenewalDiscount) { %>
23+
<mj-text css-class="text-body">
24+
<span data-l10n-id="subscriptionRenewalReminder-content-discount-change">
25+
Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied.
26+
</span>
27+
</mj-text>
28+
<% } else { %>
2229
<mj-text css-class="text-body">
2330
<span data-l10n-id="subscriptionRenewalReminder-content-discount-ending">
2431
Because a previous discount has ended, your subscription will renew at the standard price.
2532
</span>
2633
</mj-text>
34+
<% } %>
2735
<% } %>
2836
2937
<mj-text css-class="text-body">

packages/fxa-auth-server/lib/senders/emails/templates/subscriptionRenewalReminder/index.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ subscriptionRenewalReminder-content-greeting = "Dear <%- productName %> customer
77
subscriptionRenewalReminder-content-intro = "Your current subscription is set to automatically renew in <%- reminderLength %> days."
88

99
<% if (hadDiscount) { %>
10+
<% if (hasRenewalDiscount) { %>
11+
subscriptionRenewalReminder-content-discount-change = "Your next invoice reflects a change in pricing, as a previous discount has ended and a new discount has been applied."
12+
<% } else { %>
1013
subscriptionRenewalReminder-content-discount-ending = "Because a previous discount has ended, your subscription will renew at the standard price."
14+
<% } %>
15+
<% } %>
1116

1217
subscriptionRenewalReminder-content-charge = "At that time, Mozilla will renew your <%- planIntervalCount %> <%- planInterval %> subscription and a charge of <%- invoiceTotal %> will be applied to the payment method on your account."
13-
<% } else { %>
14-
subscriptionRenewalReminder-content-charge = "At that time, Mozilla will renew your <%- planIntervalCount %> <%- planInterval %> subscription and a charge of <%- invoiceTotal %> will be applied to the payment method on your account."
15-
<% } %>
1618

1719
<%- include ('/partials/subscriptionUpdateBillingEnsure/index.txt') %>
1820

0 commit comments

Comments
 (0)