Skip to content

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

feat: add referral integration

Marc Seitz3b07cd1fa814
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index 15423544..1c76e8e5 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -235,6 +235,9 @@ export function UpgradePlanModal({
loading={clicked}
onClick={() => {
setClicked(true);
+ // @ts-ignore
+ // prettier-ignore
+ const tolt_referral_id: string | undefined = window.tolt_referral;
fetch(
`/api/teams/${
teamInfo?.currentTeam?.id
@@ -247,6 +250,10 @@ export function UpgradePlanModal({
}`,
{
method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ body: JSON.stringify({ referral: tolt_referral_id }),
},
)
.then(async (res) => {
diff --git a/lib/types.ts b/lib/types.ts
index 4fa6194c..e7e1ff0d 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -213,6 +213,7 @@ export type AnalyticsEvents =
event: "Stripe Checkout Clicked";
teamId: string;
priceId: string;
+ referral: boolean | undefined;
};
export interface Team {
diff --git a/pages/_document.tsx b/pages/_document.tsx
index 47faab55..c2b08770 100644
--- a/pages/_document.tsx
+++ b/pages/_document.tsx
@@ -3,7 +3,15 @@ import { Head, Html, Main, NextScript } from "next/document";
export default function Document() {
return (
<Html lang="en" className="h-full bg-background" suppressHydrationWarning>
- <Head />
+ <Head>
+ {process.env.NEXT_PUBLIC_TOLT_REFERRAL_ID && (
+ <script
+ async
+ src="https://cdn.tolt.io/tolt.js"
+ data-tolt={process.env.NEXT_PUBLIC_TOLT_REFERRAL_ID}
+ />
+ )}
+ </Head>
<body className="h-full">
<Main />
<NextScript />
diff --git a/pages/api/teams/[teamId]/billing/upgrade.ts b/pages/api/teams/[teamId]/billing/upgrade.ts
index cbdcd4f3..6eafc57a 100644
--- a/pages/api/teams/[teamId]/billing/upgrade.ts
+++ b/pages/api/teams/[teamId]/billing/upgrade.ts
@@ -83,6 +83,11 @@ export default async function handle(
mode: "subscription",
allow_promotion_codes: true,
client_reference_id: teamId,
+ ...(req.body.referral && {
+ metadata: {
+ tolt_referral: req.body.referral,
+ },
+ }),
});
}
@@ -91,6 +96,7 @@ export default async function handle(
event: "Stripe Checkout Clicked",
teamId,
priceId: priceId,
+ referral: req.body.referral ? true : undefined,
});
return res.status(200).json(stripeSession);