import {z} from 'zod' export type GetApiMerchantsMerchantIdCustomersCustomerIdContractsArgs = {Authorization: unknown, Accept: string, 'Content-Type': string, merchant_id: string, customer_id: string}; export type GetApiMerchantsMerchantIdCustomersCustomerIdContractsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const contract = z.object({customer_id: z.string().optional(), bill_amount: z.string().optional(), status: z.enum(["enabled", "disabled", "completed"]).optional(), start_date: z.string().optional(), end_date: z.string().optional(), schedule: z.string().optional(), num_left: z.string().optional()}); export const version = z.string(); export const getApiMerchantsMerchantIdCustomersCustomerIdContractsResponse = z.object({contracts: z.array(contract).optional(), v: version.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 the contract for a Merchant's Customer * * GET /merchants/{merchant_id}/customers/{customer_id}/contracts */ export const getApiMerchantsMerchantIdCustomersCustomerIdContracts = async (args: GetApiMerchantsMerchantIdCustomersCustomerIdContractsArgs, options?: GetApiMerchantsMerchantIdCustomersCustomerIdContractsOptions) => { const {baseUrl = "https://tb.paymentfusion.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) const url = `${baseUrl.replace(/\/+$/, '')}/merchants/${encodeURIComponent(String(args.merchant_id))}/customers/${encodeURIComponent(String(args.customer_id))}/contracts${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(getApiMerchantsMerchantIdCustomersCustomerIdContractsResponse, await res.json()) };