Skip to content

Commit fc6721f

Browse files
authored
Merge pull request #19860 from mozilla/pay-2294-cron-updates-reminders
feat(auth): update subscription reminders script for cron
2 parents 184f8f6 + 8e4d2a2 commit fc6721f

4 files changed

Lines changed: 51 additions & 0 deletions

File tree

packages/fxa-auth-server/lib/payments/initSubplat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ export async function initSubplat({
216216
paypalCustomerManager,
217217
logger
218218
);
219+
219220
/**
220221
* Add initialized instances to Container
221222
*/

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const planIntervalsToDuration = {
3434
interface EndingRemindersOptions {
3535
enabled: boolean;
3636
paymentsNextUrl: string;
37+
dailyReminderDays?: number;
3738
monthlyReminderDays: number;
3839
yearlyReminderDays: number;
3940
}
@@ -45,6 +46,7 @@ export class SubscriptionReminders {
4546
private planDuration: Duration;
4647
private reminderDuration: Duration;
4748
private endingReminderEnabled: boolean;
49+
private dailyEndingReminderDuration: Duration | undefined;
4850
private monthlyEndingReminderDuration: Duration;
4951
private yearlyEndingReminderDuration: Duration;
5052
private paymentsNextUrl: string;
@@ -74,6 +76,11 @@ export class SubscriptionReminders {
7476
this.planDuration = Duration.fromObject({ days: planLength });
7577
this.reminderDuration = Duration.fromObject({ days: reminderLength });
7678
this.endingReminderEnabled = endingReminderOptions.enabled;
79+
if (endingReminderOptions.dailyReminderDays) {
80+
this.dailyEndingReminderDuration = Duration.fromObject({
81+
days: endingReminderOptions.dailyReminderDays,
82+
});
83+
}
7784
this.monthlyEndingReminderDuration = Duration.fromObject({
7885
days: endingReminderOptions.monthlyReminderDays,
7986
});
@@ -414,6 +421,13 @@ export class SubscriptionReminders {
414421

415422
// 4
416423
if (this.endingReminderEnabled) {
424+
// Daily
425+
if (this.dailyEndingReminderDuration) {
426+
await this.sendEndingReminders(
427+
this.dailyEndingReminderDuration,
428+
SubplatInterval.Daily
429+
);
430+
}
417431
// Monthly
418432
await this.sendEndingReminders(
419433
this.monthlyEndingReminderDuration,

packages/fxa-auth-server/scripts/subscription-reminders.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { parseBooleanArg } from './lib/args';
2020

2121
const DEFAULT_PLAN_LENGTH = 180;
2222
const DEFAULT_REMINDER_LENGTH = 14;
23+
const DEFAULT_ENDING_REMINDER_DAILY_LENGTH = 0;
2324
const DEFAULT_ENDING_REMINDER_MONTHLY_LENGTH = 7;
2425
const DEFAULT_ENDING_REMINDER_YEARLY_LENGTH = 14;
2526

@@ -28,6 +29,7 @@ Sentry.init({});
2829
async function init() {
2930
program
3031
.version(pckg.version)
32+
.allowUnknownOption(true)
3133
.option(
3234
'-p, --plan-length [days]',
3335
'Plan length in days beyond which a reminder email before the next recurring charge should be sent. Defaults to 180.',
@@ -43,6 +45,11 @@ async function init() {
4345
'Enable the sending of subscription ending reminder emails. Defaults to false.',
4446
false
4547
)
48+
.option(
49+
'-d, --ending-reminder-daily-length [days]',
50+
'Reminder length in days before the daily subscription ending date to send the reminder email. Defaults to 0.',
51+
DEFAULT_ENDING_REMINDER_DAILY_LENGTH.toString()
52+
)
4653
.option(
4754
'-m, --ending-reminder-monthly-length [days]',
4855
'Reminder length in days before the montly subscription ending date to send the reminder email. Defaults to 7.',
@@ -78,6 +85,7 @@ async function init() {
7885
{
7986
enabled: parseBooleanArg(program.enableEndingReminders),
8087
paymentsNextUrl: config.smtp.subscriptionSettingsUrl,
88+
dailyReminderDays: parseInt(program.endingReminderDailyLength),
8189
monthlyReminderDays: parseInt(program.endingReminderMonthlyLength),
8290
yearlyReminderDays: parseInt(program.endingReminderYearlyLength),
8391
},

packages/fxa-auth-server/test/local/payments/subscription-reminders.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('SubscriptionReminders', () => {
6060
let mockConfig;
6161
let realDateNow;
6262

63+
const mockDailyReminderDuration = undefined;
6364
const mockMonthlyReminderDuration = 7;
6465
const mockYearlyReminderDuration = 14;
6566

@@ -97,6 +98,7 @@ describe('SubscriptionReminders', () => {
9798
{
9899
enabled: false,
99100
paymentsNextUrl: 'http://localhost:3035',
101+
dailyReminderDays: mockDailyReminderDuration,
100102
monthlyReminderDays: mockMonthlyReminderDuration,
101103
yearlyReminderDays: mockYearlyReminderDuration,
102104
},
@@ -727,6 +729,32 @@ describe('SubscriptionReminders', () => {
727729
'yearly'
728730
);
729731
});
732+
733+
it('calls sendEndingReminders for daily if dailyEndingReminderDuration is provided', async () => {
734+
const mockDailyReminderDays = 3;
735+
reminder.sendEndingReminders = sandbox.fake.resolves({});
736+
reminder.endingReminderEnabled = true;
737+
reminder.dailyEndingReminderDuration = Duration.fromObject({
738+
days: mockDailyReminderDays,
739+
});
740+
await reminder.sendReminders();
741+
742+
sinon.assert.calledWith(
743+
reminder.sendEndingReminders,
744+
Duration.fromObject({ days: mockDailyReminderDays }),
745+
'daily'
746+
);
747+
sinon.assert.calledWith(
748+
reminder.sendEndingReminders,
749+
Duration.fromObject({ days: mockMonthlyReminderDuration }),
750+
'monthly'
751+
);
752+
sinon.assert.calledWith(
753+
reminder.sendEndingReminders,
754+
Duration.fromObject({ days: mockYearlyReminderDuration }),
755+
'yearly'
756+
);
757+
});
730758
});
731759

732760
describe('sendEndingReminders', () => {

0 commit comments

Comments
 (0)