import {z} from 'zod' export type BankBilletPaymentObject = {id?: number | undefined, bank_billet_id: number | null, bank_billet_account_id: number | null, discharge_id?: (number | null) | undefined, amount?: number | undefined, paid_amount: number, paid_at: string | null, paid_bank?: (string | null) | undefined, paid_agency?: (string | null) | undefined, paid_agency_number?: (string | null) | undefined, paid_agency_digit?: (string | null) | undefined, bank_rate?: (number | null) | undefined, credit_at?: (string | null) | undefined, direct?: (boolean | null) | undefined, expire_at?: (string | null) | undefined, kind: 0 | 1 | 2, document_number?: (string | null) | undefined, our_number?: (string | null) | undefined, created_via_api?: (boolean | null) | undefined, created_at?: (string | null) | undefined, updated_at?: (string | null) | undefined, customer_person_name?: (string | null) | undefined, paid_by_pix?: (boolean | null) | undefined, financial_provider_external_id?: (string | null) | undefined, line_parsed?: (unknown | null) | undefined}; export type CreateApiV1BankBilletPaymentsArgs = {'User-Agent'?: string | undefined, 'X-Idempotency-Key'?: string | undefined, body: BankBilletPaymentObject}; export type CreateApiV1BankBilletPaymentsOptions = {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 }; /** * Efetuar Pagamento de Boleto * * POST /v1/bank_billet_payments */ export const createApiV1BankBilletPayments = async (args: CreateApiV1BankBilletPaymentsArgs, options?: CreateApiV1BankBilletPaymentsOptions) => { const {baseUrl = "https://api-sandbox.kobana.com.br", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['User-Agent'] != null) headers.set("User-Agent", String(args['User-Agent'])) if (args['X-Idempotency-Key'] != null) headers.set("X-Idempotency-Key", String(args['X-Idempotency-Key'])) 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: "POST", 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(bankBilletPaymentObject, await res.json()) };