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.

Add invoice.payment_failed Stripe Webhook

Steven Teyf5a8dc806b7d
diff --git a/apps/web/app/admin.dub.co/components/send-thanks.tsx b/apps/web/app/admin.dub.co/components/send-thanks.tsx
deleted file mode 100644
index 99800e28d3..0000000000
--- a/apps/web/app/admin.dub.co/components/send-thanks.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-"use client";
-
-import { LoadingSpinner } from "@dub/ui";
-import { cn } from "@dub/utils";
-import { useFormStatus } from "react-dom";
-import { toast } from "sonner";
-
-export default function SendThanks() {
- return (
- <div className="flex flex-col space-y-5">
- <form
- action={async (formData) => {
- if (
- !confirm(
- `This will send an email to ${formData.get("email")} with a thank you message. Are you sure?`,
- )
- ) {
- return;
- }
- await fetch("/api/admin/send-thanks", {
- method: "POST",
- body: JSON.stringify({
- email: formData.get("email"),
- }),
- }).then(async (res) => {
- if (res.ok) {
- toast.success("Successfully sent email");
- } else {
- const error = await res.text();
- toast.error(error);
- }
- });
- }}
- >
- <Form />
- </form>
- </div>
- );
-}
-
-const Form = () => {
- const { pending } = useFormStatus();
-
- return (
- <div className="relative flex w-full rounded-md shadow-sm">
- <input
- name="email"
- id="email"
- type="email"
- required
- disabled={pending}
- autoComplete="off"
- className={cn(
- "block w-full rounded-md border-gray-300 text-sm text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500",
- pending && "bg-gray-100",
- )}
- placeholder="[email protected]"
- aria-invalid="true"
- />
- {pending && (
- <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-gray-400" />
- )}
- </div>
- );
-};
diff --git a/apps/web/app/admin.dub.co/page.tsx b/apps/web/app/admin.dub.co/page.tsx
index f339c13a92..e0315b5118 100644
--- a/apps/web/app/admin.dub.co/page.tsx
+++ b/apps/web/app/admin.dub.co/page.tsx
@@ -2,7 +2,6 @@ import { constructMetadata } from "@dub/utils";
import ImpersonateUser from "./components/impersonate-user";
import ImpersonateWorkspace from "./components/impersonate-workspace";
import RefreshDomain from "./components/refresh-domain";
-import SendThanks from "./components/send-thanks";
export const metadata = constructMetadata({
title: "Dub Admin",
@@ -31,11 +30,6 @@ export default function AdminPage() {
</p>
<RefreshDomain />
</div>
- <div className="flex flex-col space-y-4 px-5 py-10">
- <h2 className="text-xl font-semibold">Send Thanks</h2>
- <p className="text-sm text-gray-500">Send thank you email to a user</p>
- <SendThanks />
- </div>
</div>
);
}
diff --git a/apps/web/app/api/admin/send-thanks/route.ts b/apps/web/app/api/admin/send-thanks/route.ts
deleted file mode 100644
index 5b0b0b9b94..0000000000
--- a/apps/web/app/api/admin/send-thanks/route.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { withAdmin } from "@/lib/auth";
-import { sendEmail } from "emails";
-import UpgradeEmail from "emails/upgrade-email";
-import { NextResponse } from "next/server";
-
-// POST /api/admin/send-thanks
-export const POST = withAdmin(async ({ req }) => {
- const { email } = await req.json();
-
- await sendEmail({
- email,
- subject: "Thank you for upgrading to Dub.co Pro!",
- react: UpgradeEmail({
- name: null,
- email,
- plan: "pro",
- }),
- marketing: true,
- bcc: process.env.TRUSTPILOT_BCC_EMAIL,
- });
-
- return NextResponse.json({ success: true });
-});
diff --git a/apps/web/app/api/stripe/webhook/checkout-session-completed.ts b/apps/web/app/api/stripe/webhook/checkout-session-completed.ts
new file mode 100644
index 0000000000..caf14863b5
--- /dev/null
+++ b/apps/web/app/api/stripe/webhook/checkout-session-completed.ts
@@ -0,0 +1,94 @@
+import { limiter } from "@/lib/cron/limiter";
+import { prisma } from "@/lib/prisma";
+import { stripe } from "@/lib/stripe";
+import { getPlanFromPriceId, log } from "@dub/utils";
+import { sendEmail } from "emails";
+import UpgradeEmail from "emails/upgrade-email";
+import Stripe from "stripe";
+
+export async function checkoutSessionCompleted(event: Stripe.Event) {
+ const checkoutSession = event.data.object as Stripe.Checkout.Session;
+
+ if (
+ checkoutSession.client_reference_id === null ||
+ checkoutSession.customer === null
+ ) {
+ await log({
+ message: "Missing items in Stripe webhook callback",
+ type: "errors",
+ });
+ return;
+ }
+
+ const subscription = await stripe.subscriptions.retrieve(
+ checkoutSession.subscription as string,
+ );
+ const priceId = subscription.items.data[0].price.id;
+
+ const plan = getPlanFromPriceId(priceId);
+
+ if (!plan) {
+ await log({
+ message: `Invalid price ID in checkout.session.completed event: ${priceId}`,
+ type: "errors",
+ });
+ return;
+ }
+
+ const stripeId = checkoutSession.customer.toString();
+
+ // when the workspace subscribes to a plan, set their stripe customer ID
+ // in the database for easy identification in future webhook events
+ // also update the billingCycleStart to today's date
+
+ const workspace = await prisma.project.update({
+ where: {
+ id: checkoutSession.client_reference_id,
+ },
+ data: {
+ stripeId,
+ billingCycleStart: new Date().getDate(),
+ plan: plan.name.toLowerCase(),
+ usageLimit: plan.limits.clicks!,
+ linksLimit: plan.limits.links!,
+ domainsLimit: plan.limits.domains!,
+ aiLimit: plan.limits.ai!,
+ tagsLimit: plan.limits.tags!,
+ usersLimit: plan.limits.users!,
+ },
+ select: {
+ users: {
+ select: {
+ user: {
+ select: {
+ name: true,
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ const users = workspace.users.map(({ user }) => ({
+ name: user.name,
+ email: user.email,
+ }));
+
+ await Promise.allSettled(
+ users.map((user) => {
+ limiter.schedule(() =>
+ sendEmail({
+ email: user.email as string,
+ subject: `Thank you for upgrading to Dub.co ${plan.name}!`,
+ react: UpgradeEmail({
+ name: user.name,
+ email: user.email as string,
+ plan: plan.name,
+ }),
+ marketing: true,
+ }),
+ );
+ }),
+ );
+}
diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts
new file mode 100644
index 0000000000..f32aa59746
--- /dev/null
+++ b/apps/web/app/api/stripe/webhook/customer-subscription-deleted.ts
@@ -0,0 +1,103 @@
+import { prisma } from "@/lib/prisma";
+import { redis } from "@/lib/upstash";
+import { FREE_PLAN, log } from "@dub/utils";
+import { sendEmail } from "emails";
+import { NextResponse } from "next/server";
+import Stripe from "stripe";
+
+export async function customerSubscriptionDeleted(event: Stripe.Event) {
+ const subscriptionDeleted = event.data.object as Stripe.Subscription;
+
+ const stripeId = subscriptionDeleted.customer.toString();
+
+ // If a workspace deletes their subscription, reset their usage limit in the database to 1000.
+ // Also remove the root domain redirect for all their domains from Redis.
+ const workspace = await prisma.project.findUnique({
+ where: {
+ stripeId,
+ },
+ select: {
+ id: true,
+ slug: true,
+ domains: true,
+ users: {
+ select: {
+ user: {
+ select: {
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ if (!workspace) {
+ await log({
+ message:
+ "Workspace with Stripe ID *`" +
+ stripeId +
+ "`* not found in Stripe webhook `customer.subscription.deleted` callback",
+ type: "errors",
+ });
+ return NextResponse.json({ received: true });
+ }
+
+ const workspaceUsers = workspace.users.map(
+ ({ user }) => user.email as string,
+ );
+
+ const pipeline = redis.pipeline();
+ // remove root domain redirect for all domains
+ workspace.domains.forEach((domain) => {
+ pipeline.hset(domain.slug.toLowerCase(), {
+ _root: {
+ id: domain.id,
+ projectId: workspace.id,
+ },
+ });
+ });
+
+ await Promise.allSettled([
+ prisma.project.update({
+ where: {
+ stripeId,
+ },
+ data: {
+ plan: "free",
+ usageLimit: FREE_PLAN.limits.clicks!,
+ linksLimit: FREE_PLAN.limits.links!,
+ domainsLimit: FREE_PLAN.limits.domains!,
+ aiLimit: FREE_PLAN.limits.ai!,
+ tagsLimit: FREE_PLAN.limits.tags!,
+ usersLimit: FREE_PLAN.limits.users!,
+ },
+ }),
+ pipeline.exec(),
+ log({
+ message:
+ ":cry: Workspace *`" + workspace.slug + "`* deleted their subscription",
+ type: "cron",
+ mention: true,
+ }),
+ workspaceUsers.map((email) =>
+ sendEmail({
+ email,
+ subject: "Feedback on your Dub.co experience?",
+ text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",
+ }),
+ ),
+ workspace.domains.forEach((domain) => {
+ prisma.domain.update({
+ where: {
+ id: domain.id,
+ },
+ data: {
+ target: null,
+ noindex: false,
+ },
+ });
+ }),
+ ]);
+}
diff --git a/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts b/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts
new file mode 100644
index 0000000000..75c50ea530
--- /dev/null
+++ b/apps/web/app/api/stripe/webhook/customer-subscription-updated.ts
@@ -0,0 +1,58 @@
+import { prisma } from "@/lib/prisma";
+import { getPlanFromPriceId, log } from "@dub/utils";
+import { NextResponse } from "next/server";
+import Stripe from "stripe";
+
+export async function customerSubscriptionUpdated(event: Stripe.Event) {
+ const subscriptionUpdated = event.data.object as Stripe.Subscription;
+ const priceId = subscriptionUpdated.items.data[0].price.id;
+
+ const plan = getPlanFromPriceId(priceId);
+
+ if (!plan) {
+ await log({
+ message: `Invalid price ID in customer.subscription.updated event: ${priceId}`,
+ type: "errors",
+ });
+ return;
+ }
+
+ const stripeId = subscriptionUpdated.customer.toString();
+
+ const workspace = await prisma.project.findUnique({
+ where: {
+ stripeId,
+ },
+ });
+
+ if (!workspace) {
+ await log({
+ message:
+ "Workspace with Stripe ID *`" +
+ stripeId +
+ "`* not found in Stripe webhook `customer.subscription.updated` callback",
+ type: "errors",
+ });
+ return NextResponse.json({ received: true });
+ }
+
+ const newPlan = plan.name.toLowerCase();
+
+ // If a workspace upgrades/downgrades their subscription, update their usage limit in the database.
+ if (workspace.plan !== newPlan) {
+ await prisma.project.update({
+ where: {
+ stripeId,
+ },
+ data: {
+ plan: newPlan,
+ usageLimit: plan.limits.clicks!,
+ linksLimit: plan.limits.links!,
+ domainsLimit: plan.limits.domains!,
+ aiLimit: plan.limits.ai!,
+ tagsLimit: plan.limits.tags!,
+ usersLimit: plan.limits.users!,
+ },
+ });
+ }
+}
diff --git a/apps/web/app/api/stripe/webhook/invoice-payment-failed.tsx b/apps/web/app/api/stripe/webhook/invoice-payment-failed.tsx
new file mode 100644
index 0000000000..f7aa88a952
--- /dev/null
+++ b/apps/web/app/api/stripe/webhook/invoice-payment-failed.tsx
@@ -0,0 +1,76 @@
+import { prisma } from "@/lib/prisma";
+import { log } from "@dub/utils";
+import { sendEmail } from "emails";
+import FailedPayment from "emails/failed-payment";
+import Stripe from "stripe";
+
+export async function invoicePaymentFailed(event: Stripe.Event) {
+ const {
+ customer: stripeId,
+ attempt_count: attemptCount,
+ amount_due: amountDue,
+ } = event.data.object as Stripe.Invoice;
+
+ if (!stripeId) {
+ await log({
+ message: "Missing customer ID in invoice.payment_failed event",
+ type: "errors",
+ });
+ return;
+ }
+
+ const workspace = await prisma.project.findUnique({
+ where: {
+ stripeId: stripeId.toString(),
+ },
+ select: {
+ name: true,
+ slug: true,
+ users: {
+ select: {
+ user: {
+ select: {
+ name: true,
+ email: true,
+ },
+ },
+ },
+ },
+ },
+ });
+
+ if (!workspace) {
+ await log({
+ message: `Project with Stripe ID ${stripeId} not found in invoice.payment_failed event`,
+ type: "errors",
+ });
+ return;
+ }
+
+ await Promise.all(
+ workspace.users.map(({ user }) =>
+ sendEmail({
+ email: user.email as string,
+ subject: `${
+ attemptCount == 2
+ ? "2nd notice: "
+ : attemptCount == 3
+ ? "3rd notice: "
+ : ""
+ }Your payment for Dub.co failed`,
+ react: (
+ <FailedPayment
+ attemptCount={attemptCount}
+ amountDue={amountDue}
+ user={{
+ name: user.name,
+ email: user.email as string,
+ }}
+ workspace={workspace}
+ />
+ ),
+ }),
+ ),
+ );
+}
diff --git a/apps/web/app/api/stripe/webhook/route.ts b/apps/web/app/api/stripe/webhook/route.ts
index 3959f68a33..ef9472a428 100644
--- a/apps/web/app/api/stripe/webhook/route.ts
+++ b/apps/web/app/api/stripe/webhook/route.ts
@@ -1,17 +1,17 @@
-import { limiter } from "@/lib/cron/limiter";
-import { prisma } from "@/lib/prisma";
import { stripe } from "@/lib/stripe";
-import { redis } from "@/lib/upstash";
-import { FREE_PLAN, getPlanFromPriceId, log } from "@dub/utils";
-import { sendEmail } from "emails";
-import UpgradeEmail from "emails/upgrade-email";
+import { log } from "@dub/utils";
import { NextResponse } from "next/server";
import Stripe from "stripe";
+import { checkoutSessionCompleted } from "./checkout-session-completed";
+import { customerSubscriptionDeleted } from "./customer-subscription-deleted";
+import { customerSubscriptionUpdated } from "./customer-subscription-updated";
+import { invoicePaymentFailed } from "./invoice-payment-failed";
const relevantEvents = new Set([
"checkout.session.completed",
"customer.subscription.updated",
"customer.subscription.deleted",
+ "invoice.payment_failed",
]);
// POST /api/stripe/webhook – listen to Stripe webhooks
@@ -29,263 +29,34 @@ export const POST = async (req: Request) => {
status: 400,
});
}
- if (relevantEvents.has(event.type)) {
- try {
- if (event.type === "checkout.session.completed") {
- const checkoutSession = event.data.object as Stripe.Checkout.Session;
- if (
- checkoutSession.client_reference_id === null ||
- checkoutSession.customer === null
- ) {
- await log({
- message: "Missing items in Stripe webhook callback",
- type: "errors",
- });
- return;
- }
-
- const subscription = await stripe.subscriptions.retrieve(
- checkoutSession.subscription as string,
- );
- const priceId = subscription.items.data[0].price.id;
-
- const plan = getPlanFromPriceId(priceId);
-
- if (!plan) {
- await log({
- message: `Invalid price ID in checkout.session.completed event: ${priceId}`,
- type: "errors",
- });
- return;
- }
-
- const stripeId = checkoutSession.customer.toString();
-
- // when the workspace subscribes to a plan, set their stripe customer ID
- // in the database for easy identification in future webhook events
- // also update the billingCycleStart to today's date
-
- const workspace = await prisma.project.update({
- where: {
- id: checkoutSession.client_reference_id,
- },
- data: {
- stripeId,
- billingCycleStart: new Date().getDate(),
- plan: plan.name.toLowerCase(),
- usageLimit: plan.limits.clicks!,
- linksLimit: plan.limits.links!,
- domainsLimit: plan.limits.domains!,
- aiLimit: plan.limits.ai!,
- tagsLimit: plan.limits.tags!,
- usersLimit: plan.limits.users!,
- },
- select: {
- users: {
- select: {
- user: {
- select: {
- name: true,
- email: true,
- },
- },
- },
- },
- },
- });
-
- const users = workspace.users.map(({ user }) => ({
- name: user.name,
- email: user.email,
- }));
-
- await Promise.allSettled(
- users.map((user) => {
- limiter.schedule(() =>
- sendEmail({
- email: user.email as string,
- subject: `Thank you for upgrading to Dub.co ${plan.name}!`,
- react: UpgradeEmail({
- name: user.name,
- email: user.email as string,
- plan: plan.name,
- }),
- marketing: true,
- }),
- );
- }),
- );
- }
-
- // for subscription updates
- if (event.type === "customer.subscription.updated") {
- const subscriptionUpdated = event.data.object as Stripe.Subscription;
- const priceId = subscriptionUpdated.items.data[0].price.id;
-
- const plan = getPlanFromPriceId(priceId);
-
- if (!plan) {
- await log({
- message: `Invalid price ID in customer.subscription.updated event: ${priceId}`,
- type: "errors",
- });
- return;
- }
-
- const stripeId = subscriptionUpdated.customer.toString();
-
- const workspace = await prisma.project.findUnique({
- where: {
- stripeId,
- },
- });
-
- if (!workspace) {
- await log({
- message:
- "Workspace with Stripe ID *`" +
- stripeId +
- "`* not found in Stripe webhook `customer.subscription.updated` callback",
- type: "errors",
- });
- return NextResponse.json({ received: true });
- }
-
- const newPlan = plan.name.toLowerCase();
-
- // If a workspace upgrades/downgrades their subscription, update their usage limit in the database.
- if (workspace.plan !== newPlan) {
- await prisma.project.update({
- where: {
- stripeId,
- },
- data: {
- plan: newPlan,
- usageLimit: plan.limits.clicks!,
- linksLimit: plan.limits.links!,
- domainsLimit: plan.limits.domains!,
- aiLimit: plan.limits.ai!,
- tagsLimit: plan.limits.tags!,
- usersLimit: plan.limits.users!,
- },
- });
- }
- }
-
- // If workspace cancels their subscription
- if (event.type === "customer.subscription.deleted") {
- const subscriptionDeleted = event.data.object as Stripe.Subscription;
-
- const stripeId = subscriptionDeleted.customer.toString();
-
- // If a workspace deletes their subscription, reset their usage limit in the database to 1000.
- // Also remove the root domain redirect for all their domains from Redis.
- const workspace = await prisma.project.findUnique({
- where: {
- stripeId,
- },
- select: {
- id: true,
- slug: true,
- domains: true,
- users: {
- select: {
- user: {
- select: {
- email: true,
- },
- },
- },
- },
- },
- });
-
- if (!workspace) {
- await log({
- message:
- "Workspace with Stripe ID *`" +
- stripeId +
- "`* not found in Stripe webhook `customer.subscription.deleted` callback",
- type: "errors",
- });
- return NextResponse.json({ received: true });
- }
-
- const workspaceUsers = workspace.users.map(
- ({ user }) => user.email as string,
- );
-
- const pipeline = redis.pipeline();
- // remove root domain redirect for all domains
- workspace.domains.forEach((domain) => {
- pipeline.hset(domain.slug.toLowerCase(), {
- _root: {
- id: domain.id,
- projectId: workspace.id,
- },
- });
- });
-
- await Promise.allSettled([
- prisma.project.update({
- where: {
- stripeId,
- },
- data: {
- plan: "free",
- usageLimit: FREE_PLAN.limits.clicks!,
- linksLimit: FREE_PLAN.limits.links!,
- domainsLimit: FREE_PLAN.limits.domains!,
- aiLimit: FREE_PLAN.limits.ai!,
- tagsLimit: FREE_PLAN.limits.tags!,
- usersLimit: FREE_PLAN.limits.users!,
- },
- }),
- pipeline.exec(),
- log({
- message:
- ":cry: Workspace *`" +
- workspace.slug +
- "`* deleted their subscription",
- type: "cron",
- mention: true,
- }),
- workspaceUsers.map((email) =>
- sendEmail({
- email,
- subject: "Feedback on your Dub.co experience?",
- text: "Hey!\n\nI noticed you recently cancelled your Dub.co subscription – we're sorry to see you go!\n\nI'd love to hear your feedback on your experience with Dub – what could we have done better?\n\nThanks!\n\nSteven Tey\nFounder, Dub.co",
- }),
- ),
- workspace.domains.forEach((domain) => {
- prisma.domain.update({
- where: {
- id: domain.id,
- },
- data: {
- target: null,
- noindex: false,
- },
- });
- }),
- ]);
- }
- } catch (error) {
- await log({
- message: `Stripe webhook failed. Error: ${error.message}`,
- type: "errors",
- });
- return new Response(
- 'Webhook error: "Webhook handler failed. View logs."',
- {
- status: 400,
- },
- );
+ // Ignore unsupported events
+ if (!relevantEvents.has(event.type)) {
+ return new Response("Unsupported event, skipping...", {
+ status: 200,
+ });
+ }
+ try {
+ switch (event.type) {
+ case "checkout.session.completed":
+ await checkoutSessionCompleted(event);
+ break;
+ case "customer.subscription.updated":
+ await customerSubscriptionUpdated(event);
+ break;
+ case "customer.subscription.deleted":
+ await customerSubscriptionDeleted(event);
+ break;
+ case "invoice.payment_failed":
+ await invoicePaymentFailed(event);
+ break;
}
- } else {
- return new Response(`🤷‍♀️ Unhandled event type: ${event.type}`, {
+ } catch (error) {
+ await log({
+ message: `Stripe webhook failed. Error: ${error.message}`,
+ type: "errors",
+ });
+ return new Response('Webhook error: "Webhook handler failed. View logs."', {
status: 400,
});
}
diff --git a/apps/web/emails/failed-payment.tsx b/apps/web/emails/failed-payment.tsx
new file mode 100644
index 0000000000..09edf6e08e
--- /dev/null
+++ b/apps/web/emails/failed-payment.tsx
@@ -0,0 +1,87 @@
+import { DUB_WORDMARK } from "@dub/utils";
+import { Project } from "@prisma/client";
+import {
+ Body,
+ Container,
+ Head,
+ Heading,
+ Html,
+ Img,
+ Link,
+ Preview,
+ Section,
+ Tailwind,
+ Text,
+} from "@react-email/components";
+import Footer from "./components/footer";
+
+export default function FailedPayment({
+ user = { name: "Brendon Urie", email: "[email protected]" },
+ workspace = { name: "Dub", slug: "dub" },
+ amountDue = 2400,
+ attemptCount = 2,
+}: {
+ user: { name?: string | null; email: string };
+ workspace: Pick<Project, "name" | "slug">;
+ amountDue: number;
+ attemptCount: number;
+}) {
+ const title = `${
+ attemptCount == 2 ? "2nd notice: " : attemptCount == 3 ? "3rd notice: " : ""
+ }Your payment for Dub.co failed`;
+
+ return (
+ <Html>
+ <Head />
+ <Preview>{title}</Preview>
+ <Tailwind>
+ <Body className="mx-auto my-auto bg-white font-sans">
+ <Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">
+ <Section className="mt-8">
+ <Img
+ src={DUB_WORDMARK}
+ height="40"
+ alt="Dub"
+ className="mx-auto my-0"
+ />
+ </Section>
+ <Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">
+ {attemptCount == 2 ? "2nd " : attemptCount == 3 ? "3rd " : ""}
+ Failed Payment for Dub.co
+ </Heading>
+ <Text className="text-sm leading-6 text-black">
+ Hey{user.name ? `, ${user.name}` : ""}!
+ </Text>
+ <Text className="text-sm leading-6 text-black">
+ Your payment of{" "}
+ <code className="text-purple-600">${amountDue / 100}</code> for
+ your Dub workspace{" "}
+ <code className="text-purple-600">{workspace.name}</code> has
+ failed. Please{" "}
+ <Link
+ href="https://dub.co/help/article/how-to-change-billing-information"
+ className="font-medium text-blue-600 no-underline"
+ >
+ update your payment information
+ </Link>{" "}
+ using the link below:
+ </Text>
+ <Section className="my-8 text-center">
+ <Link
+ className="rounded-full bg-black px-6 py-3 text-center text-[12px] font-semibold text-white no-underline"
+ href={`https://app.dub.co/${workspace.slug}/settings/billing`}
+ >
+ Update payment information
+ </Link>
+ </Section>
+ <Text className="text-sm leading-6 text-black">
+ If you have any questions, feel free to respond to this email –
+ we're happy to help!
+ </Text>
+ <Footer email={user.email} />
+ </Container>
+ </Body>
+ </Tailwind>
+ </Html>
+ );
+}
diff --git a/apps/web/scripts/send-emails.tsx b/apps/web/scripts/send-emails.tsx
new file mode 100644
index 0000000000..0f0573cd04
--- /dev/null
+++ b/apps/web/scripts/send-emails.tsx
@@ -0,0 +1,40 @@
+import "dotenv-flow/config";
+import { sendEmail } from "emails";
+import FailedPayment from "emails/failed-payment";
+
+const attemptCount = 2;
+const amountDue = 2400;
+const user = {
+ name: "Steven",
+ email: "[email protected]",
+};
+const workspace = {
+ name: "Dub",
+ slug: "dub",
+};
+
+async function main() {
+ const res = await sendEmail({
+ email: user.email as string,
+ subject: `${
+ attemptCount == 2
+ ? "2nd notice: "
+ : attemptCount == 3
+ ? "3rd notice: "
+ : ""
+ }Your payment for Dub.co failed`,
+ react: (
+ <FailedPayment
+ attemptCount={attemptCount}
+ amountDue={amountDue}
+ user={user}
+ workspace={workspace}
+ />
+ ),
+ });
+
+ console.log({ res });
+}
+
+main();
diff --git a/packages/utils/src/constants/index.ts b/packages/utils/src/constants/index.ts
index f7724a5654..1b97b5ba5e 100644
--- a/packages/utils/src/constants/index.ts
+++ b/packages/utils/src/constants/index.ts
@@ -57,6 +57,7 @@ export const ADMIN_HOSTNAMES = new Set([
]);
export const DUB_LOGO = "https://assets.dub.co/logo.png";
+export const DUB_WORDMARK = "https://assets.dub.co/wordmark.png";
export const DUB_THUMBNAIL = "https://assets.dub.co/thumbnail.jpg";
export const DUB_WORKSPACE_ID = "cl7pj5kq4006835rbjlt2ofka";