From ed3e4d22ef472a552780bbe58da65206eaa02789 Mon Sep 17 00:00:00 2001 From: Mythie Date: Fri, 5 May 2023 19:29:42 +1000 Subject: [PATCH 01/42] feat: scaffhold subscription table and ui --- .env.example | 6 + .vscode/settings.json | 2 +- apps/web/components/settings.tsx | 34 +- apps/web/next.config.js | 10 +- apps/web/package.json | 7 +- apps/web/pages/settings/billing.tsx | 1 + apps/web/process-env.d.ts | 24 + apps/web/tsconfig.json | 2 +- package-lock.json | 1808 ++++++++++++++++- packages/lib/package.json | 5 +- packages/lib/process-env.d.ts | 24 + packages/lib/stripe/data/plans.ts | 12 + .../lib/stripe/handlers/portal-session.ts | 1 + packages/lib/stripe/handlers/webhook.ts | 155 ++ packages/lib/stripe/index.ts | 6 + .../migration.sql | 26 + .../migration.sql | 11 + .../migration.sql | 2 + packages/prisma/schema.prisma | 24 + 19 files changed, 2128 insertions(+), 32 deletions(-) create mode 100644 apps/web/pages/settings/billing.tsx create mode 100644 apps/web/process-env.d.ts create mode 100644 packages/lib/process-env.d.ts create mode 100644 packages/lib/stripe/data/plans.ts create mode 100644 packages/lib/stripe/handlers/portal-session.ts create mode 100644 packages/lib/stripe/handlers/webhook.ts create mode 100644 packages/lib/stripe/index.ts create mode 100644 packages/prisma/migrations/20230505085625_create_subscription_table/migration.sql create mode 100644 packages/prisma/migrations/20230505085908_update_unique_constraint/migration.sql create mode 100644 packages/prisma/migrations/20230505091928_add_past_due_value/migration.sql diff --git a/.env.example b/.env.example index 7da56a2e3..12a455ed6 100644 --- a/.env.example +++ b/.env.example @@ -37,6 +37,12 @@ SMTP_MAIL_PASSWORD='' # Sender for signing requests and completion mails. MAIL_FROM='documenso@localhost.com' +# STRIPE +STRIPE_API_KEY= +STRIPE_WEBHOOK_SECRET= +STRIPE_PRICE_ID= + #FEATURE FLAGS # Allow users to register via the /signup page. Otherwise they will be redirect to the home page. ALLOW_SIGNUP=true +ALLOW_SUBSCRIPTIONS=true \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 17ceca23e..41c0f1a88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,7 @@ "editor.codeActionsOnSave": { "source.removeUnusedImports": false }, - "typescript.tsdk": "node_modules\\typescript\\lib", + "typescript.tsdk": "node_modules/typescript/lib", "spellright.language": ["de"], "spellright.documentTypes": ["markdown", "latex", "plaintext"] } diff --git a/apps/web/components/settings.tsx b/apps/web/components/settings.tsx index 32d868804..5556d3198 100644 --- a/apps/web/components/settings.tsx +++ b/apps/web/components/settings.tsx @@ -5,7 +5,7 @@ import { useRouter } from "next/router"; import { updateUser } from "@documenso/features"; import { getUser } from "@documenso/lib/api"; import { Button } from "@documenso/ui"; -import { KeyIcon, UserCircleIcon } from "@heroicons/react/24/outline"; +import { CreditCardIcon, KeyIcon, UserCircleIcon } from "@heroicons/react/24/outline"; import { useSession } from "next-auth/react"; const subNavigation = [ @@ -21,6 +21,12 @@ const subNavigation = [ icon: KeyIcon, current: false, }, + { + name: "Billing", + href: "/settings/billing", + icon: CreditCardIcon, + current: false, + }, ]; function classNames(...classes: any) { @@ -33,7 +39,6 @@ export default function Setttings() { email: "", name: "", }); - useEffect(() => { getUser().then((res: any) => { res.json().then((j: any) => { @@ -158,6 +163,7 @@ export default function Setttings() { + + + + From bde80bf2c9879add6992af5ebc96afb80f37e0fa Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Sun, 21 May 2023 18:52:35 +0200 Subject: [PATCH 12/42] clean up debug --- packages/lib/constants.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/lib/constants.ts b/packages/lib/constants.ts index d43db0f2c..9d27dd873 100644 --- a/packages/lib/constants.ts +++ b/packages/lib/constants.ts @@ -1,8 +1,4 @@ export const NEXT_PUBLIC_WEBAPP_URL = process.env.IS_PULL_REQUEST === "true" ? process.env.RENDER_EXTERNAL_URL - : process.env.NEXT_PUBLIC_WEBAPP_URL; - -console.log("IS_PULL_REQUEST:" + process.env.IS_PULL_REQUEST); -console.log("RENDER_EXTERNAL_URL:" + process.env.RENDER_EXTERNAL_URL); -console.log("NEXT_PUBLIC_WEBAPP_URL:" + process.env.NEXT_PUBLIC_WEBAPP_URL); + : process.env.NEXT_PUBLIC_WEBAPP_URL; \ No newline at end of file From 73b72c6cce88d7353392ee1b38850f2273d2f165 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Sun, 21 May 2023 20:10:06 +0200 Subject: [PATCH 13/42] fix NEXT_PUBLIC_ALLOW_SIGNUP reference --- apps/web/pages/signup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/pages/signup.tsx b/apps/web/pages/signup.tsx index 689444de9..2f020fa6e 100644 --- a/apps/web/pages/signup.tsx +++ b/apps/web/pages/signup.tsx @@ -15,7 +15,7 @@ export default function SignupPage(props: { source: string }) { } export async function getServerSideProps(context: any) { - if (process.env.ALLOW_SIGNUP !== "true") + if (process.env.NEXT_PUBLIC_ALLOW_SIGNUP !== "true") return { redirect: { destination: "/login", From ed7700074675b2ef34acb97f23e934d2f171d375 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Sun, 21 May 2023 20:28:06 +0200 Subject: [PATCH 14/42] fix: pass recipient token to signed page --- apps/web/pages/documents/[id]/sign.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/pages/documents/[id]/sign.tsx b/apps/web/pages/documents/[id]/sign.tsx index 252d0f429..b04352f9e 100644 --- a/apps/web/pages/documents/[id]/sign.tsx +++ b/apps/web/pages/documents/[id]/sign.tsx @@ -73,7 +73,7 @@ export async function getServerSideProps(context: any) { return { redirect: { permanent: false, - destination: `/documents/${recipient.Document.id}/signed`, + destination: `/documents/${recipient.Document.id}/signed?token=recipientToken`, }, }; } From 38a8279757261bc9e420832eefd23d6104ebd9cf Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Sun, 21 May 2023 20:36:38 +0200 Subject: [PATCH 15/42] fix --- apps/web/pages/documents/[id]/sign.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/pages/documents/[id]/sign.tsx b/apps/web/pages/documents/[id]/sign.tsx index b04352f9e..c2fbb1230 100644 --- a/apps/web/pages/documents/[id]/sign.tsx +++ b/apps/web/pages/documents/[id]/sign.tsx @@ -73,7 +73,7 @@ export async function getServerSideProps(context: any) { return { redirect: { permanent: false, - destination: `/documents/${recipient.Document.id}/signed?token=recipientToken`, + destination: `/documents/${recipient.Document.id}/signed?token=${recipientToken}`, }, }; } From 106ac40fb13ca00c1c7ecbfd7d81b549ef46c952 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Sun, 21 May 2023 21:01:34 +0200 Subject: [PATCH 16/42] texts, monthly billing default --- apps/web/components/billing-plans.tsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/web/components/billing-plans.tsx b/apps/web/components/billing-plans.tsx index 43740276d..419478cfd 100644 --- a/apps/web/components/billing-plans.tsx +++ b/apps/web/components/billing-plans.tsx @@ -6,7 +6,7 @@ import { Switch } from "@headlessui/react"; export const BillingPlans = () => { const { subscription, isLoading } = useSubscription(); - const [isAnnual, setIsAnnual] = useState(true); + const [isAnnual, setIsAnnual] = useState(false); return (
@@ -45,10 +45,8 @@ export const BillingPlans = () => {

- Lorem ipsum dolor sit amet consectetur, adipisicing elit. Corrupti voluptates delectus - doloremque hic vel! + All you need for easy signing.

Includes everthing we build this year.

-