import {z} from 'zod' export type GetApiApiV1PaymentMethodsArgs = {code?: string | undefined, id?: string | undefined, limit?: number | undefined, page?: number | undefined, getResult?: (0 | 1) | undefined, 'Time-Stamp': string, 'Time-Signature': string, 'User-Token': string, 'Client-Token': string}; export type GetApiApiV1PaymentMethodsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const peakWCFModelsAPIBodyAPIBodyPaymentMethod = z.object({totalPaymentMethod: z.number().int().optional(), resDesc: z.string().optional(), resCode: z.string().optional()}); export const peakWCFModelsAPIResponseResponsePaymentMethodModel = z.object({peakPaymentMethods: peakWCFModelsAPIBodyAPIBodyPaymentMethod.optional(), eventType: z.string().optional(), apiType: z.string().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 Payment Method * * GET /api/v1/PaymentMethods */ export const getApiApiV1PaymentMethods = async (args: GetApiApiV1PaymentMethodsArgs, options?: GetApiApiV1PaymentMethodsOptions) => { const {baseUrl = "https://api.peakaccount.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.code != null) query.append("code", String(args.code)) if (args.id != null) query.append("id", String(args.id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.getResult != null) query.append("getResult", String(args.getResult)) if (args['Time-Stamp'] != null) headers.set("Time-Stamp", String(args['Time-Stamp'])) if (args['Time-Signature'] != null) headers.set("Time-Signature", String(args['Time-Signature'])) if (args['User-Token'] != null) headers.set("User-Token", String(args['User-Token'])) if (args['Client-Token'] != null) headers.set("Client-Token", String(args['Client-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/PaymentMethods${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(peakWCFModelsAPIResponseResponsePaymentMethodModel, await res.json()) };