Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update charge-failed.ts

Kiran K62810828c107
diff --git a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
index e94e99ca9a..02ee7fa2be 100644
--- a/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
+++ b/apps/web/app/(ee)/api/stripe/webhook/charge-failed.ts
@@ -8,6 +8,7 @@ import { stripe } from "@/lib/stripe";
import { sendEmail } from "@dub/email";
import { resend } from "@dub/email/resend";
import { VARIANT_TO_FROM_MAP } from "@dub/email/resend/constants";
+import DomainExpired from "@dub/email/templates/domain-expired";
import DomainRenewalFailed from "@dub/email/templates/domain-renewal-failed";
import PartnerPayoutFailed from "@dub/email/templates/partner-payout-failed";
import { prisma } from "@dub/prisma";
@@ -218,6 +219,24 @@ async function processDomainRenewalInvoice({ invoice }: { invoice: Invoice }) {
},
});
+ const workspace = await prisma.project.findUniqueOrThrow({
+ where: {
+ id: invoice.workspaceId,
+ },
+ include: {
+ users: {
+ where: {
+ role: "owner",
+ },
+ select: {
+ user: true,
+ },
+ },
+ },
+ });
+
+ const workspaceOwners = workspace.users.filter(({ user }) => user.email);
+
// Domain renewal failed 3 times, turn off auto-renew for the domains
if (invoice.failedAttempts >= 3) {
await Promise.allSettled(
@@ -228,6 +247,24 @@ async function processDomainRenewalInvoice({ invoice }: { invoice: Invoice }) {
}),
),
);
+
+ if (workspaceOwners.length > 0) {
+ await resend?.batch.send(
+ workspaceOwners.map(({ user }) => ({
+ from: VARIANT_TO_FROM_MAP.notifications,
+ to: user.email!,
+ subject: "Domain expired",
+ react: DomainExpired({
+ email: user.email!,
+ workspace: {
+ name: workspace.name,
+ slug: workspace.slug,
+ },
+ domains,
+ }),
+ })),
+ );
+ }
}
// We'll retry the invoice 3 times, if it fails 3 times, we'll turn off auto-renew for the domains
@@ -240,43 +277,22 @@ async function processDomainRenewalInvoice({ invoice }: { invoice: Invoice }) {
invoiceId: invoice.id,
},
});
- }
- const workspace = await prisma.project.findUniqueOrThrow({
- where: {
- id: invoice.workspaceId,
- },
- include: {
- users: {
- where: {
- role: "owner",
- },
- select: {
- user: true,
- },
- },
- },
- });
-
- const workspaceOwners = workspace.users.filter(({ user }) => user.email);
-
- if (workspaceOwners.length === 0) {
- console.log("No workspace owners found, skipping...");
- return;
+ if (workspaceOwners.length > 0) {
+ await resend?.batch.send(
+ workspaceOwners.map(({ user }) => ({
+ from: VARIANT_TO_FROM_MAP.notifications,
+ to: user.email!,
+ subject: "Domain renewal failed",
+ react: DomainRenewalFailed({
+ email: user.email!,
+ workspace: {
+ slug: workspace.slug,
+ },
+ domains,
+ }),
+ })),
+ );
+ }
}
-
- await resend?.batch.send(
- workspaceOwners.map(({ user }) => ({
- from: VARIANT_TO_FROM_MAP.notifications,
- to: user.email!,
- subject: "Domain renewal failed",
- react: DomainRenewalFailed({
- email: user.email!,
- workspace: {
- slug: workspace.slug,
- },
- domains,
- }),
- })),
- );
}