import {z} from 'zod' export type GetApiV1BankBilletPaymentsArgs = {'User-Agent'?: string | undefined, page?: number | undefined, per_page?: number | undefined, paid_from?: string | undefined, paid_to?: string | undefined, bank_billet_id?: string | undefined, bank_billet_account_id?: string | undefined}; export type GetApiV1BankBilletPaymentsOptions = {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 getApiV1BankBilletPaymentsResponse = z.array(bankBilletPaymentObject); 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 }; /** * Listar Pagamentos de Boleto * * GET /v1/bank_billet_payments */ export const getApiV1BankBilletPayments = async (args: GetApiV1BankBilletPaymentsArgs, options?: GetApiV1BankBilletPaymentsOptions) => { 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 (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.paid_from != null) query.append("paid_from", String(args.paid_from)) if (args.paid_to != null) query.append("paid_to", String(args.paid_to)) if (args.bank_billet_id != null) query.append("bank_billet_id", String(args.bank_billet_id)) if (args.bank_billet_account_id != null) query.append("bank_billet_account_id", String(args.bank_billet_account_id)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/bank_billet_payments${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(getApiV1BankBilletPaymentsResponse, await res.json()) };