Refactored both Stripe and Team Accounts features' schemas for better data validation and added specificity to keys. Enhanced form validations with methods to ensure Stripe keys follow appropriate prefixes. Replaced generic string types with UUID for accountId attributes in different services. Also turned off autocomplete for destructive actions for improved security.
32 lines
813 B
TypeScript
32 lines
813 B
TypeScript
import { z } from 'zod';
|
|
|
|
import { LineItemUsageType, PaymentType } from '../create-billing-schema';
|
|
|
|
export const CreateBillingCheckoutSchema = z
|
|
.object({
|
|
returnUrl: z.string().url(),
|
|
accountId: z.string().uuid(),
|
|
paymentType: PaymentType,
|
|
lineItems: z.array(
|
|
z.object({
|
|
id: z.string(),
|
|
quantity: z.number().int().positive(),
|
|
usageType: LineItemUsageType.optional(),
|
|
}),
|
|
),
|
|
trialDays: z.number().optional(),
|
|
customerId: z.string().optional(),
|
|
customerEmail: z.string().email().optional(),
|
|
})
|
|
.refine(
|
|
(schema) => {
|
|
if (schema.paymentType === 'one-time' && schema.trialDays) {
|
|
return false;
|
|
}
|
|
},
|
|
{
|
|
message: 'Trial days are only allowed for recurring payments',
|
|
path: ['trialDays'],
|
|
},
|
|
);
|