ghostguild-org/server/api/helcim/verify-payment.post.js
Jennie Robinson Faber 10a28ac5ef
All checks were successful
Test / vitest (push) Successful in 13m42s
Test / playwright (push) Successful in 19m35s
Test / Notify on failure (push) Has been skipped
feat(helcim): accept signup-bridge cookie in verify-payment
Membership signup verifies the card before email verification, so the
signup-bridge cookie set by /api/helcim/customer now satisfies auth in
verify-payment when no session exists. Adds a cloudflared tunnel script
for testing the Helcim flow locally against a production build.
2026-05-24 14:01:02 +01:00

44 lines
1.5 KiB
JavaScript

// Verify payment token from HelcimPay.js
import { requireAuth, getSignupBridgeMember } from '../../utils/auth.js'
import { validateBody } from '../../utils/validateBody.js'
import { paymentVerifySchema } from '../../utils/schemas.js'
import { listHelcimCustomerCards } from '../../utils/helcim.js'
export default defineEventHandler(async (event) => {
try {
// Membership signup verifies the card before email verify; allow the
// signup-bridge cookie set by /api/helcim/customer to satisfy auth here.
const bridgeMember = await getSignupBridgeMember(event)
if (!bridgeMember) {
await requireAuth(event)
}
const body = await validateBody(event, paymentVerifySchema)
// Verify the card token by fetching the customer's cards from Helcim
const cards = await listHelcimCustomerCards(body.customerId)
// Verify the card token exists for this customer
const cardExists = cards.some(card =>
card.cardToken === body.cardToken
)
if (!cardExists) {
throw createError({
statusCode: 400,
statusMessage: 'Payment method not found or does not belong to this customer'
})
}
return {
success: true,
cardToken: body.cardToken,
message: 'Payment verified with Helcim'
}
} catch (error) {
console.error('Error verifying payment:', error)
throw createError({
statusCode: error.statusCode || 500,
statusMessage: error.statusMessage || 'Failed to verify payment'
})
}
})