import {z} from 'zod' export type GetApiPaymentCapturesArgs = {limit?: number | undefined, starting_after?: string | undefined, sort_order?: ('asc' | 'desc') | undefined, start_date?: string | undefined, end_date?: string | undefined, idempotency_key?: string | undefined, connected_account_id?: string | undefined, payment_reference?: string | undefined, remittance_reference?: string | undefined, start_value_date?: string | undefined, end_value_date?: string | undefined, transaction_reference?: string | undefined, amount_from?: number | undefined, amount_to?: number | undefined, original_payment_amount_from?: number | undefined, original_payment_amount_to?: number | undefined, currency?: string | undefined, canceled?: boolean | undefined, reconciliation_status?: ('unreconciled' | 'partially_reconciled' | 'reconciled' | 'excluded') | undefined, source?: ('api' | 'reporting_file') | undefined, merchant_id?: string | undefined, type?: ('charge' | 'chargeback' | 'refund') | undefined, network?: string | undefined}; export type GetApiPaymentCapturesOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const commonCbsTransaction = z.object({id: z.string().optional(), type: z.enum(["deposit", "withdrawal", "disbursement", "repayment", "adjustment"]).optional(), context: z.enum(["deposit", "suspense", "disbursement", "repayment"]).optional(), payment_validation_type: z.enum(["internal_account_is_active", "direct_debit_mandate_is_active", "liquidity_screening", "sanctions_screening", "risk_screening", "limits_screening", "mambu_authorization"]).optional(), account_id: z.string().optional(), authorization_id: z.string().optional(), external_id: z.string().optional(), channel: z.string().optional(), booked_at: z.string().optional()}); export const commonCbsData = z.object({transaction_id: z.string().optional(), authorization_id: z.string().optional(), transactions: z.array(commonCbsTransaction).optional()}); export const paymentCaptureDetails = z.object({id: z.string(), idempotency_key: z.string().optional(), object: z.literal("payment_capture"), connected_account_id: z.string(), transaction_reference: z.string().optional(), amount: z.number().int(), original_payment_amount: z.number().int().optional(), currency: z.string(), type: z.enum(["charge", "chargeback", "refund"]), authorization_id: z.string(), payment_reference: z.string(), date: z.string(), value_date: z.string(), network: z.enum(["visa", "mastercard", "cb", "american_express"]), remittance_reference: z.string(), remittance_date: z.string(), fee_amount: z.number().int(), fee_currency: z.string(), net_amount: z.number().int(), net_currency: z.string(), reconciled_amount: z.number().int().gte(0), reconciliation_status: z.enum(["unreconciled", "partially_reconciled", "reconciled", "excluded"]), source: z.enum(["api", "reporting_file"]), merchant_id: z.string().optional(), metadata: z.object({}), canceled_at: z.string().nullable(), created_at: z.string(), cbs_data: commonCbsData.optional()}); export const getApiPaymentCapturesResponse = z.object({records: z.array(paymentCaptureDetails)}); 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 payment captures * * GET /payment_captures */ export const getApiPaymentCaptures = async (args: GetApiPaymentCapturesArgs, options?: GetApiPaymentCapturesOptions) => { const {baseUrl = "https://sandbox.numeral.io/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.starting_after != null) query.append("starting_after", String(args.starting_after)) if (args.sort_order != null) query.append("sort_order", String(args.sort_order)) if (args.start_date != null) query.append("start_date", String(args.start_date)) if (args.end_date != null) query.append("end_date", String(args.end_date)) if (args.idempotency_key != null) query.append("idempotency_key", String(args.idempotency_key)) if (args.connected_account_id != null) query.append("connected_account_id", String(args.connected_account_id)) if (args.payment_reference != null) query.append("payment_reference", String(args.payment_reference)) if (args.remittance_reference != null) query.append("remittance_reference", String(args.remittance_reference)) if (args.start_value_date != null) query.append("start_value_date", String(args.start_value_date)) if (args.end_value_date != null) query.append("end_value_date", String(args.end_value_date)) if (args.transaction_reference != null) query.append("transaction_reference", String(args.transaction_reference)) if (args.amount_from != null) query.append("amount_from", String(args.amount_from)) if (args.amount_to != null) query.append("amount_to", String(args.amount_to)) if (args.original_payment_amount_from != null) query.append("original_payment_amount_from", String(args.original_payment_amount_from)) if (args.original_payment_amount_to != null) query.append("original_payment_amount_to", String(args.original_payment_amount_to)) if (args.currency != null) query.append("currency", String(args.currency)) if (args.canceled != null) query.append("canceled", String(args.canceled)) if (args.reconciliation_status != null) query.append("reconciliation_status", String(args.reconciliation_status)) if (args.source != null) query.append("source", String(args.source)) if (args.merchant_id != null) query.append("merchant_id", String(args.merchant_id)) if (args.type != null) query.append("type", String(args.type)) if (args.network != null) query.append("network", String(args.network)) if (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payment_captures${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(getApiPaymentCapturesResponse, await res.json()) };