race condition fixed, payment inside
This commit is contained in:
43
app/api/payments/currencies/route.ts
Normal file
43
app/api/payments/currencies/route.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user