44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { getNowPaymentsConfig } from '@/lib/nowpayments'
|
|
|
|
// GET /api/payments/currencies - Get available payment currencies from NOWPayments
|
|
export async function GET() {
|
|
try {
|
|
const nowPaymentsConfig = getNowPaymentsConfig()
|
|
|
|
// Fetch available currencies from NOWPayments
|
|
const response = await fetch(
|
|
`${nowPaymentsConfig.baseUrl}/v1/currencies?fixed_rate=true`,
|
|
{
|
|
method: 'GET',
|
|
headers: {
|
|
'x-api-key': nowPaymentsConfig.apiKey,
|
|
},
|
|
}
|
|
)
|
|
|
|
if (!response.ok) {
|
|
const error = await response.json()
|
|
console.error('NOWPayments currencies error:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch available currencies', details: error },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
|
|
const data = await response.json()
|
|
|
|
// Return the currencies array
|
|
return NextResponse.json({
|
|
currencies: data.currencies || [],
|
|
})
|
|
} catch (error) {
|
|
console.error('Error fetching currencies:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch currencies' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|
|
|