Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

feat: update the upgrade email notification

Marc Seitz338bb51b79db
diff --git a/components/emails/upgrade-plan.tsx b/components/emails/upgrade-plan.tsx
index 5666b575..e7326934 100644
--- a/components/emails/upgrade-plan.tsx
+++ b/components/emails/upgrade-plan.tsx
@@ -14,6 +14,8 @@ import {
Text,
} from "@react-email/components";
+import { Footer } from "./shared/footer";
+
interface UpgradePlanEmailProps {
name: string | null | undefined;
planType: string;
@@ -21,10 +23,18 @@ interface UpgradePlanEmailProps {
const UpgradePlanEmail = ({
name,
- planType = "pro",
+ planType = "datarooms-plus",
}: UpgradePlanEmailProps) => {
const previewText = `The document sharing infrastructure for the modern web`;
+ const PLAN_TYPE_MAP = {
+ pro: "Pro",
+ business: "Business",
+ datarooms: "Data Rooms",
+ "datarooms-plus": "Data Rooms Plus",
+ };
+
+ const planTypeText = PLAN_TYPE_MAP[planType as keyof typeof PLAN_TYPE_MAP];
const features: any = {
pro: [
"Custom branding",
@@ -52,8 +62,7 @@ const UpgradePlanEmail = ({
],
};
- const planTypeText = planType.toLowerCase();
- const planFeatures = features[planTypeText];
+ const planFeatures = features[planType];
return (
<Html>
@@ -66,18 +75,18 @@ const UpgradePlanEmail = ({
<span className="font-bold tracking-tighter">Papermark</span>
</Text>
<Text className="font-seminbold mx-0 mb-8 mt-4 p-0 text-center text-xl">
- Thanks for upgrading to Papermark {planType}!
+ Thanks for upgrading to Papermark {planTypeText}!
</Text>
<Text className="text-sm leading-6 text-black">
Hey{name && ` ${name}`}!
</Text>
<Text className="text-sm">
Marc is here. I wanted to personally reach out to thank you for
- upgrading to Papermark {planType}!
+ upgrading to Papermark {planTypeText}!
</Text>
<Text className="text-sm leading-6 text-black">
- On the {planType} plan, you now have access to:
+ On the {planTypeText} plan, you now have access to:
</Text>
{planFeatures?.map(
(feature: string, index: number) => (
@@ -96,9 +105,7 @@ const UpgradePlanEmail = ({
style={{ padding: "12px 20px" }}
>
Share your{" "}
- {planTypeText.includes("datarooms")
- ? "data rooms"
- : "documents"}
+ {planType.includes("datarooms") ? "data rooms" : "documents"}
</Button>
</Section>
<Section>
@@ -108,23 +115,7 @@ const UpgradePlanEmail = ({
</Text>
<Text className="text-sm text-gray-400">Marc from Papermark</Text>
</Section>
- <Hr />
- <Section className="mt-8 text-gray-400">
- <Text className="text-xs">
- © {new Date().getFullYear()}{" "}
- <a
- href="https://www.papermark.com"
- className="text-gray-400 no-underline"
- target="_blank"
- >
- papermark.com
- </a>
- </Text>
- <Text className="text-xs">
- If you have any feedback or questions about this email, simply
- reply to it. I&apos;d love to hear from you!
- </Text>
- </Section>
+ <Footer />
</Container>
</Body>
</Tailwind>
diff --git a/ee/stripe/webhooks/checkout-session-completed.ts b/ee/stripe/webhooks/checkout-session-completed.ts
index 74aded70..a125a9ab 100644
--- a/ee/stripe/webhooks/checkout-session-completed.ts
+++ b/ee/stripe/webhooks/checkout-session-completed.ts
@@ -5,10 +5,12 @@ import {
PRO_PLAN_LIMITS,
} from "@/ee/limits/constants";
import { stripeInstance } from "@/ee/stripe";
+import { waitUntil } from "@vercel/functions";
import Stripe from "stripe";
import { sendUpgradePlanEmail } from "@/lib/emails/send-upgrade-plan";
import prisma from "@/lib/prisma";
+import { sendUpgradeOneMonthCheckinEmailTask } from "@/lib/trigger/send-scheduled-email";
import { log } from "@/lib/utils";
import { getPlanFromPriceId } from "../utils";
@@ -100,7 +102,7 @@ export async function checkoutSessionCompleted(
});
// if event creation time more than 1 hour ago, return
- if (event.created > Date.now() - 1 * 60 * 60 * 1000) {
+ if (event.created < Date.now() / 1000 - 1 * 60 * 60) {
await log({
message: `Checkout session completed event created more than 1 hour ago: ${event.id}`,
type: "error",
@@ -109,11 +111,14 @@ export async function checkoutSessionCompleted(
}
// Send thank you email to project owner if they are a new customer
- await sendUpgradePlanEmail({
- user: {
- email: team.users[0].user.email as string,
- name: team.users[0].user.name as string,
- },
- planType: plan.slug,
- });
+ waitUntil(
+ sendUpgradePlanEmail({
+ user: {
+ email: team.users[0].user.email as string,
+ name: team.users[0].user.name as string,
+ },
+ planType: plan.slug,
+ }),
+ );
+
}
diff --git a/lib/emails/send-upgrade-plan.ts b/lib/emails/send-upgrade-plan.ts
index a89d84bb..69d51269 100644
--- a/lib/emails/send-upgrade-plan.ts
+++ b/lib/emails/send-upgrade-plan.ts
@@ -1,18 +1,28 @@
-import UpgradePlanEmail from "@/components/emails/upgrade-plan";
-
import { sendEmail } from "@/lib/resend";
import { CreateUserEmailProps } from "@/lib/types";
+import UpgradePlanEmail from "@/components/emails/upgrade-plan";
+
+const PLAN_TYPE_MAP = {
+ pro: "Pro",
+ business: "Business",
+ datarooms: "Data Rooms",
+ "datarooms-plus": "Data Rooms Plus",
+};
+
export const sendUpgradePlanEmail = async (
params: CreateUserEmailProps & { planType: string },
) => {
const { name, email } = params.user;
const { planType } = params;
const emailTemplate = UpgradePlanEmail({ name, planType });
+
+ const planTypeText = PLAN_TYPE_MAP[planType as keyof typeof PLAN_TYPE_MAP];
+
try {
await sendEmail({
to: email as string,
- subject: `Thank you for upgrading to Papermark ${planType}!`,
+ subject: `Thank you for upgrading to Papermark ${planTypeText}!`,
react: emailTemplate,
test: process.env.NODE_ENV === "development",
});
diff --git a/pages/api/stripe/webhook.ts b/pages/api/stripe/webhook.ts
index d8eca84f..a7fb3c5b 100644
--- a/pages/api/stripe/webhook.ts
+++ b/pages/api/stripe/webhook.ts
@@ -10,7 +10,9 @@ import type Stripe from "stripe";
import { log } from "@/lib/utils";
// Stripe requires the raw body to construct the event.
+// add supportsResponseStreaming to enable waitUntil
export const config = {
+ supportsResponseStreaming: true,
api: {
bodyParser: false,
},