This commit is contained in:
root
2025-12-21 17:36:44 +01:00
parent bb1c5b43d6
commit 8a0835c564
15 changed files with 1124 additions and 193 deletions

View File

@@ -1,5 +1,6 @@
import { NextResponse } from 'next/server'
import { getNowPaymentsConfig } from '@/lib/nowpayments'
import { ALLOWED_PAYMENT_CURRENCIES } from '@/lib/payment-currencies'
// GET /api/payments/currencies - Get available payment currencies from NOWPayments
export async function GET() {
@@ -27,10 +28,27 @@ export async function GET() {
}
const data = await response.json()
// Filter currencies to only include the selected list
const currencies = (data.currencies || []).filter((c: any) => {
let currencyCode: string | null = null
// Handle object format (when fixed_rate=true)
if (typeof c === 'object' && c !== null && c.currency) {
currencyCode = String(c.currency).trim().toLowerCase()
}
// Handle string format (when fixed_rate=false)
else if (typeof c === 'string') {
currencyCode = c.trim().toLowerCase()
}
// Check if currency is in the allowed list
return currencyCode && ALLOWED_PAYMENT_CURRENCIES.includes(currencyCode as any)
})
// Return the currencies array
// Return the filtered currencies array
return NextResponse.json({
currencies: data.currencies || [],
currencies: currencies,
})
} catch (error) {
console.error('Error fetching currencies:', error)