boxy/app/api/create-payment-intent/route.ts
2025-06-23 01:25:35 +05:30

42 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server';
import { createPaymentIntent } from '@/app/lib/stripe';
export async function POST(req: Request) {
try {
console.log('Creating payment intent...');
// For now, we'll skip authentication check until Firebase Admin is set up
// TODO: Add proper authentication check with Firebase Admin
const { amount, currency } = await req.json();
console.log('Payment intent request:', { amount, currency });
if (!amount || amount <= 0) {
console.error('Invalid amount:', amount);
return NextResponse.json(
{ error: 'Invalid amount' },
{ status: 400 }
);
}
console.log('Calling createPaymentIntent with:', { amount, currency });
const { clientSecret, paymentIntentId } = await createPaymentIntent(
amount,
currency
);
console.log('Payment intent created successfully:', { paymentIntentId });
return NextResponse.json({
clientSecret,
paymentIntentId,
});
} catch (error) {
console.error('Error creating payment intent:', error);
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Error creating payment intent' },
{ status: 500 }
);
}
}