import {z} from 'zod' export type GetApiV1VaTransferIdArgs = {id: string}; export type GetApiV1VaTransferIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const publicTransferBeneficiaryDto = z.object({id: z.string(), accountName: z.string(), accountNumber: z.string(), bankCode: z.string(), bankName: z.string(), providerId: z.string().optional(), description: z.string().optional(), isActive: z.boolean(), mode: z.enum(["test", "live"]), createdAt: z.string(), updatedAt: z.string()}); export const publicTransferTransactionMetaDto = z.object({amount: z.number(), symbol: z.string(), currency: z.string(), fxRate: z.number().nullable().optional(), settlementAmount: z.number().nullable().optional(), settlementCurrency: z.string().nullable().optional(), settlementSymbol: z.string().nullable().optional()}); export const publicTransferFeeBreakdownDto = z.object({fee: z.number(), vat: z.number(), processorFee: z.number(), allInclusiveKyshiFee: z.number(), totalFees: z.number(), others: z.record(z.string(), z.number())}); export const publicTransferTransactionDto = z.object({id: z.string(), amount: z.number(), type: z.enum(["DR", "CR"]), channel: z.string().optional(), processor: z.enum(["PROVIDUS_BANK", "STERLING", "VFD", "PAYSTACK", "FLUTTERWAVE", "CHOICE", "STITCH", "PAGA", "STRIPE", "ASSET_MFB", "MOMENTPAY", "PAWAPAY"]), feeBearer: z.enum(["MERCHANT", "CUSTOMER"]), balanceBefore: z.number(), balanceAfter: z.number(), netAmount: z.number(), meta: publicTransferTransactionMetaDto, feeBreakdown: publicTransferFeeBreakdownDto, status: z.enum(["PENDING", "SUCCESS", "IN_REVIEW", "FAILED", "REVERSAL", "COLLECTED"]), currency: z.string(), reference: z.string(), paymentType: z.string(), createdAt: z.string(), updatedAt: z.string()}); export const getApiV1VaTransferIdResponse = z.object({status: z.boolean(), message: z.string(), code: z.number(), data: z.object({id: z.string(), code: z.string(), status: z.enum(["PENDING_APPROVAL", "APPROVED"]), mode: z.enum(["test", "live"]), beneficiary: publicTransferBeneficiaryDto, transaction: publicTransferTransactionDto, createdAt: z.string(), updatedAt: z.string(), approvedAt: z.string().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 a VA transfer * * GET /v1/va/transfer/{id} */ export const getApiV1VaTransferId = async (args: GetApiV1VaTransferIdArgs, options?: GetApiV1VaTransferIdOptions) => { const {baseUrl = "https://api.kyshi.co", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("x-api-key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/va/transfer/${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(getApiV1VaTransferIdResponse, await res.json()) };