import {z} from 'zod' export type UpdateApiV3CollectionAccountIdArgs = {id: string, body: {metadata?: Record | undefined}}; export type UpdateApiV3CollectionAccountIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const collectionAccountRequest = z.object({id: z.string().optional(), object: z.string().optional(), collection_account_id: z.string().optional(), type: z.enum(["enablement", "disablement", "reenablement"]).optional(), status: z.enum(["processing", "approval_hold", "requires_action", "succeeded", "failed", "cancelled"]).optional(), requested_currencies: z.array(z.string()).optional(), created_at: z.string().optional(), updated_at: z.string().optional(), status_description: z.string().optional()}); export const collectionAccount = z.object({id: z.string().optional(), object: z.string().optional(), type: z.enum(["virtual_account", "wallet"]).optional(), description: z.string().optional(), on_behalf_of: z.string().optional(), country: z.string().optional(), currencies: z.array(z.string()).optional(), payment_method_type: z.string().optional(), virtual_account: z.object({account_holder_name: z.string().optional(), account_number: z.string().optional(), iban: z.string().optional(), bank_name: z.string().optional(), bank_branch: z.string().optional(), bank_address: z.object({address_line_1: z.string().optional(), address_line_2: z.string().optional(), city: z.string().optional(), country: z.string().optional()}).optional(), bank_codes: z.record(z.string(), z.string()).optional(), account_reenablement_supported: z.boolean().optional()}).optional(), wallet: z.object({type: z.string().optional(), deposit_address: z.string().optional()}).optional(), status: z.enum(["disabled", "enabled"]).optional(), requests: z.array(collectionAccountRequest).optional(), status_description: z.string().optional(), alias: z.string().optional(), balance_transaction: z.string().optional(), metadata: z.object({}).optional(), created_at: z.string().optional(), updated_at: 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 }; /** * Update Collection Account * * PUT /v3/collection_account/{id} */ export const updateApiV3CollectionAccountId = async (args: UpdateApiV3CollectionAccountIdArgs, options?: UpdateApiV3CollectionAccountIdOptions) => { const {baseUrl = "https://service-sandbox.tazapay.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/collection_account/${encodeURIComponent(String(args.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(collectionAccount, await res.json()) };