refactor(helcim): use helper in unused admin endpoints
This commit is contained in:
parent
0d792c7c70
commit
130e5bfa9f
4 changed files with 29 additions and 113 deletions
|
|
@ -1,35 +1,17 @@
|
|||
// Get Helcim payment plans
|
||||
const HELCIM_API_BASE = 'https://api.helcim.com/v2'
|
||||
import { listHelcimPlans } from '../../utils/helcim.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
await requireAdmin(event)
|
||||
const config = useRuntimeConfig(event)
|
||||
const helcimToken = config.helcimApiToken
|
||||
|
||||
const response = await fetch(`${HELCIM_API_BASE}/payment-plans`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'accept': 'application/json',
|
||||
'api-token': helcimToken
|
||||
}
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
console.error('Failed to fetch payment plans:', response.status, response.statusText)
|
||||
throw createError({
|
||||
statusCode: response.status,
|
||||
statusMessage: 'Failed to fetch payment plans'
|
||||
})
|
||||
}
|
||||
|
||||
const plansData = await response.json()
|
||||
|
||||
|
||||
const plansData = await listHelcimPlans()
|
||||
|
||||
return {
|
||||
success: true,
|
||||
plans: plansData
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
if (error.statusCode) throw error
|
||||
console.error('Error fetching Helcim payment plans:', error)
|
||||
|
|
@ -38,4 +20,4 @@ export default defineEventHandler(async (event) => {
|
|||
statusMessage: 'An unexpected error occurred'
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue