diff --git a/.env.sample b/.env.sample index 4bf7c56..a2cc611 100644 --- a/.env.sample +++ b/.env.sample @@ -22,11 +22,11 @@ EMAIL_SERVER= # Stripe settings (You don't need these, it's for the cloud instance payments) NEXT_PUBLIC_STRIPE_IS_ACTIVE= STRIPE_SECRET_KEY= -PRICE_ID= +MONTHLY_PRICE_ID= +YEARLY_PRICE_ID= NEXT_PUBLIC_TRIAL_PERIOD_DAYS= NEXT_PUBLIC_STRIPE_BILLING_PORTAL_URL= BASE_URL=http://localhost:3000 -NEXT_PUBLIC_PRICING= # Docker postgres settings POSTGRES_PASSWORD= diff --git a/pages/api/payment/index.ts b/pages/api/payment/index.ts index cd37caf..e62ac4a 100644 --- a/pages/api/payment/index.ts +++ b/pages/api/payment/index.ts @@ -2,18 +2,27 @@ import type { NextApiRequest, NextApiResponse } from "next"; import { getServerSession } from "next-auth/next"; import { authOptions } from "@/pages/api/auth/[...nextauth]"; import paymentCheckout from "@/lib/api/paymentCheckout"; +import { Plan } from "@/types/global"; export default async function users(req: NextApiRequest, res: NextApiResponse) { const STRIPE_SECRET_KEY = process.env.STRIPE_SECRET_KEY; - const PRICE_ID = process.env.PRICE_ID; + const MONTHLY_PRICE_ID = process.env.MONTHLY_PRICE_ID; + const YEARLY_PRICE_ID = process.env.YEARLY_PRICE_ID; const session = await getServerSession(req, res, authOptions); if (!session?.user?.id) return res.status(401).json({ response: "You must be logged in." }); - else if (!STRIPE_SECRET_KEY || !PRICE_ID) { + else if (!STRIPE_SECRET_KEY || !MONTHLY_PRICE_ID || !YEARLY_PRICE_ID) { return res.status(400).json({ response: "Payment is disabled." }); } + let PRICE_ID = MONTHLY_PRICE_ID; + + if ((Number(req.query.plan) as unknown as Plan) === Plan.monthly) + PRICE_ID = MONTHLY_PRICE_ID; + else if ((Number(req.query.plan) as unknown as Plan) === Plan.yearly) + PRICE_ID = YEARLY_PRICE_ID; + if (req.method === "GET") { const users = await paymentCheckout( STRIPE_SECRET_KEY, diff --git a/pages/subscribe.tsx b/pages/subscribe.tsx index 5894108..8c58f6c 100644 --- a/pages/subscribe.tsx +++ b/pages/subscribe.tsx @@ -6,10 +6,13 @@ import { toast } from "react-hot-toast"; import { useSession } from "next-auth/react"; import { useRouter } from "next/router"; import CenteredForm from "@/layouts/CenteredForm"; +import { Plan } from "@/types/global"; export default function Subscribe() { const [submitLoader, setSubmitLoader] = useState(false); + const [plan, setPlan] = useState(0); + const { data, status } = useSession(); const router = useRouter(); @@ -18,7 +21,7 @@ export default function Subscribe() { const redirectionToast = toast.loading("Redirecting to Stripe..."); - const res = await fetch("/api/payment"); + const res = await fetch("/api/payment?plan=" + plan); const data = await res.json(); router.push(data.response); @@ -26,11 +29,9 @@ export default function Subscribe() { return (

@@ -38,16 +39,64 @@ export default function Subscribe() {

-

You will be redirected to Stripe.

- Feel free to reach out to us at{" "} + You will be redirected to Stripe, feel free to reach out to us at{" "} support@linkwarden.app {" "} - in case of any issues. + in case of any issue.

+
+ + + +
+ %25 Off +
+
+ +
+

+ ${plan === Plan.monthly ? "4" : "3"} + + /mo + +

+

+ Billed {plan === Plan.monthly ? "Monthly" : "Yearly"} +

+
+

Total:

+
+

+ {process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS}-day free trial, then + ${plan === Plan.monthly ? "4" : "3"} per month +

+

+ VAT if applicable

+
+
+
+ { collections: CollectionIncludingLinks[]; } + +export enum Plan { + monthly, + yearly, +}