Adding features

This commit is contained in:
Jennie Robinson Faber 2025-10-05 16:15:09 +01:00
parent 600fef2b7c
commit 2b55ca4104
75 changed files with 9796 additions and 2759 deletions

View file

@ -0,0 +1,61 @@
// Create a new Helcim payment plan
const HELCIM_API_BASE = 'https://api.helcim.com/v2'
export default defineEventHandler(async (event) => {
try {
const config = useRuntimeConfig(event)
const body = await readBody(event)
// Validate required fields
if (!body.name || !body.amount || !body.frequency) {
throw createError({
statusCode: 400,
statusMessage: 'Name, amount, and frequency are required'
})
}
const helcimToken = config.public.helcimToken || process.env.NUXT_PUBLIC_HELCIM_TOKEN
console.log('Creating payment plan:', body.name)
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'
})
})
if (!response.ok) {
const errorText = await response.text()
console.error('Failed to create payment plan:', response.status, errorText)
throw createError({
statusCode: response.status,
statusMessage: `Failed to create payment plan: ${errorText}`
})
}
const planData = await response.json()
console.log('Payment plan created:', planData)
return {
success: true,
plan: planData
}
} catch (error) {
console.error('Error creating Helcim payment plan:', error)
throw createError({
statusCode: error.statusCode || 500,
statusMessage: error.message || 'Failed to create payment plan'
})
}
})