refactor(payments): extract PAYMENT_METADATA_TYPE constants
This commit is contained in:
parent
0eeb3c351f
commit
5432dfe8f2
4 changed files with 24 additions and 4 deletions
|
|
@ -10,10 +10,10 @@ export default defineEventHandler(async (event) => {
|
|||
const body = await validateBody(event, helcimInitializePaymentSchema)
|
||||
const metaType = body.metadata?.type
|
||||
|
||||
const isEventTicket = metaType === 'event_ticket'
|
||||
const isSeriesTicket = metaType === 'series_ticket'
|
||||
const isEventTicket = metaType === PAYMENT_METADATA_TYPES.EVENT_TICKET
|
||||
const isSeriesTicket = metaType === PAYMENT_METADATA_TYPES.SERIES_TICKET
|
||||
const isTicket = isEventTicket || isSeriesTicket
|
||||
const isMembershipSignup = metaType === 'membership_signup'
|
||||
const isMembershipSignup = metaType === PAYMENT_METADATA_TYPES.MEMBERSHIP_SIGNUP
|
||||
|
||||
if (!isTicket) {
|
||||
if (isMembershipSignup) {
|
||||
|
|
|
|||
15
server/utils/paymentTypes.js
Normal file
15
server/utils/paymentTypes.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Metadata.type values accepted by /api/helcim/initialize-payment.
|
||||
// Shared by the Zod schema (PAYMENT_METADATA_TYPE_VALUES in z.enum) and the
|
||||
// route handler so server-side wire validation stays single-sourced. The client
|
||||
// composable intentionally uses inline string literals — server-side z.enum
|
||||
// rejects any drift as a 400.
|
||||
|
||||
export const PAYMENT_METADATA_TYPES = {
|
||||
EVENT_TICKET: 'event_ticket',
|
||||
SERIES_TICKET: 'series_ticket',
|
||||
SUBSCRIPTION: 'subscription',
|
||||
CARD_VERIFY: 'card_verify',
|
||||
MEMBERSHIP_SIGNUP: 'membership_signup'
|
||||
}
|
||||
|
||||
export const PAYMENT_METADATA_TYPE_VALUES = Object.values(PAYMENT_METADATA_TYPES)
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import * as z from 'zod'
|
||||
import { ADMIN_ALERT_TYPES } from '../models/adminAlertDismissal.js'
|
||||
import { PAYMENT_METADATA_TYPE_VALUES } from './paymentTypes.js'
|
||||
|
||||
export const emailSchema = z.object({
|
||||
email: z.string().trim().toLowerCase().email()
|
||||
|
|
@ -71,7 +72,7 @@ export const helcimInitializePaymentSchema = z.object({
|
|||
amount: z.number().min(0).optional(),
|
||||
customerCode: z.string().max(200).optional(),
|
||||
metadata: z.object({
|
||||
type: z.enum(['event_ticket', 'series_ticket', 'subscription', 'card_verify', 'membership_signup']).optional(),
|
||||
type: z.enum(PAYMENT_METADATA_TYPE_VALUES).optional(),
|
||||
eventTitle: z.string().max(500).optional(),
|
||||
eventId: z.string().max(200).optional(),
|
||||
seriesId: z.string().max(200).optional(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue