"use client" import { useState, useEffect } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card" import { Badge } from "@/components/ui/badge" import { CheckCircle, XCircle, AlertTriangle, RefreshCw, ExternalLink, Package, ShoppingCart, CreditCard, } from "lucide-react" interface StripeStatus { success: boolean account?: { id: string name: string email: string country: string charges_enabled: boolean payouts_enabled: boolean } products?: { total: number active: number sample: Array<{ id: string name: string description?: string price?: { id: string unit_amount: number currency: string } }> } paymentMethods?: { total: number types: string[] } recentInvoices: number environment: string apiVersion: string timestamp: string error?: string } export function StripeStatus() { const [status, setStatus] = useState(null) const [loading, setLoading] = useState(true) const [lastUpdated, setLastUpdated] = useState("") const fetchStatus = async () => { try { const response = await fetch("/api/stripe/test", { method: "POST", cache: "no-store", }) if (response.ok) { const data = await response.json() setStatus(data) setLastUpdated(new Date().toLocaleTimeString()) } else { setStatus({ success: false, error: "Failed to fetch status", timestamp: new Date().toISOString(), recentInvoices: 0, environment: process.env.NODE_ENV || "development", apiVersion: "unknown", }) } } catch (error) { setStatus({ success: false, error: error instanceof Error ? error.message : "Network error", timestamp: new Date().toISOString(), recentInvoices: 0, environment: process.env.NODE_ENV || "development", apiVersion: "unknown", }) } finally { setLoading(false) } } useEffect(() => { fetchStatus() const interval = setInterval(fetchStatus, 30000) // Refresh every 30 seconds return () => clearInterval(interval) }, []) if (loading) { return ( Checking Stripe connection... ) } if (!status) { return (
Unable to connect to Stripe
) } const stripeWorking = status.success return (
{/* Status Overview */}
{stripeWorking ? ( ) : ( )} Stripe {stripeWorking ? "Connected" : "Not Connected"}
Last updated: {lastUpdated}
{stripeWorking ? (

Your Stripe account is connected and ready for products.

) : (

{status.error || "Unable to connect to Stripe. Please check your configuration."}

Setup Required
)}
{/* Account Info */} {stripeWorking && status.account && ( Account Information
Account ID:
{status.account.id}
Business Name:
{status.account.name || "Not set"}
Country:
{status.account.country}
Charges Enabled:
{status.account.charges_enabled ? ( Yes ) : ( No )}
)} {/* Products Status */} Products Status {stripeWorking && status.products ? (
{status.products.total} total products {status.products.active} active
{status.products.sample.length > 0 && (

Recent products:

{status.products.sample.map((product) => (
{product.name}
{product.price && (
${(product.price.unit_amount / 100).toFixed(2)}{" "} {product.price.currency.toUpperCase()}
)}
{product.price ? ( Available ) : ( No Price )}
))}
)} {status.products.total === 0 && (

No products found. Add some products in Stripe Dashboard.

)}
) : !stripeWorking ? (

Connect to Stripe to view product status

) : (

Loading products...

)}
{/* Payment Methods */} {stripeWorking && status.paymentMethods && ( Payment Methods
{status.paymentMethods.total} methods available
{status.paymentMethods.types.map((type) => ( {type} ))}
)} {/* Quick Actions */} {stripeWorking && ( Quick Actions )}
) }