- Build complete Next.js CRM for commercial real estate - Add authentication with JWT sessions and role-based access - Add GoHighLevel API integration for contacts, conversations, opportunities - Add AI-powered Control Center with tool calling - Add Setup page with onboarding checklist (/setup) - Add sidebar navigation with Setup menu item - Fix type errors in onboarding API, GHL services, and control center tools - Add Prisma schema with SQLite for local development - Add UI components with clay morphism design system Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getStripeClient } from '@/lib/stripe/client';
|
|
import { handleCheckoutComplete } from '@/lib/stripe/checkout';
|
|
import { settingsService } from '@/lib/settings/settings-service';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = await request.text();
|
|
const signature = request.headers.get('stripe-signature');
|
|
|
|
if (!signature) {
|
|
return NextResponse.json({ error: 'No signature' }, { status: 400 });
|
|
}
|
|
|
|
const settings = await settingsService.getAll();
|
|
if (!settings.stripeWebhookSecret) {
|
|
console.error('Stripe webhook secret not configured');
|
|
return NextResponse.json({ error: 'Webhook not configured' }, { status: 500 });
|
|
}
|
|
|
|
const stripe = await getStripeClient();
|
|
const event = stripe.webhooks.constructEvent(
|
|
body,
|
|
signature,
|
|
settings.stripeWebhookSecret
|
|
);
|
|
|
|
switch (event.type) {
|
|
case 'checkout.session.completed': {
|
|
const session = event.data.object;
|
|
if (session.metadata?.type === 'dfy_service') {
|
|
await handleCheckoutComplete(session.id);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case 'payment_intent.payment_failed': {
|
|
const paymentIntent = event.data.object;
|
|
console.log('Payment failed:', paymentIntent.id);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({ received: true });
|
|
} catch (error) {
|
|
console.error('Webhook error:', error);
|
|
return NextResponse.json({ error: 'Webhook handler failed' }, { status: 500 });
|
|
}
|
|
}
|