Skip to content

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

feat: upgrade stripe and pricing

Marc Seitzd4fa9bfe54a6
diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx
index b507c560..58df4c02 100644
--- a/components/Sidebar.tsx
+++ b/components/Sidebar.tsx
@@ -25,6 +25,7 @@ import {
import SiderbarFolders from "./sidebar-folders";
import { AddFolderModal } from "./folders/add-folder-modal";
import { ScrollArea } from "./ui/scroll-area";
+import { UpgradePlanModal } from "./billing/upgrade-plan-modal";
export default function Sidebar() {
return (
@@ -208,6 +209,23 @@ export const SidebarComponent = ({ className }: { className?: string }) => {
</div>
);
}
+ if (userPlan !== "business" && item.name === "Datarooms") {
+ return (
+ <UpgradePlanModal
+ key={item.name}
+ clickedPlan={"Business"}
+ trigger={"datarooms"}
+ >
+ <div className="group flex gap-x-2 items-center rounded-md px-3 py-2 text-sm leading-6 w-full hover:bg-transparent text-muted-foreground">
+ <item.icon
+ className="h-5 w-5 shrink-0"
+ aria-hidden="true"
+ />
+ {item.name}
+ </div>
+ </UpgradePlanModal>
+ );
+ }
return (
<button
key={item.name}
diff --git a/components/billing/upgrade-plan-modal.tsx b/components/billing/upgrade-plan-modal.tsx
index bb2c354a..e931f56b 100644
--- a/components/billing/upgrade-plan-modal.tsx
+++ b/components/billing/upgrade-plan-modal.tsx
@@ -54,8 +54,7 @@ export function UpgradePlanModal({
"Custom domains",
"Custom branding",
"Notion documents",
- "Data room (coming soon)",
- "Shareable folders (coming soon)",
+ "Data room",
"AI Document Assistant incl. 2500 credits",
"Priority Support",
];
diff --git a/lib/stripe/index.ts b/lib/stripe/index.ts
index 7126078e..b926fb66 100644
--- a/lib/stripe/index.ts
+++ b/lib/stripe/index.ts
@@ -3,7 +3,7 @@ import Stripe from "stripe";
export const stripe = new Stripe(
process.env.STRIPE_SECRET_KEY_LIVE ?? process.env.STRIPE_SECRET_KEY ?? "",
{
- apiVersion: "2023-08-16",
+ apiVersion: "2023-10-16",
appInfo: {
name: "Papermark.io",
version: "0.1.0",
diff --git a/lib/stripe/utils.ts b/lib/stripe/utils.ts
index 6e206f86..025f7d36 100644
--- a/lib/stripe/utils.ts
+++ b/lib/stripe/utils.ts
@@ -1,3 +1,5 @@
+import Stripe from "stripe";
+
export function getPlanFromPriceId(priceId: string) {
const env =
process.env.NEXT_PUBLIC_VERCEL_ENV === "production" ? "production" : "test";
@@ -10,18 +12,7 @@ export function getPlanFromPriceId(priceId: string) {
// custom type coercion because Stripe's types are wrong
export function isNewCustomer(
- previousAttributes: // Stripe.Event.Data.PreviousAttributes | undefined
- | {
- default_payment_method?: string;
- items?: {
- data?: {
- price?: {
- id?: string;
- }[];
- };
- };
- }
- | undefined,
+ previousAttributes: Partial<Stripe.Subscription> | undefined,
) {
let isNewCustomer = false;
try {
@@ -37,25 +28,40 @@ export function isNewCustomer(
return isNewCustomer;
}
+export function isUpgradedCustomer(
+ previousAttributes: Partial<Stripe.Subscription> | undefined,
+) {
+ let isUpgradedUser = false;
+ try {
+ if (
+ // if user has items in their subscription
+ previousAttributes?.items !== undefined
+ ) {
+ isUpgradedUser = true;
+ }
+ } catch (error) {
+ console.error("An error occurred:", error);
+ }
+ return isUpgradedUser;
+}
+
export const PLANS = [
{
name: "Pro",
slug: "pro",
price: {
monthly: {
- amount: 29,
+ amount: 39,
priceIds: {
- test: "price_1NmHGzFJyGSZ96lhp946ODFI",
- production: "price_1Op0Q3FJyGSZ96lhtEUxLSGs", // new price
- // production: "price_1NmMZ7FJyGSZ96lhyad2LW90", // old price
+ test: "price_1P3JdWFJyGSZ96lhLqX6drHK",
+ production: "price_1P3FK4FJyGSZ96lhD67yF3lj",
},
},
yearly: {
- amount: 290,
+ amount: 390,
priceIds: {
- test: "price_1NmHHaFJyGSZ96lhXxg2fTr7",
- production: "price_1Op0fFFJyGSZ96lhPVrvzz5a", // new price
- // production: "price_1NmMZ7FJyGSZ96lhqZEkh50e", // old price
+ test: "price_1P3JlWFJyGSZ96lhddEsPKGg",
+ production: "price_1P3FQPFJyGSZ96lhXPwLPl49",
},
},
},
diff --git a/package-lock.json b/package-lock.json
index 3eed5559..3626cc4e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -39,7 +39,7 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@react-email/components": "^0.0.15",
"@sindresorhus/slugify": "^2.2.1",
- "@stripe/stripe-js": "^2.1.7",
+ "@stripe/stripe-js": "^3.2.0",
"@tailwindcss/typography": "^0.5.10",
"@teamhanko/passkeys-next-auth-provider": "^0.2.7",
"@tremor/react": "^3.14.1",
@@ -97,7 +97,7 @@
"remark-toc": "^9.0.0",
"resend": "^3.2.0",
"sonner": "^1.4.3",
- "stripe": "^13.9.0",
+ "stripe": "^14.24.0",
"swr": "^2.2.5",
"tailwind-merge": "^2.2.1",
"tailwindcss": "^3.4.1",
@@ -4432,9 +4432,12 @@
"integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg=="
},
"node_modules/@stripe/stripe-js": {
- "version": "2.1.7",
- "resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-2.1.7.tgz",
- "integrity": "sha512-oI620ARpFp5jCXfwIYMxyBJmtTFuAjSA8x3k3JgW1M6cvLmw9XgmNcGNegQWmirpozhFNflxrZEgp10og+6MSA=="
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/@stripe/stripe-js/-/stripe-js-3.2.0.tgz",
+ "integrity": "sha512-dNu+FLX0UrxM0RVgr4YVc5dJdmC6Wx5Grgi53E28K+n+/aIqVrWkonKtAEPcdkabQz6i/1IpNd93s+UUVSOkcg==",
+ "engines": {
+ "node": ">=12.16"
+ }
},
"node_modules/@swc/core": {
"version": "1.3.101",
@@ -16727,9 +16730,9 @@
}
},
"node_modules/stripe": {
- "version": "13.9.0",
- "resolved": "https://registry.npmjs.org/stripe/-/stripe-13.9.0.tgz",
- "integrity": "sha512-sQAqodCvaw/iYWauHHdOWlFGj0oZj/3A51zs4rG5PN3SUJUFSSjtnbc9q5Djpls0iz3nXz2UwjzAdKHVP4dVqQ==",
+ "version": "14.24.0",
+ "resolved": "https://registry.npmjs.org/stripe/-/stripe-14.24.0.tgz",
+ "integrity": "sha512-r0JWz2quThXsFbp1pevkAAoDk4sw3kFMQEc2qvxMFUOhw/SFGqtAGz4vQgP/fMWzO28ljBNEiz68KqRx0JS3dw==",
"dependencies": {
"@types/node": ">=8.1.0",
"qs": "^6.11.0"
diff --git a/package.json b/package.json
index dcc533e2..c5c1f860 100644
--- a/package.json
+++ b/package.json
@@ -47,7 +47,7 @@
"@radix-ui/react-tooltip": "^1.0.7",
"@react-email/components": "^0.0.15",
"@sindresorhus/slugify": "^2.2.1",
- "@stripe/stripe-js": "^2.1.7",
+ "@stripe/stripe-js": "^3.2.0",
"@tailwindcss/typography": "^0.5.10",
"@teamhanko/passkeys-next-auth-provider": "^0.2.7",
"@tremor/react": "^3.14.1",
@@ -105,7 +105,7 @@
"remark-toc": "^9.0.0",
"resend": "^3.2.0",
"sonner": "^1.4.3",
- "stripe": "^13.9.0",
+ "stripe": "^14.24.0",
"swr": "^2.2.5",
"tailwind-merge": "^2.2.1",
"tailwindcss": "^3.4.1",
diff --git a/pages/api/stripe/webhook.ts b/pages/api/stripe/webhook.ts
index fa5297a7..583923ec 100644
--- a/pages/api/stripe/webhook.ts
+++ b/pages/api/stripe/webhook.ts
@@ -3,7 +3,11 @@ import { Readable } from "node:stream";
import type Stripe from "stripe";
import prisma from "@/lib/prisma";
import { stripe } from "@/lib/stripe";
-import { getPlanFromPriceId, isNewCustomer } from "@/lib/stripe/utils";
+import {
+ getPlanFromPriceId,
+ isNewCustomer,
+ isUpgradedCustomer,
+} from "@/lib/stripe/utils";
import { log } from "@/lib/utils";
import { sendUpgradePlanEmail } from "@/lib/emails/send-upgrade-plan";
@@ -126,6 +130,9 @@ export default async function webhookHandler(
const subscriptionUpdated = event.data.object as Stripe.Subscription;
const priceId = subscriptionUpdated.items.data[0].price.id;
const newCustomer = isNewCustomer(event.data.previous_attributes);
+ const upgradedCustomer = isUpgradedCustomer(
+ event.data.previous_attributes,
+ );
const plan = getPlanFromPriceId(priceId);
const stripeId = subscriptionUpdated.customer.toString();
@@ -145,6 +152,27 @@ export default async function webhookHandler(
newCustomer,
});
+ // if user upgrades from Pro to Business, checkout event won't be fired
+ // so we need to update the user immediately
+ if (upgradedCustomer && !newCustomer) {
+ await prisma.team.update({
+ where: {
+ stripeId: stripeId,
+ },
+ data: {
+ plan: plan.slug,
+ subscriptionId,
+ startsAt,
+ endsAt,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ pendingSubscriptionUpdates.delete(stripeId);
+ }
+
// If project cancels their subscription
} else if (event.type === "customer.subscription.deleted") {
const subscriptionDeleted = event.data.object as Stripe.Subscription;
diff --git a/pages/pricing.tsx b/pages/pricing.tsx
index 45619449..a6840173 100644
--- a/pages/pricing.tsx
+++ b/pages/pricing.tsx
@@ -57,7 +57,7 @@ const tiers: {
name: "Pro",
id: "tier-pro",
href: "/login",
- price: { monthly: "€29", annually: "€290" },
+ price: { monthly: "€39", annually: "€390" },
description: "The branded experience for your documents.",
featureIntro: "Everything in Free, plus:",
features: [
@@ -83,11 +83,10 @@ const tiers: {
featureIntro: "Everything in Pro, plus:",
features: [
"10 users",
+ "Data rooms",
"Unlimited documents",
"Unlimited subfolder levels",
"Large file uploads",
- "Data rooms (coming soon)",
- "Shareable folders (coming soon)",
"24h Priority Support",
],
bgColor: "#fb7a00",
diff --git a/pages/settings/billing.tsx b/pages/settings/billing.tsx
index 42e4da62..e85132a7 100644
--- a/pages/settings/billing.tsx
+++ b/pages/settings/billing.tsx
@@ -71,7 +71,7 @@ export default function Billing() {
id: "tier-free",
href: "/login",
currentPlan: plan && plan == "free" ? true : false,
- price: { monthly: "€0", annually: "$0" },
+ price: { monthly: "€0", annually: "€0" },
description: "The essentials to start sharing documents securely.",
featureIntro: "What's included:",
features: [
@@ -94,7 +94,7 @@ export default function Billing() {
id: "tier-pro",
href: "/login",
currentPlan: plan && plan == "pro" ? true : false,
- price: { monthly: "€29", annually: "$290" },
+ price: { monthly: "€39", annually: "€390" },
description: "The branded experience for your documents.",
featureIntro: "Everything in Free, plus:",
features: [
@@ -116,16 +116,15 @@ export default function Billing() {
id: "tier-business",
href: "/login",
currentPlan: plan && plan == "business" ? true : false,
- price: { monthly: "€79", annually: "$790" },
+ price: { monthly: "€79", annually: "€790" },
description: "A plan that scales with your rapidly growing business.",
featureIntro: "Everything in Pro, plus:",
features: [
"10 users",
+ "Data rooms",
"Unlimited documents",
"Unlimited subfolder levels",
"Large file uploads",
- "Shareable folders (coming soon)",
- "Data rooms (coming soon)",
"24h Priority Support",
],
bgColor: "#fb7a00",