Files
AnchorOS/app/api/create-payment-intent/route.ts
Marco Gallegos 28e98a2a44 feat: Complete SalonOS implementation with authentication, payments, reports, and documentation
- Implement client authentication with Supabase magic links
- Add Stripe payment integration for deposits
- Complete The Boutique booking flow with payment processing
- Implement Aperture backend with staff/resources management
- Add comprehensive reports: sales, payments, payroll
- Create permissions management system by roles
- Configure kiosk system with enrollment
- Add no-show logic and penalization system
- Update project documentation and API docs
- Enhance README with current project status
2026-01-16 17:35:29 -06:00

60 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import Stripe from 'stripe'
import { supabaseAdmin } from '@/lib/supabase/client'
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!)
export async function POST(request: NextRequest) {
try {
const {
customer_email,
customer_phone,
customer_first_name,
customer_last_name,
service_id,
location_id,
start_time_utc,
notes
} = await request.json()
// Get service price
const { data: service, error: serviceError } = await supabaseAdmin
.from('services')
.select('base_price, name')
.eq('id', service_id)
.single()
if (serviceError || !service) {
return NextResponse.json({ error: 'Service not found' }, { status: 400 })
}
// Calculate deposit (50% or $200 max)
const depositAmount = Math.min(service.base_price * 0.5, 200) * 100 // in cents
// Create payment intent
const paymentIntent = await stripe.paymentIntents.create({
amount: Math.round(depositAmount),
currency: 'usd',
metadata: {
service_id,
location_id,
start_time_utc,
customer_email,
customer_phone,
customer_first_name,
customer_last_name,
notes: notes || ''
},
receipt_email: customer_email,
})
return NextResponse.json({
clientSecret: paymentIntent.client_secret,
amount: depositAmount,
serviceName: service.name
})
} catch (error) {
console.error('Error creating payment intent:', error)
return NextResponse.json({ error: 'Internal server error' }, { status: 500 })
}
}