Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
import { NextResponse } from 'next/server';
import { createClient } from '@/lib/supabase/server';
import { stripe } from '@/lib/stripe';
export async function GET() {
try {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const { data: profile } = await supabase
.from('profiles')
.select('organization_id')
.eq('id', user.id)
.single();
if (!profile?.organization_id) {
return NextResponse.json({ error: 'No organization' }, { status: 400 });
}
const { data: org } = await supabase
.from('organizations')
.select('stripe_customer_id')
.eq('id', profile.organization_id)
.single();
if (!org?.stripe_customer_id) {
return NextResponse.json([]);
}
const invoices = await stripe.invoices.list({
customer: org.stripe_customer_id as string,
limit: 24,
});
const result = invoices.data.map((inv) => ({
id: inv.id,
number: inv.number,
date: inv.created ? new Date(inv.created * 1000).toISOString() : null,
amount: inv.amount_paid != null ? inv.amount_paid / 100 : 0,
currency: inv.currency ?? 'usd',
status: inv.status,
pdfUrl: inv.invoice_pdf,
}));
return NextResponse.json(result);
} catch (err) {
console.error('[stripe/invoices] GET error:', err);
return NextResponse.json(
{ error: err instanceof Error ? err.message : 'Internal error' },
{ status: 500 },
);
}
}