import {z} from 'zod' export type GetApiApiPublicPaymentsStrategiesIdArgs = {id: string}; export type GetApiApiPublicPaymentsStrategiesIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const gETPaymentStrategiesGetPublicPaymentStrategy200Response = z.object({_id: z.string(), sellerId: z.string(), name: z.string(), policy: z.object({allowedPaymentGateways: z.array(z.object({gatewayId: z.string()})), changePaymentMethodPolicy: z.enum(["always", "never"]).optional(), paymentCompletionPolicy: z.object({target: z.enum(["none", "event_start_date", "event_end_date"])}).optional()}), options: z.array(z.object({_id: z.string().optional(), status: z.enum(["ENABLED", "DISABLED"]), name: z.string(), scheme: z.enum(["one-off", "installments"]), installmentOptions: z.object({interval: z.enum(["DAY", "WEEK", "MONTH"]), numberOfInstallments: z.number().int().gte(1), every: z.number().int().gte(1), timingOptions: z.object({type: z.enum(["first_installment", "last_installment"]), offsetOptions: z.union([z.object({anchor: z.literal("order_date"), offset: z.number().int().gte(1), offsetUnit: z.enum(["DAY", "WEEK", "MONTH"]).optional()}), z.object({anchor: z.literal("event_start_date"), offset: z.number().int().lte(-1), offsetUnit: z.enum(["DAY", "WEEK", "MONTH"])})]).optional()}).optional()}).optional(), downPaymentOptions: z.object({type: z.enum(["none", "percent", "fixed"]), value: z.number().gte(0)}).optional(), requirements: z.object({minAmount: z.number().gte(0).optional(), maxAmount: z.number().gte(0).optional()}).optional(), feeOptions: z.object({outerChargeVar: z.number().gte(0).optional(), outerChargeFix: z.number().gte(0).optional()}).optional()}))}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Public Payment Strategy * * GET /api/public/payments/strategies/{id} */ export const getApiApiPublicPaymentsStrategiesId = async (args: GetApiApiPublicPaymentsStrategiesIdArgs, options?: GetApiApiPublicPaymentsStrategiesIdOptions) => { const {baseUrl = "https://vivenu.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/public/payments/strategies/${encodeURIComponent(String(args.id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(gETPaymentStrategiesGetPublicPaymentStrategy200Response, await res.json()) };