rc 1.0
This commit is contained in:
27
app/api/shipping-fee/route.ts
Normal file
27
app/api/shipping-fee/route.ts
Normal 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',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user