@@ -1,6 +1,4 @@
|
||||
import Stripe from "stripe";
|
||||
import verifySubscription from "./stripe/verifySubscription";
|
||||
import { prisma } from "./db";
|
||||
|
||||
export default async function paymentCheckout(
|
||||
stripeSecretKey: string,
|
||||
@@ -11,23 +9,6 @@ export default async function paymentCheckout(
|
||||
apiVersion: "2022-11-15",
|
||||
});
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
email: email.toLowerCase(),
|
||||
},
|
||||
include: {
|
||||
subscriptions: true,
|
||||
parentSubscription: true,
|
||||
},
|
||||
});
|
||||
|
||||
const subscription = await verifySubscription(user);
|
||||
|
||||
if (subscription) {
|
||||
// To prevent users from creating multiple subscriptions
|
||||
return { response: "/dashboard", status: 200 };
|
||||
}
|
||||
|
||||
const listByEmail = await stripe.customers.list({
|
||||
email: email.toLowerCase(),
|
||||
expand: ["data.subscriptions"],
|
||||
@@ -37,7 +18,6 @@ export default async function paymentCheckout(
|
||||
|
||||
const NEXT_PUBLIC_TRIAL_PERIOD_DAYS =
|
||||
process.env.NEXT_PUBLIC_TRIAL_PERIOD_DAYS;
|
||||
|
||||
const session = await stripe.checkout.sessions.create({
|
||||
customer: isExistingCustomer ? isExistingCustomer : undefined,
|
||||
line_items: [
|
||||
@@ -48,7 +28,7 @@ export default async function paymentCheckout(
|
||||
],
|
||||
mode: "subscription",
|
||||
customer_email: isExistingCustomer ? undefined : email.toLowerCase(),
|
||||
success_url: `${process.env.BASE_URL}/dashboard`,
|
||||
success_url: `${process.env.BASE_URL}?session_id={CHECKOUT_SESSION_ID}`,
|
||||
cancel_url: `${process.env.BASE_URL}/login`,
|
||||
automatic_tax: {
|
||||
enabled: true,
|
||||
|
||||
Reference in New Issue
Block a user