export type GetApiChargesArgs = {'q[clientControlNumberEq]'?: string | undefined, 'q[documentNumberEq]'?: number | undefined, 'q[createdAtEq]'?: string | undefined, 'q[createdAtGteq]'?: string | undefined, 'q[createdAtLteq]'?: string | undefined, 'q[paidAtEq]'?: string | undefined, 'q[paidAtGt]'?: string | undefined, 'q[paidAtLt]'?: string | undefined, 'q[paidAtGteq]'?: string | undefined, 'q[paidAtLteq]'?: string | undefined, 'q[statusEq]'?: ('pending' | 'paid' | 'overpaid' | 'paid_externally') | undefined, 'q[paymentMethodEq]'?: ('boleto' | 'pix' | 'ted') | undefined, 'q[dueDateEq]'?: string | undefined, 'q[dueDateGt]'?: string | undefined, 'q[dueDateLt]'?: string | undefined, 'q[yourNumberEq]'?: string | undefined, 'q[receivedAtEq]'?: string | undefined, 'q[receivedAtGt]'?: string | undefined, 'q[receivedAtLt]'?: string | undefined, 'p[page]'?: number | undefined, 'p[per_page]'?: number | undefined}; export type GetApiChargesOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, sec1?: string | undefined, fetch?: typeof fetch | undefined}; /** * Listar cobranças * * GET /charges */ export const getApiCharges = async (args: GetApiChargesArgs, options?: GetApiChargesOptions) => { const {baseUrl = "https://pagamentos.grafeno.be/api/v2", fetch: fetchFn = fetch, sec0, sec1} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['q[clientControlNumberEq]'] != null) query.append("q[clientControlNumberEq]", String(args['q[clientControlNumberEq]'])) if (args['q[documentNumberEq]'] != null) query.append("q[documentNumberEq]", String(args['q[documentNumberEq]'])) if (args['q[createdAtEq]'] != null) query.append("q[createdAtEq]", String(args['q[createdAtEq]'])) if (args['q[createdAtGteq]'] != null) query.append("q[createdAtGteq]", String(args['q[createdAtGteq]'])) if (args['q[createdAtLteq]'] != null) query.append("q[createdAtLteq]", String(args['q[createdAtLteq]'])) if (args['q[paidAtEq]'] != null) query.append("q[paidAtEq]", String(args['q[paidAtEq]'])) if (args['q[paidAtGt]'] != null) query.append("q[paidAtGt]", String(args['q[paidAtGt]'])) if (args['q[paidAtLt]'] != null) query.append("q[paidAtLt]", String(args['q[paidAtLt]'])) if (args['q[paidAtGteq]'] != null) query.append("q[paidAtGteq]", String(args['q[paidAtGteq]'])) if (args['q[paidAtLteq]'] != null) query.append("q[paidAtLteq]", String(args['q[paidAtLteq]'])) if (args['q[statusEq]'] != null) query.append("q[statusEq]", String(args['q[statusEq]'])) if (args['q[paymentMethodEq]'] != null) query.append("q[paymentMethodEq]", String(args['q[paymentMethodEq]'])) if (args['q[dueDateEq]'] != null) query.append("q[dueDateEq]", String(args['q[dueDateEq]'])) if (args['q[dueDateGt]'] != null) query.append("q[dueDateGt]", String(args['q[dueDateGt]'])) if (args['q[dueDateLt]'] != null) query.append("q[dueDateLt]", String(args['q[dueDateLt]'])) if (args['q[yourNumberEq]'] != null) query.append("q[yourNumberEq]", String(args['q[yourNumberEq]'])) if (args['q[receivedAtEq]'] != null) query.append("q[receivedAtEq]", String(args['q[receivedAtEq]'])) if (args['q[receivedAtGt]'] != null) query.append("q[receivedAtGt]", String(args['q[receivedAtGt]'])) if (args['q[receivedAtLt]'] != null) query.append("q[receivedAtLt]", String(args['q[receivedAtLt]'])) if (args['p[page]'] != null) query.append("p[page]", String(args['p[page]'])) if (args['p[per_page]'] != null) query.append("p[per_page]", String(args['p[per_page]'])) if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) if (sec1 !== undefined) headers.set("Authorization", sec1) const url = `${baseUrl.replace(/\/+$/, '')}/charges${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 (await res.json()) as unknown };