import {z} from 'zod' export type PayoutMethodRequest = {payout_method: string, description?: string | undefined, is_default?: boolean | undefined, payout_method_category?: ('REAL_TIME_GROSS_SETTLEMENT_SYSTEM' | 'REAL_TIME_NET_SETTLEMENT_SYSTEM' | 'MASS_NET_PAYMENT_SYSTEM' | 'BOOK_TRANSFER' | 'CASH_PAYOUT' | 'WALLET_PAYMENT' | 'OTHER') | undefined, estimated_time_to_credit?: ({time_value: number, time_unit: 'SECONDS' | 'MINUTES' | 'HOURS' | 'DAYS'}) | undefined}; export type UpdateApiConfigPayoutMethodsPayoutMethodIdArgs = {body: PayoutMethodRequest}; export type UpdateApiConfigPayoutMethodsPayoutMethodIdOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const payoutMethodResponse = z.object({payout_method_id: z.string().optional(), payout_method: z.string().optional(), description: z.string().optional(), is_default: z.boolean().optional(), payout_method_category: z.enum(["REAL_TIME_GROSS_SETTLEMENT_SYSTEM", "REAL_TIME_NET_SETTLEMENT_SYSTEM", "MASS_NET_PAYMENT_SYSTEM", "BOOK_TRANSFER", "CASH_PAYOUT", "WALLET_PAYMENT", "OTHER"]).optional(), estimated_time_to_credit: z.object({time_value: z.number().int(), time_unit: z.enum(["SECONDS", "MINUTES", "HOURS", "DAYS"])}).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 }; /** * Update payout method * * PUT /config/payout_methods/{payout_method_id} */ export const updateApiConfigPayoutMethodsPayoutMethodId = async (args: UpdateApiConfigPayoutMethodsPayoutMethodIdArgs, options: UpdateApiConfigPayoutMethodsPayoutMethodIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (Bearer !== undefined) headers.set("Authorization", Bearer) const url = `${baseUrl.replace(/\/+$/, '')}/config/payout_methods/${encodeURIComponent(String(args.payout_method_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(payoutMethodResponse, await res.json()) };