import { NextResponse } from "next/server" import { getStripeClient, STRIPE_API_VERSION } from "@/lib/stripe/client" import { requireAdminToken } from "@/lib/server/admin-auth" export async function POST(request: Request) { const authError = requireAdminToken(request) if (authError) { return authError } try { const stripe = getStripeClient() // Test basic Stripe connectivity const account = await stripe.accounts.retrieve() // Get products and prices const products = await stripe.products.list({ active: true, expand: ["data.default_price"], limit: 50, }) // Get payment methods available const paymentMethods = await stripe.paymentMethods.list({ type: "card", }) // Get upcoming invoices (to test webhook functionality) const invoices = await stripe.invoices.list({ limit: 5, }) return NextResponse.json({ success: true, timestamp: new Date().toISOString(), account: { id: account.id, name: account.business_profile?.name || "N/A", email: account.email, country: account.country, charges_enabled: account.charges_enabled, payouts_enabled: account.payouts_enabled, }, products: { total: products.data.length, active: products.data.filter((p) => p.active).length, sample: products.data.slice(0, 3).map((p) => ({ id: p.id, name: p.name, description: p.description, price: p.default_price ? { id: (p.default_price as any).id, unit_amount: (p.default_price as any).unit_amount, currency: (p.default_price as any).currency, } : null, })), }, paymentMethods: { total: paymentMethods.data.length, types: [...new Set(paymentMethods.data.map((pm) => pm.type))], }, recentInvoices: invoices.data.length, environment: process.env.NODE_ENV, apiVersion: STRIPE_API_VERSION, }) } catch (error) { console.error("Stripe test error:", error) return NextResponse.json( { success: false, error: error instanceof Error ? error.message : "Unknown error", timestamp: new Date().toISOString(), }, { status: 500 } ) } }