feat: add tasker integration for proration email notifications (#27247)

* feat: add proration invoice and reminder email templates

Add email templates for monthly proration billing notifications:

- ProrationInvoiceEmail: Sent when invoice is created for additional seats
- ProrationReminderEmail: Sent 7 days later if invoice remains unpaid

Includes:
- React email templates using V2BaseEmailHtml
- BaseEmail classes for rendering
- Billing email service functions
- Translation keys for email content

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* feat: add tasker integration for proration email notifications

Add task handlers for proration billing email flow:

- sendProrationInvoiceEmail: Sends invoice email and schedules reminder
- sendProrationReminderEmail: Sends reminder if invoice still unpaid
- cancelProrationReminder: Cancels scheduled reminder on payment success

The calling job should trigger these tasks after:
1. MonthlyProrationService.createProrationForTeam() succeeds with invoice
2. handleProrationPaymentSuccess() is called (to cancel reminder)

Co-Authored-By: Claude Opus 4.5 <[email protected]>

* feat: i18n + feedback from cubic + morgan

* fix: use default tasker import instead of non-existent getTasker

Co-Authored-By: unknown <>

* fix: add trigger tasks plus DI

* use for await

* fix query

* fix: remove duplicate JOIN alias in findTeamMembersWithPermission query

The raw SQL query had two INNER JOINs using the same alias 'u':
- INNER JOIN "users" u ON m."userId" = u.id
- INNER JOIN "User" u ON m."userId" = u.id

This would cause a SQL error at runtime. Removed the duplicate JOIN
with incorrect table name ("User" instead of "users").

Fixes issue identified by Cubic AI review.

Co-Authored-By: unknown <>

---------

Co-authored-by: Claude Opus 4.5 <[email protected]>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-02-03 08:29:36 +00:00
1 parent 3c1d906808
commit 52f3ddaf74
28 files changed
+804 -41

No files matched your search

+30 -7
View File
@@ -25,13 +25,21 @@ const eventTypeDisableAttendeeEmail = (metadata?: EventTypeMetadata) => {
return !!metadata?.disableStandardEmails?.all?.attendee;
};
export const sendOrganizerPaymentRefundFailedEmail = async (calEvent: CalendarEvent) => {
export const sendOrganizerPaymentRefundFailedEmail = async (
calEvent: CalendarEvent
) => {
const emailsToSend: Promise<unknown>[] = [];
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent })));
emailsToSend.push(
sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent }))
);
if (calEvent.team?.members) {
for (const teamMember of calEvent.team.members) {
emailsToSend.push(sendEmail(() => new OrganizerPaymentRefundFailedEmail({ calEvent, teamMember })));
emailsToSend.push(
sendEmail(
() => new OrganizerPaymentRefundFailedEmail({ calEvent, teamMember })
)
);
}
}
@@ -75,7 +83,15 @@ export const sendCreditBalanceLowWarningEmails = async (input: {
for (const admin of team.adminAndOwners) {
emailsToSend.push(
sendEmail(() => new CreditBalanceLowWarningEmail({ user: admin, balance, team, creditFor }))
sendEmail(
() =>
new CreditBalanceLowWarningEmail({
user: admin,
balance,
team,
creditFor,
})
)
);
}
@@ -83,7 +99,9 @@ export const sendCreditBalanceLowWarningEmails = async (input: {
}
if (user) {
await sendEmail(() => new CreditBalanceLowWarningEmail({ user, balance, creditFor }));
await sendEmail(
() => new CreditBalanceLowWarningEmail({ user, balance, creditFor })
);
}
};
@@ -117,14 +135,19 @@ export const sendCreditBalanceLimitReachedEmails = async ({
for (const admin of team.adminAndOwners) {
emailsToSend.push(
sendEmail(() => new CreditBalanceLimitReachedEmail({ user: admin, team, creditFor }))
sendEmail(
() =>
new CreditBalanceLimitReachedEmail({ user: admin, team, creditFor })
)
);
}
await Promise.all(emailsToSend);
}
if (user) {
await sendEmail(() => new CreditBalanceLimitReachedEmail({ user, creditFor }));
await sendEmail(
() => new CreditBalanceLimitReachedEmail({ user, creditFor })
);
}
};
@@ -72,6 +72,10 @@ export default class ProrationInvoiceEmail extends BaseEmail {
protected getTextBody(): string {
const formattedAmount = (this.proration.proratedAmount / 100).toFixed(2);
return `An invoice for $${formattedAmount} has been created for ${this.proration.netSeatIncrease} additional seat(s) for your team ${this.team.name}.`;
return this.user.t("proration_invoice_text", {
amount: formattedAmount,
seats: this.proration.netSeatIncrease,
teamName: this.team.name,
});
}
}
@@ -65,6 +65,9 @@ export default class ProrationReminderEmail extends BaseEmail {
protected getTextBody(): string {
const formattedAmount = (this.proration.proratedAmount / 100).toFixed(2);
return `Reminder: Your invoice of $${formattedAmount} for team ${this.team.name} is still unpaid. Please pay to avoid restrictions on adding new users.`;
return this.user.t("proration_reminder_text", {
amount: formattedAmount,
teamName: this.team.name,
});
}
}