This commit is contained in:
root
2025-12-22 06:43:19 +01:00
parent a940d51475
commit 6f4ca75faf
25 changed files with 1350 additions and 221 deletions

View File

@@ -0,0 +1,27 @@
import { NextRequest, NextResponse } from 'next/server'
import { getCountryFromIp, calculateShippingFee } from '@/lib/geolocation'
import { getCurrencyForCountry } from '@/lib/currency'
// GET /api/shipping-fee - Get shipping fee based on user's IP location
export async function GET(request: NextRequest) {
try {
const countryCode = await getCountryFromIp(request)
const shippingFee = calculateShippingFee(countryCode)
const currency = getCurrencyForCountry(countryCode)
return NextResponse.json({
shipping_fee: shippingFee,
country_code: countryCode,
currency: currency,
})
} catch (error) {
console.error('Error calculating shipping fee:', error)
// Default to 40 EUR if detection fails
return NextResponse.json({
shipping_fee: 40,
country_code: null,
currency: 'EUR',
})
}
}