refactor(helcim): use helper in unused admin endpoints

This commit is contained in:
Jennie Robinson Faber 2026-04-08 22:11:25 +01:00
parent 0d792c7c70
commit 130e5bfa9f
4 changed files with 29 additions and 113 deletions

View file

@ -1,42 +1,18 @@
// Create a new Helcim payment plan
const HELCIM_API_BASE = 'https://api.helcim.com/v2'
import { createHelcimPlan } from '../../utils/helcim.js'
export default defineEventHandler(async (event) => {
try {
await requireAdmin(event)
const config = useRuntimeConfig(event)
const body = await validateBody(event, helcimCreatePlanSchema)
const helcimToken = config.helcimApiToken
const response = await fetch(`${HELCIM_API_BASE}/payment-plans`, {
method: 'POST',
headers: {
'accept': 'application/json',
'content-type': 'application/json',
'api-token': helcimToken
},
body: JSON.stringify({
planName: body.name,
planAmount: parseFloat(body.amount),
planFrequency: body.frequency, // 'monthly', 'weekly', 'biweekly', etc.
planCurrency: body.currency || 'CAD'
})
const planData = await createHelcimPlan({
planName: body.name,
planAmount: parseFloat(body.amount),
planFrequency: body.frequency,
planCurrency: body.currency || 'CAD'
})
if (!response.ok) {
const errorText = await response.text()
console.error('Failed to create payment plan:', response.status, errorText)
throw createError({
statusCode: response.status,
statusMessage: 'Payment plan creation failed'
})
}
const planData = await response.json()
return {
success: true,
plan: planData