Compare commits

...

5 Commits

Author SHA1 Message Date
daniel31x13 94b261fa32 minor change 2024-03-17 17:56:36 -04:00
daniel31x13 c684b54aef bug fix 2024-03-17 17:39:52 -04:00
daniel31x13 ffc037b854 bug fixed 2024-03-16 20:09:58 -04:00
daniel31x13 5990d4ce2d support for arbitrary values in manual installation 2024-03-13 09:56:13 -04:00
daniel31x13 bae4cf1d4f support for other ports in manual installation 2024-03-13 09:48:16 -04:00
6 changed files with 52 additions and 40 deletions
+7 -6
View File
@@ -32,11 +32,12 @@ export default async function checkSubscriptionByEmail(email: string) {
customer.subscriptions?.data.some((subscription) => {
subscription.current_period_end;
active = subscription.items.data.some(
(e) =>
(e.price.id === MONTHLY_PRICE_ID && e.price.active === true) ||
(e.price.id === YEARLY_PRICE_ID && e.price.active === true)
);
active =
subscription.items.data.some(
(e) =>
(e.price.id === MONTHLY_PRICE_ID && e.price.active === true) ||
(e.price.id === YEARLY_PRICE_ID && e.price.active === true)
) || false;
stripeSubscriptionId = subscription.id;
currentPeriodStart = subscription.current_period_start * 1000;
currentPeriodEnd = subscription.current_period_end * 1000;
@@ -44,7 +45,7 @@ export default async function checkSubscriptionByEmail(email: string) {
});
return {
active,
active: active || false,
stripeSubscriptionId,
currentPeriodStart,
currentPeriodEnd,
+7 -4
View File
@@ -16,8 +16,11 @@ export default async function paymentCheckout(
const isExistingCustomer = listByEmail?.data[0]?.id || undefined;
console.log("isExistingCustomer", listByEmail?.data[0]);
const NEXT_PUBLIC_TRIAL_PERIOD_DAYS =
process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS;
Number(process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS) || 14;
const session = await stripe.checkout.sessions.create({
customer: isExistingCustomer ? isExistingCustomer : undefined,
line_items: [
@@ -34,9 +37,9 @@ export default async function paymentCheckout(
enabled: true,
},
subscription_data: {
trial_period_days: NEXT_PUBLIC_TRIAL_PERIOD_DAYS
? Number(NEXT_PUBLIC_TRIAL_PERIOD_DAYS)
: 14,
trial_period_days: isExistingCustomer
? undefined
: NEXT_PUBLIC_TRIAL_PERIOD_DAYS,
},
});
+15 -17
View File
@@ -17,15 +17,7 @@ export default async function verifySubscription(
const currentDate = new Date();
if (
subscription &&
currentDate > subscription.currentPeriodEnd &&
!subscription.active
) {
return null;
}
if (!subscription || currentDate > subscription.currentPeriodEnd) {
if (!subscription?.active || currentDate > subscription.currentPeriodEnd) {
const {
active,
stripeSubscriptionId,
@@ -59,15 +51,21 @@ export default async function verifySubscription(
},
})
.catch((err) => console.log(err));
}
} else if (!active) {
const subscription = await prisma.subscription.findFirst({
where: {
userId: user.id,
},
});
if (!active) {
if (user.username)
// await prisma.user.update({
// where: { id: user.id },
// data: { username: null },
// });
return null;
if (subscription)
await prisma.subscription.delete({
where: {
userId: user.id,
},
});
return null;
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ export default async function verifyUser({
}
if (STRIPE_SECRET_KEY) {
const subscribedUser = verifySubscription(user);
const subscribedUser = await verifySubscription(user);
if (!subscribedUser) {
res.status(401).json({
+2 -2
View File
@@ -10,10 +10,10 @@
"seed": "node ./prisma/seed.js"
},
"scripts": {
"dev": "concurrently -k \"next dev\" \"yarn worker:dev\"",
"dev": "concurrently -k -P \"next dev {@}\" \"yarn worker:dev\" --",
"worker:dev": "nodemon --skip-project scripts/worker.ts",
"worker:prod": "ts-node --transpile-only --skip-project scripts/worker.ts",
"start": "concurrently \"next start\" \"yarn worker:prod\"",
"start": "concurrently -k -P \"next start {@}\" \"yarn worker:prod\" --",
"build": "next build",
"lint": "next lint",
"format": "prettier --write \"**/*.{ts,tsx,js,json,md}\""
+20 -10
View File
@@ -5,6 +5,7 @@ import { useRouter } from "next/router";
import CenteredForm from "@/layouts/CenteredForm";
import { Plan } from "@/types/global";
import AccentSubmitButton from "@/components/AccentSubmitButton";
import useAccountStore from "@/store/account";
export default function Subscribe() {
const [submitLoader, setSubmitLoader] = useState(false);
@@ -12,6 +13,8 @@ export default function Subscribe() {
const [plan, setPlan] = useState<Plan>(1);
const { account } = useAccountStore();
const router = useRouter();
async function submit() {
@@ -27,9 +30,13 @@ export default function Subscribe() {
return (
<CenteredForm
text={`Start with a ${
process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14
}-day free trial, cancel anytime!`}
text={
account.username
? ""
: `Start with a ${
process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14
}-day free trial, cancel anytime!`
}
>
<div className="p-4 mx-auto flex flex-col gap-3 justify-between max-w-[30rem] min-w-80 w-full bg-base-200 rounded-2xl shadow-md border border-neutral-content">
<p className="sm:text-3xl text-2xl text-center font-extralight">
@@ -37,7 +44,6 @@ export default function Subscribe() {
</p>
<div className="divider my-0"></div>
<div>
<p>
You will be redirected to Stripe, feel free to reach out to us at{" "}
@@ -47,7 +53,6 @@ export default function Subscribe() {
in case of any issue.
</p>
</div>
<div className="flex gap-3 border border-solid border-neutral-content w-4/5 mx-auto p-1 rounded-xl relative">
<button
onClick={() => setPlan(Plan.monthly)}
@@ -74,7 +79,6 @@ export default function Subscribe() {
25% Off
</div>
</div>
<div className="flex flex-col gap-2 justify-center items-center">
<p className="text-3xl">
${plan === Plan.monthly ? "4" : "3"}
@@ -89,13 +93,20 @@ export default function Subscribe() {
</legend>
<p className="text-sm">
{process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS}-day free trial, then $
{plan === Plan.monthly ? "4 per month" : "36 annually"}
{account.username
? ""
: `${process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS}-day free trial, then `}
${plan === Plan.monthly ? "4 per month" : "36 annually"}
</p>
<p className="text-sm">+ VAT if applicable</p>
</fieldset>
</div>
<p className="text-sm mb-5">
{account.username
? "Please note that since your trial has been previously ended, your subscription will start immediately. You can cancel anytime."
: ""}
</p>
</div>
<AccentSubmitButton
type="button"
label="Complete Subscription!"
@@ -103,7 +114,6 @@ export default function Subscribe() {
onClick={submit}
loading={submitLoader}
/>
<div
onClick={() => signOut()}
className="w-fit mx-auto cursor-pointer text-neutral font-semibold "