import { z } from 'zod'; import { BillingSchema, Money } from './billing'; import { ListSchema } from './common'; import type { PaymentInputSchemaType, PaymentResponseSchemaType, } from './payment'; import { PaymentInputSchema, PaymentResponseSchema } from './payment'; /** * @deprecated */ export const ProductSchema = z.object({ productId: z.number(), startDate: z.string(), description: z.string(), firstPaymentAmount: z.number(), billingFrequency: z.enum(['yearly', 'monthly', 'weekly', 'daily']), billingFrequencyInterval: z.number(), name: z.string(), price: z.number(), firstBillingDate: z.string(), imageUrl: z.string(), minimumStartDate: z.string(), maximumStartDate: z.string().nullable(), }); /** * @deprecated */ export const ActivationProductSchema = ProductSchema.pick({ name: true, description: true, price: true, }).extend({ id: z.number(), }); /** * @deprecated */ export const ProductHalSchema = ProductSchema.extend({ _embedded: z .object({ activationProduct: ActivationProductSchema, }) .optional(), }); /** * @deprecated */ export const ProductInputSchema = ProductSchema.pick({ productId: true, startDate: true, }); export const VatCategory = z.object({ id: z.string(), name: z.string(), }); export const VatCategoryHal = VatCategory.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), }); export const VatPercentage = z.object({ id: z.string(), vatCategoryId: z.string(), value: z.number(), }); export const VatPercentageHal = VatPercentage.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), _embedded: z.object({ vatCategory: VatCategoryHal, }), }); export const Product = z.object({ id: z.string(), name: z.string(), description: z.string(), imageUrl: z.string(), priceInclVat: Money, summary: z.string().nullable(), }); export type ProductType = z.infer; export const ProductHal = Product.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), }); export type ProductHalSchemaType = z.infer; export const OrderLineItemSchema = z.object({ id: z.string(), orderId: z.string(), productId: z.string(), vatPercentageId: z.string(), quantity: z.number(), priceInclVat: Money, totalPriceInclVat: Money, subscription: BillingSchema.extend({ firstBillingDate: z.string().nullable(), }).nullable(), options: z .object({ startDate: z.string().nullable(), }) .nullable(), }); export type OrderLineItemSchemaType = z.infer; export const OrderLineItemInputSchema = OrderLineItemSchema.pick({ productId: true, quantity: true, }); export type OrderLineItemInputSchemaType = z.infer< typeof OrderLineItemInputSchema >; export const OrderLineItemUpdateInputSchema = OrderLineItemSchema.pick({ quantity: true, }) .extend({ options: z .object({ startDate: z.string(), }) .nullable(), }) .partial(); export type OrderLineItemUpdateInputSchemaType = z.infer< typeof OrderLineItemUpdateInputSchema >; export const OrderLineItemHalSchema = OrderLineItemSchema.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), _embedded: z.object({ product: ProductHal, vatPercentage: VatPercentageHal, }), }); export type OrderLineItemHalSchemaType = z.infer; export const OrderSchema = z.object({ id: z.string(), /** * @deprecated use `id` instead */ orderId: z.number(), sessionId: z.string(), status: z.string(), firstName: z.string(), lastName: z.string(), emailAddress: z.string(), birthdate: z.string(), street: z.string().nullable(), postalCode: z.string().nullable(), city: z.string().nullable(), houseNumber: z.string().nullable(), houseNumberExtension: z.string().nullable(), country: z.string().nullable(), photoUrl: z.string().nullable(), newsletterSubscription: z.boolean().optional(), newsletterLanguageCode: z.string().optional(), termsAndConditionsAcceptedAt: z.string().nullable(), privacyStatementAcceptedAt: z.string().nullable(), updatedAt: z.string(), createdAt: z.string(), /** * @deprecated the payment URL should come from order confirmation */ paymentUrl: z.string().nullish(), totalPriceInclVat: Money.nullable(), voucherCode: z.string().nullish(), }); export const OrderHalSchema = OrderSchema.extend({ _links: z.object({ self: z.object({ href: z.string(), }), }), _embedded: z.object({ products: z.array(ProductHalSchema).optional(), lineItems: z.array(OrderLineItemHalSchema).optional(), }), }); export type OrderHalSchemaType = z.infer; export const OrderCreateInputSchema = OrderSchema.pick({ birthdate: true, }).extend({ /** * @deprecated */ serviceConditions: z.string().nullish(), /** * @deprecated */ firstName: z.string().optional(), /** * @deprecated */ lastName: z.string().optional(), /** * @deprecated */ emailAddress: z.string().optional(), street: z.string().nullable().optional(), postalCode: z.string().nullable().optional(), city: z.string().nullable().optional(), houseNumber: z.string().nullable().optional(), houseNumberExtension: z.string().nullable().optional(), country: z.string().nullable().optional(), }); export type OrderCreateInputSchemaType = z.infer; export const OrderUpdateInputSchema = OrderSchema.pick({ firstName: true, lastName: true, emailAddress: true, birthdate: true, street: true, postalCode: true, city: true, houseNumber: true, houseNumberExtension: true, country: true, termsAndConditionsAcceptedAt: true, privacyStatementAcceptedAt: true, newsletterSubscription: true, newsletterLanguageCode: true, }).extend({ serviceConditions: z.string().optional(), products: z.array(ProductInputSchema).optional(), }); export type OrderUpdateInputSchemaType = z.infer; export const PaymentMethodIssuerSchema = z.object({ id: z.string(), name: z.string(), }); export const PaymentMethodSchema = z.object({ id: z.string(), issuers: z.array(PaymentMethodIssuerSchema).optional(), }); export type PaymentMethodSchemaType = z.infer; export const PaymentMethodHalListSchema = ListSchema.extend({ _embedded: z.object({ paymentMethods: z.array(PaymentMethodSchema), }), _links: z.undefined().optional(), }); export type PaymentMethodHalListSchemaType = z.infer< typeof PaymentMethodHalListSchema >; export const StartPaymentInputSchema = z.object({ paymentMethod: z.string(), paymentMethodDetails: z.object({ issuerId: z.string().nullish(), }), returnUrlSuccess: z.string(), returnUrlFailure: z.string(), }); export type StartPaymentInputSchemaType = z.infer< typeof StartPaymentInputSchema >; export const StartPaymentResponseSchema = z.object({ _links: z.object({ paymentUrl: z.object({ href: z.string(), }), }), }); export type StartPaymentResponseSchemaType = z.infer< typeof StartPaymentResponseSchema >; export const AvailableProductsListSchema = z.object({ items: z.array(ProductSchema), }); export type AvailableProductsListSchemaType = z.infer< typeof AvailableProductsListSchema >; export const OrderConfirmInputSchema = PaymentInputSchema; export type OrderConfirmInputSchemaType = PaymentInputSchemaType; export const OrderConfirmResponseSchema = PaymentResponseSchema; export type OrderConfirmResponseSchemaType = PaymentResponseSchemaType; export const AddVoucherInputSchema = z.object({ code: z.string(), }); export type AddVoucherInputSchemaType = z.infer; export const AddVoucherResponseSchema = z.object({ code: z.string(), }); export type AddVoucherResponseSchemaType = z.infer< typeof AddVoucherResponseSchema >; export const ProductOptionInformationResponse = z.object({ startDate: z.object({ minimum: z.string(), maximum: z.string().nullable(), }), }); export type ProductOptionInformationResponseType = z.infer< typeof ProductOptionInformationResponse >;