import {z} from 'zod' export type GetApiApiV1SendMoneyTransactionsArgs = {account?: string | undefined, amount?: number | undefined, category?: number | undefined, created_at_after?: string | undefined, created_at_before?: string | undefined, narrative?: string | undefined, page?: number | undefined, processor__transaction_id?: string | undefined, provider?: ('AIRTIME' | 'INTASEND' | 'INTASEND-XB' | 'INTASEND-XB-BANK' | 'MPESA-B2B' | 'MPESA-B2C' | 'PESALINK' | 'RTGS') | undefined, record_id?: string | undefined, state?: ('CANCELLED' | 'INITIATED' | 'INITIATION-FAILED' | 'OBSERVATION' | 'PAYERROR' | 'PAYSUCCESS' | 'PENDING' | 'PROCESSING-RESULTS' | 'RESULT-FAILED' | 'RETRY') | undefined, wallet_id?: string | undefined}; export type GetApiApiV1SendMoneyTransactionsOptions = {baseUrl?: string | undefined, IntaSendBearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const accountTypeAa8Enum = z.enum(["TillNumber", "PayBill"]); export const blankEnum = z.literal(""); export const nullEnum = z.unknown(); export const transactionsResultSer = z.object({transaction_id: z.string(), status: z.string(), status_code: z.string(), request_reference_id: z.string().optional(), provider: z.string(), bank_code: z.union([z.enum(["1", "2", "3", "6", "7", "10", "11", "12", "14", "16", "17", "18", "19", "23", "25", "31", "32", "35", "36", "43", "48", "49", "50", "51", "53", "54", "55", "57", "60", "61", "63", "65", "66", "68", "70", "72", "74", "75", "76", "78", "79", "89", "97", "FINANCE_TRUST_BANK_UGANDA_TRANSFER", "EXIM_BANK_UGANDA_TRANSFER", "BANK_OF_INDIA_UGANDA_TRANSFER", "CENTENARY_RURAL_DEVELOPMENT_BANK_UGANDA_TRANSFER", "BANK_OF_BARODA_UGANDA_TRANSFER", "BANK_OF_AFRICA_UGANDA_TRANSFER", "CITIBANK_UGANDA_TRANSFER", "ABSA_BANK_UGANDA_TRANSFER", "GUARANTY_TRUST_BANK_UGANDA_TRANSFER", "KCB_BANK_UGANDA_TRANSFER", "ABC_CAPITAL_BANK_UGANDA_TRANSFER", "EQUITY_BANK_UGANDA_TRANSFER", "HOUSING_FINANCE_BANK_UGANDA_TRANSFER", "CAIRO_INTERNATIONAL_BANK_UGANDA_TRANSFER", "NCBA_BANK_UGANDA_TRANSFER", "ORIENT_BANK_UGANDA_TRANSFER", "ECOBANK_UGANDA_TRANSFER", "UNITED_BANK_FOR_AFRICA_TRANSFER", "DFCU_BANK_UGANDA_TRANSFER", "POSTBANK_UGANDA_TRANSFER", "DIAMOND_TRUST_BANK_UGANDA_TRANSFER", "OPPORTUNITY_BANK_UGANDA_TRANSFER", "STANBIC_BANK_UGANDA_TRANSFER", "TOP_FINANCE_BANK_UGANDA_TRANSFER", "TROPICAL_BANK_UGANDA_TRANSFER", "STANDARD_CHARTERED_BANK_UGANDA_TRANSFER"]), z.literal(""), z.unknown()]).nullable().optional(), name: z.string().max(240).nullable().optional(), account: z.string().max(24), account_type: z.union([accountTypeAa8Enum, blankEnum, nullEnum]).nullable().optional(), account_reference: z.string().max(20).nullable().optional(), provider_reference: z.string(), provider_account_name: z.string(), amount: z.string(), charge: z.string(), narrative: z.string().max(240).nullable().optional(), file_id: z.string(), currency: z.string(), created_at: z.string().nullable(), updated_at: z.string().nullable()}); export const paginatedTransactionsResultSerList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(transactionsResultSer)}); 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 }; /** * List Send money transactions * * GET /api/v1/send-money/transactions/ */ export const getApiApiV1SendMoneyTransactions = async (args: GetApiApiV1SendMoneyTransactionsArgs, options?: GetApiApiV1SendMoneyTransactionsOptions) => { const {baseUrl = "https://api.intasend.com", fetch: fetchFn = fetch, IntaSendBearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.account != null) query.append("account", String(args.account)) if (args.amount != null) query.append("amount", String(args.amount)) if (args.category != null) query.append("category", String(args.category)) if (args.created_at_after != null) query.append("created_at_after", String(args.created_at_after)) if (args.created_at_before != null) query.append("created_at_before", String(args.created_at_before)) if (args.narrative != null) query.append("narrative", String(args.narrative)) if (args.page != null) query.append("page", String(args.page)) if (args.processor__transaction_id != null) query.append("processor__transaction_id", String(args.processor__transaction_id)) if (args.provider != null) query.append("provider", String(args.provider)) if (args.record_id != null) query.append("record_id", String(args.record_id)) if (args.state != null) query.append("state", String(args.state)) if (args.wallet_id != null) query.append("wallet_id", String(args.wallet_id)) if (IntaSendBearerAuth !== undefined) headers.set('authorization', `Bearer ${IntaSendBearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/send-money/transactions/${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(paginatedTransactionsResultSerList, await res.json()) };