remove supabase

This commit is contained in:
Reihan 2025-04-08 14:59:55 +07:00
parent ca5cd7dbd6
commit 7235a16f65

View File

@ -1,83 +1,84 @@
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
import Stripe from "stripe"; import Stripe from "stripe";
import { createClient } from "@supabase/supabase-js"; // import { createClient } from "@supabase/supabase-js";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY); const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
const supabase = createClient(process.env.SUPABASE_SERVICE_ROLE_KEY); // const supabase = createClient(process.env.SUPABASE_SERVICE_ROLE_KEY);
export async function POST(request) { export async function POST(request) {
try { try {
const { clientId, customerId } = await request.json(); // const { clientId, customerId } = await request.json();
const { data: userData, error: userError } = await supabase // const { data: userData, error: userError } = await supabase
.from("subscription_data") // .from("subscription_data")
.select("*") // .select("*")
.eq("customer_id", customerId) // .eq("customer_id", customerId)
.maybeSingle(); // .maybeSingle();
if (userError || !userData) { // if (userError || !userData) {
return NextResponse.json( // return NextResponse.json(
{ error: "subscription_data not found" }, // { error: "subscription_data not found" },
{ status: 404 } // { status: 404 }
); // );
// }
// const { subscription_cost } = userData;
// // Create a new product and price
// const product = await stripe.products.create({
// name: "RankRunners Client Subscription",
// });
// const price = await stripe.prices.create({
// product: product.id,
// unit_amount: subscription_cost * 100,
// currency: "usd",
// recurring: { interval: "month" },
// });
// // Create a Checkout session
// const session = await stripe.checkout.sessions.create({
// customer: customerId,
// payment_method_types: ["card"],
// line_items: [
// {
// price: price.id,
// quantity: 1,
// },
// ],
// mode: "subscription",
// success_url: `${process.env.NEXT_PUBLIC_URL}/client-area?session_id={CHECKOUT_SESSION_ID}`,
// cancel_url: `${process.env.NEXT_PUBLIC_URL}/client-area`,
// });
// if (!session) {
// return NextResponse.json(
// { error: "Failed to create checkout session" },
// { status: 500 }
// );
// }
// // Save the session ID to Supabase
// const { error: updateError } = await supabase
// .from("subscription_data")
// .update({ stripe_session_id: session.id })
// .eq("customer_id", customerId);
// if (updateError) {
// console.error("Error updating stripe_session_id:", updateError);
// return NextResponse.json(
// {
// error:
// "Failed to update subscription data when creating checkout session",
// },
// { status: 500 }
// );
// }
// return NextResponse.json({ url: session.url });
return NextResponse.json({ url: "https://example.com" });
} catch (error) {
console.error("Error creating checkout session:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
} }
const { subscription_cost } = userData;
// Create a new product and price
const product = await stripe.products.create({
name: "RankRunners Client Subscription",
});
const price = await stripe.prices.create({
product: product.id,
unit_amount: subscription_cost * 100,
currency: "usd",
recurring: { interval: "month" },
});
// Create a Checkout session
const session = await stripe.checkout.sessions.create({
customer: customerId,
payment_method_types: ["card"],
line_items: [
{
price: price.id,
quantity: 1,
},
],
mode: "subscription",
success_url: `${process.env.NEXT_PUBLIC_URL}/client-area?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.NEXT_PUBLIC_URL}/client-area`,
});
if (!session) {
return NextResponse.json(
{ error: "Failed to create checkout session" },
{ status: 500 }
);
}
// Save the session ID to Supabase
const { error: updateError } = await supabase
.from("subscription_data")
.update({ stripe_session_id: session.id })
.eq("customer_id", customerId);
if (updateError) {
console.error("Error updating stripe_session_id:", updateError);
return NextResponse.json(
{
error:
"Failed to update subscription data when creating checkout session",
},
{ status: 500 }
);
}
return NextResponse.json({ url: session.url });
} catch (error) {
console.error("Error creating checkout session:", error);
return NextResponse.json({ error: error.message }, { status: 500 });
}
} }