- 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>
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getSession } from '@/lib/auth';
|
|
import { createDFYCheckoutSession } from '@/lib/stripe/checkout';
|
|
import { z } from 'zod';
|
|
|
|
const checkoutSchema = z.object({
|
|
productId: z.string(),
|
|
});
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const session = await getSession();
|
|
if (!session) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const body = await request.json();
|
|
const { productId } = checkoutSchema.parse(body);
|
|
|
|
const baseUrl = request.nextUrl.origin;
|
|
|
|
const checkoutSession = await createDFYCheckoutSession({
|
|
userId: session.user.id,
|
|
productId,
|
|
successUrl: `${baseUrl}/dfy/success?session_id={CHECKOUT_SESSION_ID}`,
|
|
cancelUrl: `${baseUrl}/dfy/cancel`,
|
|
});
|
|
|
|
return NextResponse.json({
|
|
checkoutUrl: checkoutSession.url,
|
|
sessionId: checkoutSession.id,
|
|
});
|
|
} catch (error) {
|
|
console.error('Checkout error:', error);
|
|
if (error instanceof z.ZodError) {
|
|
return NextResponse.json({ error: 'Invalid request', details: error.issues }, { status: 400 });
|
|
}
|
|
return NextResponse.json({ error: 'Failed to create checkout session' }, { status: 500 });
|
|
}
|
|
}
|