import {z} from 'zod' export type SplitAccountsObject = {bank_number?: string | undefined, agency_number?: string | undefined, agency_digit?: string | undefined, account_number?: string | undefined, account_digit?: string | undefined, cnpj_cpf?: string | undefined, name?: string | undefined, amount?: unknown | undefined, floating?: number | undefined, financial_provider_external_id?: string | undefined}; export type BankBilletObject = {id?: number | undefined, bank_billet_account_id?: number | undefined, bank_billet_layout_id?: (number | null) | undefined, amount: number, expire_at: string, customer_id?: (number | null) | undefined, customer_person_name: string, customer_cnpj_cpf: string, customer_state: string, customer_city_name: string, customer_zipcode: string, customer_address: string, customer_address_complement?: string | undefined, customer_address_number?: string | undefined, customer_email?: string | undefined, customer_email_cc?: string | undefined, customer_neighborhood: string, customer_phone_number?: string | undefined, customer_ignore_email?: (boolean | null) | undefined, customer_ignore_sms?: (boolean | null) | undefined, customer_mobile_local_code?: (string | null) | undefined, customer_mobile_number?: (string | null) | undefined, customer_nickname?: (string | null) | undefined, customer_notes?: (string | null) | undefined, customer_contact_person?: (string | null) | undefined, interest_type?: (0 | 1 | 2 | 7 | null) | undefined, days_for_interest?: (number | null) | undefined, interest_percentage?: (number | null) | undefined, interest_value?: (number | null) | undefined, interest_days_type?: (0 | 1 | null) | undefined, fine_type?: (0 | 1 | 2 | null) | undefined, days_for_fine?: (number | null) | undefined, fine_percentage?: (number | null) | undefined, fine_value?: (number | null) | undefined, discount_type?: (0 | 1 | 2 | null) | undefined, days_for_discount?: (number | null) | undefined, discount_percentage?: (number | null) | undefined, discount_value?: (number | null) | undefined, days_for_second_discount?: (number | null) | undefined, second_discount_percentage?: (number | null) | undefined, second_discount_value?: (number | null) | undefined, days_for_third_discount?: (number | null) | undefined, third_discount_percentage?: (number | null) | undefined, third_discount_value?: (number | null) | undefined, tags?: (Array | null) | undefined, tag_list?: (string | null) | undefined, charge_type?: (1 | 2 | 3 | 4 | null) | undefined, dispatch_type?: (1 | 2 | null) | undefined, guarantor_name?: (string | null) | undefined, guarantor_cnpj_cpf?: (string | null) | undefined, guarantor_address_number?: (string | null) | undefined, guarantor_neighborhood?: (string | null) | undefined, guarantor_phone_number?: (string | null) | undefined, guarantor_city_name?: (string | null) | undefined, guarantor_state?: (string | null) | undefined, guarantor_zipcode?: (string | null) | undefined, guarantor_address?: (string | null) | undefined, guarantor_address_complement?: (string | null) | undefined, description?: (string | null) | undefined, instructions?: (string | null) | undefined, document_date?: (string | null) | undefined, document_type?: ('01' | '02' | '03' | '04' | '05' | '06' | '07' | '08' | '09' | '10' | '11' | '12' | '13' | '14' | '15' | '16' | '17' | '18' | '19' | '20' | '21' | '22' | '23' | '24' | '25' | '26' | '27' | '28' | '29' | '30' | '31' | '32' | '33' | '34' | '35' | '36' | '37' | '38' | '39' | '40' | '41' | '42' | '43' | '44' | '45' | '99') | undefined, document_type_label?: (string | null) | undefined, document_number?: (string | null) | undefined, acceptance?: ('N' | 'S') | undefined, our_number?: (string | null) | undefined, processed_our_number?: (string | null) | undefined, processed_our_number_raw?: (string | null) | undefined, paid_amount?: (number | null) | undefined, paid_at?: (string | null) | undefined, days_for_revoke?: (number | null) | undefined, credit_bureau?: ( | 0 | 1 | 2 | null) | undefined, days_for_negativation?: (number | null) | undefined, days_for_sue_type?: ( | 0 | 1 | null) | undefined, days_for_sue?: (number | null) | undefined, sue_history?: (Array<{status?: ('order_issued' | 'order_generated' | 'registry_sent' | 'protested' | 'order_cancelled' | 'withdrawal_requested' | 'registry_withdrawn' | 'registry_withdrawal_dispatched' | 'suspended' | 'cancellation_requested' | 'cancellation_released' | 'cancellation_sent' | 'cancelled') | undefined, occurred_at?: string | undefined}>) | undefined, sue_code?: (string | null) | undefined, revoke_code?: (string | null) | undefined, first_instruction?: (string | null) | undefined, second_instruction?: (string | null) | undefined, watermark?: boolean | undefined, payment_count?: (number | null) | undefined, divergent_payment_type?: ( | 1 | 2 | 3 | 4 | null) | undefined, divergent_payment_value_type?: ( | 1 | 2 | null) | undefined, divergent_payment_maximum_value?: (number | null) | undefined, divergent_payment_minimum_value?: (number | null) | undefined, divergent_payment_maximum_percentage?: (number | null) | undefined, divergent_payment_minimum_percentage?: (number | null) | undefined, divergent_payment_limit?: (number | null) | undefined, prevent_registration?: (boolean | null) | undefined, issued_at?: (string | null) | undefined, control_number?: (string | null) | undefined, ignore_email?: (boolean | null) | undefined, ignore_sms?: (boolean | null) | undefined, ignore_whatsapp?: (boolean | null) | undefined, addons?: (unknown | null) | undefined, custom_data?: (Record | null) | undefined, meta?: (Record | null) | undefined, notes?: (string | null) | undefined, custom_attachment_name?: (string | null) | undefined, split_payment?: (boolean | null) | undefined, split_payment_type?: (1 | 2 | 3 | 4 | null) | undefined, split_accounts?: (Array | null) | undefined, payment_place?: (string | null) | undefined, installment_id?: (number | null) | undefined, installment_number?: (number | null) | undefined, installment_total?: (number | null) | undefined, customer_subscription_id?: (number | null) | undefined, beneficiary_name?: string | undefined, beneficiary_cnpj_cpf?: string | undefined, beneficiary_address?: string | undefined, beneficiary_assignor_code?: (string | null) | undefined, bank_contract_slug?: (string | null) | undefined, agency_number?: string | undefined, agency_digit?: string | undefined, account_number?: string | undefined, account_digit?: string | undefined, extra1?: string | undefined, extra1_digit?: (string | null) | undefined, extra2?: (string | null) | undefined, extra2_digit?: (string | null) | undefined, created_via_api?: (boolean | null) | undefined, created_at?: (string | null) | undefined, updated_at?: (string | null) | undefined, registration_status?: ('pending' | 'skipped' | 'requested' | 'confirmed' | 'rejected' | 'failed') | undefined, registered_at?: (string | null) | undefined, register_type?: (1 | 2) | undefined, cancel_type?: ( | 1 | 2 | null) | undefined, cancellation_reason?: ( | 1 | 2 | 3 | 4 | 5 | null) | undefined, line?: (string | null) | undefined, barcode?: (string | null) | undefined, shorten_url?: (string | null) | undefined, url?: (string | null) | undefined, carne_url?: (string | null) | undefined, formats?: (Record | null) | undefined, pix_enabled?: (boolean | null) | undefined, pix_qrcode?: (string | null) | undefined, pix_txid?: (string | null) | undefined, prevent_pix?: (boolean | null) | undefined, status?: ('generating' | 'draft' | 'generation_failed' | 'validation_failed' | 'opened' | 'canceled' | 'paid' | 'overdue' | 'blocked' | 'chargeback') | undefined, recipient_account?: (string | null) | undefined, reduction_type?: (1 | 2 | 3 | null) | undefined, reduction_amount?: (number | null) | undefined, reduction_percentage?: (number | null) | undefined, instructions_mode?: (0 | 1 | 2 | null) | undefined, import_id?: (number | null) | undefined, virtual_bank_billet_id?: (number | null) | undefined, external_id?: (string | null) | undefined, financial_provider_external_id?: (string | null) | undefined, after_create?: (Array | null) | undefined}; export type CreateApiV1BankBilletsArgs = {'User-Agent'?: string | undefined, 'X-Idempotency-Key'?: string | undefined, body: BankBilletObject}; export type CreateApiV1BankBilletsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const splitAccountsObject = z.object({bank_number: z.string().max(3).optional(), agency_number: z.string().max(5).optional(), agency_digit: z.string().max(1).optional(), account_number: z.string().max(12).optional(), account_digit: z.string().max(1).optional(), cnpj_cpf: z.string().max(20).optional(), name: z.string().max(40).optional(), amount: z.string().optional(), floating: z.number().int().optional(), financial_provider_external_id: z.string().max(2).optional()}); export const bankBilletObject = z.object({id: z.number().int().optional(), bank_billet_account_id: z.number().int().optional(), bank_billet_layout_id: z.number().int().nullable().optional(), amount: z.number(), expire_at: z.string(), customer_id: z.number().int().nullable().optional(), customer_person_name: z.string().max(120), customer_cnpj_cpf: z.string().max(20), customer_state: z.string().max(2), customer_city_name: z.string().max(60), customer_zipcode: z.string().max(8), customer_address: z.string().max(255), customer_address_complement: z.string().max(120).optional(), customer_address_number: z.string().max(10).optional(), customer_email: z.string().max(80).optional(), customer_email_cc: z.string().max(80).optional(), customer_neighborhood: z.string().max(80), customer_phone_number: z.string().max(15).optional(), customer_ignore_email: z.boolean().nullable().optional(), customer_ignore_sms: z.boolean().nullable().optional(), customer_mobile_local_code: z.string().max(2).nullable().optional(), customer_mobile_number: z.string().max(9).nullable().optional(), customer_nickname: z.string().max(255).nullable().optional(), customer_notes: z.string().nullable().optional(), customer_contact_person: z.string().max(120).nullable().optional(), interest_type: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(7)]).nullable().optional(), days_for_interest: z.number().int().nullable().optional(), interest_percentage: z.number().nullable().optional(), interest_value: z.number().nullable().optional(), interest_days_type: z.union([z.literal(0), z.literal(1)]).nullable().optional(), fine_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_fine: z.number().int().nullable().optional(), fine_percentage: z.number().nullable().optional(), fine_value: z.number().nullable().optional(), discount_type: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_discount: z.number().int().nullable().optional(), discount_percentage: z.number().nullable().optional(), discount_value: z.number().nullable().optional(), days_for_second_discount: z.number().int().nullable().optional(), second_discount_percentage: z.number().nullable().optional(), second_discount_value: z.number().nullable().optional(), days_for_third_discount: z.number().int().nullable().optional(), third_discount_percentage: z.number().nullable().optional(), third_discount_value: z.number().nullable().optional(), tags: z.array(z.string()).nullable().optional(), tag_list: z.string().nullable().optional(), charge_type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).nullable().optional(), dispatch_type: z.union([z.literal(1), z.literal(2)]).nullable().optional(), guarantor_name: z.string().max(100).nullable().optional(), guarantor_cnpj_cpf: z.string().max(20).nullable().optional(), guarantor_address_number: z.string().max(10).nullable().optional(), guarantor_neighborhood: z.string().max(80).nullable().optional(), guarantor_phone_number: z.string().max(11).nullable().optional(), guarantor_city_name: z.string().max(60).nullable().optional(), guarantor_state: z.string().max(2).nullable().optional(), guarantor_zipcode: z.string().max(8).nullable().optional(), guarantor_address: z.string().max(255).nullable().optional(), guarantor_address_complement: z.string().max(60).nullable().optional(), description: z.string().nullable().optional(), instructions: z.string().nullable().optional(), document_date: z.string().nullable().optional(), document_type: z.enum(["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "99"]).max(2).optional(), document_type_label: z.string().nullable().optional(), document_number: z.string().nullable().optional(), acceptance: z.enum(["N", "S"]).optional(), our_number: z.string().nullable().optional(), processed_our_number: z.string().nullable().optional(), processed_our_number_raw: z.string().nullable().optional(), paid_amount: z.number().nullable().optional(), paid_at: z.string().nullable().optional(), days_for_revoke: z.number().int().nullable().optional(), credit_bureau: z.union([z.literal(null), z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), days_for_negativation: z.number().int().nullable().optional(), days_for_sue_type: z.union([z.literal(null), z.literal(0), z.literal(1)]).nullable().optional(), days_for_sue: z.number().int().nullable().optional(), sue_history: z.array(z.object({status: z.enum(["order_issued", "order_generated", "registry_sent", "protested", "order_cancelled", "withdrawal_requested", "registry_withdrawn", "registry_withdrawal_dispatched", "suspended", "cancellation_requested", "cancellation_released", "cancellation_sent", "cancelled"]).optional(), occurred_at: z.string().optional()})).optional(), sue_code: z.string().max(2).nullable().optional(), revoke_code: z.string().nullable().optional(), first_instruction: z.string().max(2).nullable().optional(), second_instruction: z.string().max(2).nullable().optional(), watermark: z.boolean().optional(), payment_count: z.number().int().nullable().optional(), divergent_payment_type: z.union([z.literal(null), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).nullable().optional(), divergent_payment_value_type: z.union([z.literal(null), z.literal(1), z.literal(2)]).nullable().optional(), divergent_payment_maximum_value: z.number().nullable().optional(), divergent_payment_minimum_value: z.number().nullable().optional(), divergent_payment_maximum_percentage: z.number().nullable().optional(), divergent_payment_minimum_percentage: z.number().nullable().optional(), divergent_payment_limit: z.number().int().nullable().optional(), prevent_registration: z.boolean().nullable().optional(), issued_at: z.string().nullable().optional(), control_number: z.string().max(25).nullable().optional(), ignore_email: z.boolean().nullable().optional(), ignore_sms: z.boolean().nullable().optional(), ignore_whatsapp: z.boolean().nullable().optional(), addons: z.string().nullable().optional(), custom_data: z.object({}).nullable().optional(), meta: z.object({}).nullable().optional(), notes: z.string().nullable().optional(), custom_attachment_name: z.string().nullable().optional(), split_payment: z.boolean().nullable().optional(), split_payment_type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).nullable().optional(), split_accounts: z.array(splitAccountsObject).nullable().optional(), payment_place: z.string().max(100).nullable().optional(), installment_id: z.number().int().nullable().optional(), installment_number: z.number().int().nullable().optional(), installment_total: z.number().int().nullable().optional(), customer_subscription_id: z.number().int().nullable().optional(), beneficiary_name: z.string().optional(), beneficiary_cnpj_cpf: z.string().optional(), beneficiary_address: z.string().optional(), beneficiary_assignor_code: z.string().nullable().optional(), bank_contract_slug: z.string().nullable().optional(), agency_number: z.string().optional(), agency_digit: z.string().optional(), account_number: z.string().optional(), account_digit: z.string().optional(), extra1: z.string().optional(), extra1_digit: z.string().nullable().optional(), extra2: z.string().nullable().optional(), extra2_digit: z.string().nullable().optional(), created_via_api: z.boolean().nullable().optional(), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional(), registration_status: z.enum(["pending", "skipped", "requested", "confirmed", "rejected", "failed"]).optional(), registered_at: z.string().nullable().optional(), register_type: z.union([z.literal(1), z.literal(2)]).optional(), cancel_type: z.union([z.literal(null), z.literal(1), z.literal(2)]).nullable().optional(), cancellation_reason: z.union([z.literal(null), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).nullable().optional(), line: z.string().nullable().optional(), barcode: z.string().nullable().optional(), shorten_url: z.string().nullable().optional(), url: z.string().nullable().optional(), carne_url: z.string().nullable().optional(), formats: z.object({}).nullable().optional(), pix_enabled: z.boolean().nullable().optional(), pix_qrcode: z.string().nullable().optional(), pix_txid: z.string().nullable().optional(), prevent_pix: z.boolean().nullable().optional(), status: z.enum(["generating", "draft", "generation_failed", "validation_failed", "opened", "canceled", "paid", "overdue", "blocked", "chargeback"]).optional(), recipient_account: z.string().max(10).nullable().optional(), reduction_type: z.union([z.literal(1), z.literal(2), z.literal(3)]).nullable().optional(), reduction_amount: z.number().nullable().optional(), reduction_percentage: z.number().nullable().optional(), instructions_mode: z.union([z.literal(0), z.literal(1), z.literal(2)]).nullable().optional(), import_id: z.number().int().nullable().optional(), virtual_bank_billet_id: z.number().int().nullable().optional(), external_id: z.string().nullable().optional(), financial_provider_external_id: z.string().nullable().optional(), after_create: z.array(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 }; /** * Criar um Boleto * * POST /v1/bank_billets */ export const createApiV1BankBillets = async (args: CreateApiV1BankBilletsArgs, options?: CreateApiV1BankBilletsOptions) => { 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_billets${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(bankBilletObject, await res.json()) };