import { NextRequest, NextResponse } from 'next/server' import { auth } from '@clerk/nextjs/server' import { getStripeClient } from '@/lib/stripe/client' export async function POST() { // Check authentication - only authenticated users can test Stripe const { userId } = await auth() if (!userId) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } 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.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 }) } }