feat: stripe integration

This commit is contained in:
Vasily Zubarev
2025-04-24 15:27:44 +02:00
parent 38a5c0f814
commit abd5ad8403
31 changed files with 559 additions and 112 deletions

View File

@@ -0,0 +1,30 @@
import { getCurrentUser } from "@/lib/auth"
import { stripeClient } from "@/lib/stripe"
import { NextRequest, NextResponse } from "next/server"
export async function GET(request: NextRequest) {
const user = await getCurrentUser()
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
if (!stripeClient) {
return new NextResponse("Stripe client is not initialized", { status: 500 })
}
try {
if (!user.stripeCustomerId) {
return NextResponse.json({ error: "No Stripe customer ID found for this user" }, { status: 400 })
}
const portalSession = await stripeClient.billingPortal.sessions.create({
customer: user.stripeCustomerId,
return_url: `${request.nextUrl.origin}/settings/profile`,
})
return NextResponse.redirect(portalSession.url)
} catch (error) {
console.error("Stripe portal error:", error)
return NextResponse.json({ error: "Failed to create Stripe portal session" }, { status: 500 })
}
}