import {z} from 'zod' export type GetApiPaymentCapturesIdArgs = {id: string}; export type GetApiPaymentCapturesIdOptions = {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 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 }; /** * Retrieve payment capture * * GET /payment_captures/{id} */ export const getApiPaymentCapturesId = async (args: GetApiPaymentCapturesIdArgs, options?: GetApiPaymentCapturesIdOptions) => { 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 (sec0 !== undefined) headers.set("x-api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/payment_captures/${encodeURIComponent(String(args.id))}${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(paymentCaptureDetails, await res.json()) };