import {z} from 'zod' export type GetApiV1BankBilletPaymentsIdArgs = {'User-Agent'?: string | undefined, id: string}; export type GetApiV1BankBilletPaymentsIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const bankBilletPaymentObject = z.object({id: z.number().int().optional(), bank_billet_id: z.number().int().nullable(), bank_billet_account_id: z.number().int().nullable(), discharge_id: z.number().int().nullable().optional(), amount: z.number().optional(), paid_amount: z.number(), paid_at: z.string().nullable(), paid_bank: z.string().max(3).nullable().optional(), paid_agency: z.string().max(5).nullable().optional(), paid_agency_number: z.string().max(4).nullable().optional(), paid_agency_digit: z.string().max(1).nullable().optional(), bank_rate: z.number().nullable().optional(), credit_at: z.string().nullable().optional(), direct: z.boolean().nullable().optional(), expire_at: z.string().nullable().optional(), kind: z.union([z.literal(0), z.literal(1), z.literal(2)]), document_number: z.string().nullable().optional(), our_number: z.string().nullable().optional(), created_via_api: z.boolean().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), customer_person_name: z.string().max(255).nullable().optional(), paid_by_pix: z.boolean().nullable().optional(), financial_provider_external_id: z.string().nullable().optional(), line_parsed: z.string().nullable().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 }; /** * Informações do Pagamento de Boleto * * GET /v1/bank_billet_payments/{id} */ export const getApiV1BankBilletPaymentsId = async (args: GetApiV1BankBilletPaymentsIdArgs, options?: GetApiV1BankBilletPaymentsIdOptions) => { const {baseUrl = "https://api-sandbox.kobana.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bank_billet_payments/${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(bankBilletPaymentObject, await res.json()) };