From 9c134eeadd7fe9160a0db28a835f424f806f1b55 Mon Sep 17 00:00:00 2001 From: Rupert Bates Date: Fri, 31 Jan 2025 16:41:59 +0000 Subject: [PATCH] Tick off some more TODOs --- .../assets/helpers/productPrice/billingPeriods.ts | 2 ++ support-workers/src/typescript/model/address.ts | 5 ++++- support-workers/src/typescript/model/billingPeriod.ts | 7 ++----- support-workers/src/typescript/model/paymentFields.ts | 4 ++-- support-workers/src/typescript/model/paymentMethod.ts | 7 ++++--- support-workers/src/typescript/model/stateSchemas.ts | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/support-frontend/assets/helpers/productPrice/billingPeriods.ts b/support-frontend/assets/helpers/productPrice/billingPeriods.ts index 1331aa49e3..f6f0acb5df 100644 --- a/support-frontend/assets/helpers/productPrice/billingPeriods.ts +++ b/support-frontend/assets/helpers/productPrice/billingPeriods.ts @@ -9,6 +9,8 @@ export type WeeklyBillingPeriod = | typeof Quarterly | typeof Annual; +export const allBillingPeriods = [Monthly, Quarterly, Annual] as const; + const weeklyBillingPeriods = (): WeeklyBillingPeriod[] => { return [Monthly, Quarterly, Annual]; }; diff --git a/support-workers/src/typescript/model/address.ts b/support-workers/src/typescript/model/address.ts index 80a07a32f0..55d13b5315 100644 --- a/support-workers/src/typescript/model/address.ts +++ b/support-workers/src/typescript/model/address.ts @@ -1,4 +1,7 @@ import { z } from 'zod'; +import { isoCountries } from '../../../../support-frontend/assets/helpers/internationalisation/country'; + +export const countrySchema = z.enum(isoCountries); export const addressSchema = z.object({ lineOne: z.string().nullable(), @@ -6,7 +9,7 @@ export const addressSchema = z.object({ city: z.string().nullable(), state: z.string().nullable(), postCode: z.string().nullable(), - country: z.string(), //TODO: build a schema for this + country: countrySchema, }); type AddressLine = { diff --git a/support-workers/src/typescript/model/billingPeriod.ts b/support-workers/src/typescript/model/billingPeriod.ts index cd71162968..78aa4aceca 100644 --- a/support-workers/src/typescript/model/billingPeriod.ts +++ b/support-workers/src/typescript/model/billingPeriod.ts @@ -1,8 +1,5 @@ import { z } from 'zod'; +import { allBillingPeriods } from '../../../../support-frontend/assets/helpers/productPrice/billingPeriods'; -export const billingPeriodSchema = z.union([ - z.literal('Monthly'), //TODO: share this with support-frontend - z.literal('Annual'), - z.literal('Quarterly'), -]); +export const billingPeriodSchema = z.enum(allBillingPeriods); export type BillingPeriod = z.infer; diff --git a/support-workers/src/typescript/model/paymentFields.ts b/support-workers/src/typescript/model/paymentFields.ts index e885f81a77..05c7db6968 100644 --- a/support-workers/src/typescript/model/paymentFields.ts +++ b/support-workers/src/typescript/model/paymentFields.ts @@ -28,8 +28,8 @@ export const stripePaymentTypeSchema = z.union([ const stripePaymentFieldsSchema = z.object({ paymentType: stripePaymentProviderSchema, paymentMethod: z.string(), - stripePaymentType: stripePaymentTypeSchema, //TODO: this was optional in scala model - stripePublicKey: z.string(), //TODO: this has more validation in scala model + stripePaymentType: stripePaymentTypeSchema, + stripePublicKey: z.string(), }); export type StripePaymentFields = z.infer; const directDebitPaymentFieldsSchema = z.object({ diff --git a/support-workers/src/typescript/model/paymentMethod.ts b/support-workers/src/typescript/model/paymentMethod.ts index 6078af5d20..995eb010e8 100644 --- a/support-workers/src/typescript/model/paymentMethod.ts +++ b/support-workers/src/typescript/model/paymentMethod.ts @@ -1,4 +1,5 @@ import { z } from 'zod'; +import { countrySchema } from './address'; import { stripePaymentTypeSchema } from './paymentFields'; // Payment methods are the activated payment details which are passed into Zuora as opposed to // payment fields which are the details entered by the user into the checkout @@ -34,13 +35,13 @@ const stripePaymentMethodSchema = z.object({ TokenId: z.string(), // Stripe Card id SecondTokenId: z.string(), // Stripe Customer Id CreditCardNumber: z.string(), - CreditCardCountry: z.string().nullable(), //TODO: build a schema for this + CreditCardCountry: z.string().nullable(), CreditCardExpirationMonth: z.number(), CreditCardExpirationYear: z.number(), CreditCardType: z.string().optional(), PaymentGateway: stripePaymentGatewaySchema, Type: z.literal('CreditCardReferenceTransaction'), - StripePaymentType: stripePaymentTypeSchema, //TODO: this is optional in the scala model + StripePaymentType: stripePaymentTypeSchema, }); export type StripePaymentMethod = z.infer; @@ -50,7 +51,7 @@ const directDebitPaymentMethodSchema = z.object({ BankTransferAccountName: z.string(), BankCode: z.string(), BankTransferAccountNumber: z.string(), - Country: z.string(), //TODO: build a schema for this + Country: countrySchema, City: z.string().nullable(), PostalCode: z.string().nullable(), State: z.string().nullable(), diff --git a/support-workers/src/typescript/model/stateSchemas.ts b/support-workers/src/typescript/model/stateSchemas.ts index 4d96218705..d467a59809 100644 --- a/support-workers/src/typescript/model/stateSchemas.ts +++ b/support-workers/src/typescript/model/stateSchemas.ts @@ -90,7 +90,7 @@ const baseStateSchema = z.object({ appliedPromotion: z .object({ promoCode: z.string(), - countryGroupId: z.string(), //TODO: build a schema for this or take it from the frontend + countryGroupId: z.string(), }) .nullable(), csrUsername: z.string().nullable(),