Skip to content

Commit

Permalink
[Doom - Downgrade] Email ops when subscription cancelation takes effe…
Browse files Browse the repository at this point in the history
…ct (#2603)
  • Loading branch information
philipperolet authored Nov 20, 2023
1 parent e7642bb commit ac13488
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions front/lib/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,20 @@ export async function sendReactivateSubscriptionEmail(
};
return sendEmail(email, reactivateMessage);
}

export async function sendOpsEmail(workspaceSId: string): Promise<void> {
const opsMessage = {
from: {
name: "System",
email: "ops@dust.tt",
},
subject: `[OPS] A subscription has been canceled`,
html: `<p>Hi Dust ops,</p>
<p>The subscription of workspace '${workspaceSId}' was just canceled. Go to the <a href="https://dust.tt/poke/${workspaceSId}">Poke Page</a> and manually delete its connections</p>
<p>Also, for the first cancellations, quickly check that users have been properly revoked and the plan switched back to free</p>
<p>We'll automate this soon. Just doing that to be extra sure for the ~10 first downgrades.</p>
<p>Sincerely,
<p>Ourselves</p>`,
};
return sendEmail("ops@dust.tt", opsMessage);
}
3 changes: 3 additions & 0 deletions front/pages/api/stripe/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Authenticator } from "@app/lib/auth";
import { front_sequelize } from "@app/lib/databases";
import {
sendCancelSubscriptionEmail,
sendOpsEmail,
sendReactivateSubscriptionEmail,
} from "@app/lib/email";
import { ReturnedAPIErrorType } from "@app/lib/error";
Expand Down Expand Up @@ -351,6 +352,7 @@ async function handler(
// We can end the subscription in our database.
const activeSubscription = await Subscription.findOne({
where: { stripeSubscriptionId: stripeSubscription.id },
include: [Workspace],
});
if (!activeSubscription) {
return apiError(req, res, {
Expand All @@ -366,6 +368,7 @@ async function handler(
status: "ended",
endDate: new Date(),
});
await sendOpsEmail(activeSubscription.workspace.sId);
} else {
logger.warn(
{ event },
Expand Down

0 comments on commit ac13488

Please sign in to comment.