85 lines
2.8 KiB
JavaScript
85 lines
2.8 KiB
JavaScript
import { NextResponse } from "next/server";
|
|
import Stripe from "stripe";
|
|
// import { createClient } from "@supabase/supabase-js";
|
|
|
|
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
|
|
// const supabase = createClient(process.env.SUPABASE_SERVICE_ROLE_KEY);
|
|
|
|
export async function POST(request) {
|
|
try {
|
|
// const { clientId, customerId } = await request.json();
|
|
|
|
// const { data: userData, error: userError } = await supabase
|
|
// .from("subscription_data")
|
|
// .select("*")
|
|
// .eq("customer_id", customerId)
|
|
// .maybeSingle();
|
|
|
|
// if (userError || !userData) {
|
|
// return NextResponse.json(
|
|
// { error: "subscription_data not found" },
|
|
// { 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 });
|
|
}
|
|
}
|