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:
28 files changed
+804
-41
No files matched your search
@@ -42,6 +42,15 @@ type TaskPayloads = {
|
||||
sendAwaitingPaymentEmail: z.infer<
|
||||
typeof import("./tasks/sendAwaitingPaymentEmail").sendAwaitingPaymentEmailPayloadSchema
|
||||
>;
|
||||
sendProrationInvoiceEmail: z.infer<
|
||||
typeof import("./tasks/sendProrationInvoiceEmail").sendProrationInvoiceEmailPayloadSchema
|
||||
>;
|
||||
sendProrationReminderEmail: z.infer<
|
||||
typeof import("./tasks/sendProrationReminderEmail").sendProrationReminderEmailPayloadSchema
|
||||
>;
|
||||
cancelProrationReminder: z.infer<
|
||||
typeof import("./tasks/cancelProrationReminder").cancelProrationReminderPayloadSchema
|
||||
>;
|
||||
webhookDelivery: z.infer<
|
||||
typeof import("@calcom/features/webhooks/lib/types/webhookTask").webhookTaskPayloadSchema
|
||||
>;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { z } from "zod";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["cancelProrationReminder"] });
|
||||
|
||||
export const cancelProrationReminderPayloadSchema = z.object({
|
||||
prorationId: z.string(),
|
||||
});
|
||||
|
||||
export async function cancelProrationReminder(payload: string): Promise<void> {
|
||||
try {
|
||||
const { prorationId } = cancelProrationReminderPayloadSchema.parse(JSON.parse(payload));
|
||||
|
||||
log.debug(`Processing cancelProrationReminder task for prorationId ${prorationId}`);
|
||||
|
||||
const { default: tasker } = await import("@calcom/features/tasker");
|
||||
|
||||
await tasker.cancelWithReference(`proration-reminder-${prorationId}`, "sendProrationReminderEmail");
|
||||
|
||||
log.debug(`Successfully cancelled proration reminder for prorationId ${prorationId}`);
|
||||
} catch (error) {
|
||||
log.warn(
|
||||
`Failed to cancel proration reminder`,
|
||||
safeStringify({ payload, error: error instanceof Error ? error.message : String(error) })
|
||||
);
|
||||
// Don't throw - cancellation failure is non-critical
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
import { IS_PRODUCTION } from "@calcom/lib/constants";
|
||||
|
||||
import type { TaskHandler, TaskTypes } from "../tasker";
|
||||
|
||||
/**
|
||||
@@ -33,6 +32,12 @@ const tasks: Record<TaskTypes, () => Promise<TaskHandler>> = {
|
||||
executeAIPhoneCall: () => import("./executeAIPhoneCall").then((module) => module.executeAIPhoneCall),
|
||||
sendAwaitingPaymentEmail: () =>
|
||||
import("./sendAwaitingPaymentEmail").then((module) => module.sendAwaitingPaymentEmail),
|
||||
sendProrationInvoiceEmail: () =>
|
||||
import("./sendProrationInvoiceEmail").then((module) => module.sendProrationInvoiceEmail),
|
||||
sendProrationReminderEmail: () =>
|
||||
import("./sendProrationReminderEmail").then((module) => module.sendProrationReminderEmail),
|
||||
cancelProrationReminder: () =>
|
||||
import("./cancelProrationReminder").then((module) => module.cancelProrationReminder),
|
||||
bookingAudit: () => import("./bookingAudit").then((module) => module.bookingAudit),
|
||||
webhookDelivery: () => import("./webhookDelivery").then((module) => module.webhookDelivery),
|
||||
};
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { z } from "zod";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["sendProrationInvoiceEmail"] });
|
||||
|
||||
export const sendProrationInvoiceEmailPayloadSchema = z.object({
|
||||
prorationId: z.string(),
|
||||
teamId: z.number(),
|
||||
isAutoCharge: z.boolean(),
|
||||
});
|
||||
|
||||
export async function sendProrationInvoiceEmail(payload: string): Promise<void> {
|
||||
try {
|
||||
const { prorationId, teamId, isAutoCharge } = sendProrationInvoiceEmailPayloadSchema.parse(
|
||||
JSON.parse(payload)
|
||||
);
|
||||
|
||||
log.debug(`Processing sendProrationInvoiceEmail task for prorationId ${prorationId}, teamId ${teamId}`);
|
||||
|
||||
const { ProrationEmailService } = await import(
|
||||
"@calcom/features/ee/billing/service/proration/ProrationEmailService"
|
||||
);
|
||||
|
||||
const emailService = new ProrationEmailService();
|
||||
await emailService.sendInvoiceEmail({ prorationId, teamId, isAutoCharge });
|
||||
} catch (error) {
|
||||
log.error(
|
||||
`Failed to send proration invoice email`,
|
||||
safeStringify({ payload, error: error instanceof Error ? error.message : String(error) })
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { safeStringify } from "@calcom/lib/safeStringify";
|
||||
import { z } from "zod";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["sendProrationReminderEmail"] });
|
||||
|
||||
export const sendProrationReminderEmailPayloadSchema = z.object({
|
||||
prorationId: z.string(),
|
||||
teamId: z.number(),
|
||||
});
|
||||
|
||||
export async function sendProrationReminderEmail(payload: string): Promise<void> {
|
||||
try {
|
||||
const { prorationId, teamId } = sendProrationReminderEmailPayloadSchema.parse(JSON.parse(payload));
|
||||
|
||||
log.debug(`Processing sendProrationReminderEmail task for prorationId ${prorationId}, teamId ${teamId}`);
|
||||
|
||||
const { ProrationEmailService } = await import(
|
||||
"@calcom/features/ee/billing/service/proration/ProrationEmailService"
|
||||
);
|
||||
|
||||
const emailService = new ProrationEmailService();
|
||||
await emailService.sendReminderEmail({ prorationId, teamId });
|
||||
} catch (error) {
|
||||
log.error(
|
||||
`Failed to send proration reminder email`,
|
||||
safeStringify({ payload, error: error instanceof Error ? error.message : String(error) })
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user