mirror of
https://github.com/linkwarden/linkwarden.git
synced 2026-03-03 03:47:02 +00:00
bug fixed
This commit is contained in:
@@ -5,6 +5,7 @@ import stripeSDK from "./stripe/stripeSDK";
|
||||
const REQUIRE_CC = process.env.NEXT_PUBLIC_REQUIRE_CC === "true";
|
||||
const MANAGED_PAYMENTS_ENABLED =
|
||||
process.env.MANAGED_PAYMENTS_ENABLED === "true";
|
||||
const TRIAL_PERIOD_DAYS = process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS || 14;
|
||||
|
||||
export default async function paymentCheckout(email: string, priceId: string) {
|
||||
const stripe = stripeSDK();
|
||||
@@ -19,9 +20,22 @@ export default async function paymentCheckout(email: string, priceId: string) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return { response: "User not found", status: 404 };
|
||||
}
|
||||
|
||||
const trialEndTime =
|
||||
new Date(user.createdAt).getTime() +
|
||||
(1 + Number(TRIAL_PERIOD_DAYS)) * 86400000; // Add 1 to account for the current day
|
||||
|
||||
const daysLeft = Math.floor((trialEndTime - Date.now()) / 86400000);
|
||||
|
||||
const subscription = await verifySubscription(user);
|
||||
|
||||
if (subscription) {
|
||||
if (
|
||||
subscription?.subscriptions?.active ||
|
||||
subscription?.parentSubscription?.active
|
||||
) {
|
||||
// To prevent users from creating multiple subscriptions
|
||||
return { response: "/dashboard", status: 200 };
|
||||
}
|
||||
@@ -56,7 +70,13 @@ export default async function paymentCheckout(email: string, priceId: string) {
|
||||
: 14,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
: daysLeft > 0
|
||||
? {
|
||||
subscription_data: {
|
||||
trial_period_days: daysLeft,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...(MANAGED_PAYMENTS_ENABLED
|
||||
? {
|
||||
managed_payments: {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Trans, useTranslation } from "next-i18next";
|
||||
import { useUser } from "@linkwarden/router/user";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import Link from "next/link";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const TRIAL_PERIOD_DAYS =
|
||||
Number(process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS) || 14;
|
||||
@@ -149,31 +150,40 @@ export default function Subscribe() {
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
type="button"
|
||||
variant="accent"
|
||||
size="full"
|
||||
onClick={submit}
|
||||
disabled={submitLoader}
|
||||
<div
|
||||
className={cn(
|
||||
"flex gap-3",
|
||||
REQUIRE_CC || daysLeft <= 0 ? "flex-col" : "flex-row-reverse"
|
||||
)}
|
||||
>
|
||||
{t("complete_subscription")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="accent"
|
||||
size="full"
|
||||
onClick={submit}
|
||||
disabled={submitLoader}
|
||||
>
|
||||
{t("complete_subscription")}
|
||||
</Button>
|
||||
|
||||
{REQUIRE_CC ? (
|
||||
<div
|
||||
onClick={() => signOut()}
|
||||
className="w-fit mx-auto cursor-pointer text-neutral font-semibold "
|
||||
>
|
||||
{t("sign_out")}
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
className="w-fit mx-auto cursor-pointer text-neutral font-semibold "
|
||||
href="/dashboard"
|
||||
>
|
||||
{t("subscribe_later")}
|
||||
</Link>
|
||||
)}
|
||||
{REQUIRE_CC || daysLeft <= 0 ? (
|
||||
<div
|
||||
onClick={() => signOut()}
|
||||
className="w-fit mx-auto cursor-pointer text-neutral font-semibold "
|
||||
>
|
||||
{t("sign_out")}
|
||||
</div>
|
||||
) : (
|
||||
<Button
|
||||
className=""
|
||||
variant="metal"
|
||||
size="full"
|
||||
onClick={() => router.push("/dashboard")}
|
||||
>
|
||||
{t("subscribe_later")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CenteredForm>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user