import {z} from 'zod' export type GetApiV1PaymentsArgs = {'search.payment_id'?: Array | undefined, 'search.customer_id'?: Array | undefined, 'search.bill_id'?: Array | undefined, 'search.agent_id'?: Array | undefined, 'search.created_by'?: Array | undefined, 'search.source'?: (Array<'AGENT' | 'INHOUSE' | 'WEB' | 'LOCKBOX' | 'API' | 'AUTO_DEBIT' | 'IVR' | 'LOCKBOX_ACE' | 'LOCKBOX_BANK_OF_OKLAHOMA' | 'LOCKBOX_REGIONS' | 'LOCKBOX_REGIONS_RETAIL' | 'LOCKBOX_REGIONS_WHOLESALE' | 'CHECKFREE' | 'MONEYGRAM' | 'WACHOVIA' | 'WELLSFARGO' | 'WESTERNUNION' | 'US_PAYMENTS' | 'ORDER' | 'PSA'>) | undefined, 'search.method'?: Array | undefined, 'search.payment_type_id'?: Array | undefined, 'search.created_date_start'?: string | undefined, 'search.created_date_end'?: string | undefined, 'search.payment_account_id'?: Array | undefined, 'search.page_size'?: number | undefined, 'search.page'?: number | undefined, 'search.sort'?: string | undefined}; export type GetApiV1PaymentsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const revAppComponentsLink = z.object({rel: z.string().optional(), href: z.string().optional()}); export const revAppModelsPayment = z.object({payment_id: z.number().int().optional(), customer_id: z.number().int().optional(), bill_id: z.number().int().optional(), agent_id: z.number().int().optional(), reference_number: z.string().max(800).optional(), created_by: z.number().int().optional(), created_date: z.string().optional(), received_date: z.string().optional(), source: z.enum(["AGENT", "INHOUSE", "WEB", "LOCKBOX", "API", "AUTO_DEBIT", "IVR", "LOCKBOX_ACE", "LOCKBOX_BANK_OF_OKLAHOMA", "LOCKBOX_REGIONS", "LOCKBOX_REGIONS_RETAIL", "LOCKBOX_REGIONS_WHOLESALE", "CHECKFREE", "MONEYGRAM", "WACHOVIA", "WELLSFARGO", "WESTERNUNION", "US_PAYMENTS", "ORDER", "PSA"]).optional(), balance: z.number().optional(), payment_account_id: z.number().int().optional(), ebilling_profile_id: z.number().int().optional(), method: z.string().optional(), amount: z.number().optional(), refund_flag: z.boolean().optional(), payment_type_id: z.number().int().optional(), bounced: z.boolean().optional(), authorization_code: z.string().optional(), currency_code: z.enum(["USD", "AFN", "DZD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "THB", "PAB", "BBD", "BYN", "BZD", "BMD", "VEF", "BOB", "BRL", "BND", "BGN", "BIF", "CVE", "CAD", "KYD", "XOF", "XAF", "XPF", "CLP", "COP", "KMF", "CDF", "BAM", "NIO", "CRC", "CUP", "CZK", "GMD", "DKK", "MKD", "DJF", "STD", "DOP", "VND", "XCD", "EGP", "SVC", "ETB", "EUR", "FKP", "FJD", "HUF", "GHS", "GIP", "HTG", "PYG", "GNF", "GYD", "HKD", "UAH", "ISK", "INR", "IRR", "IQD", "JMD", "JOD", "KES", "PGK", "LAK", "HRK", "KWD", "AOA", "MMK", "GEL", "LBP", "ALL", "HNL", "SLL", "LRD", "LYD", "SZL", "LSL", "MGA", "MWK", "MYR", "MUR", "MXN", "MXV", "MDL", "MAD", "MZN", "BOV", "NGN", "ERN", "NAD", "NPR", "ANG", "ILS", "TWD", "NZD", "BTN", "KPW", "NOK", "MRO", "TOP", "PKR", "MOP", "CUC", "UYU", "PHP", "GBP", "BWP", "QAR", "GTQ", "ZAR", "OMR", "KHR", "RON", "MVR", "IDR", "RUB", "RWF", "SHP", "SAR", "RSD", "SCR", "SGD", "PEN", "SBD", "KGS", "SOS", "TJS", "SSP", "LKR", "SDG", "SRD", "SEK", "CHF", "SYP", "BDT", "WST", "TZS", "KZT", "TTD", "MNT", "TND", "TRY", "TMT", "AED", "UGX", "CLF", "COU", "UYI", "USN", "UZS", "VUV", "CHE", "CHW", "KRW", "YER", "JPY", "CNY", "ZMW", "ZWL", "PLN"]).optional(), note: z.string().optional(), links: z.array(revAppComponentsLink).optional()}); export const revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsPayment = z.object({ok: z.boolean().optional(), has_more: z.boolean().optional(), record_count: z.number().int().optional(), records: z.array(revAppModelsPayment).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 }; /** * Search payments * * GET /v1/Payments */ export const getApiV1Payments = async (args: GetApiV1PaymentsArgs, options?: GetApiV1PaymentsOptions) => { const {baseUrl = "https://restapi.rev.io", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args['search.payment_id'] ?? []) query.append("search.payment_id", String(item)) for (const item of args['search.customer_id'] ?? []) query.append("search.customer_id", String(item)) for (const item of args['search.bill_id'] ?? []) query.append("search.bill_id", String(item)) for (const item of args['search.agent_id'] ?? []) query.append("search.agent_id", String(item)) for (const item of args['search.created_by'] ?? []) query.append("search.created_by", String(item)) for (const item of args['search.source'] ?? []) query.append("search.source", String(item)) for (const item of args['search.method'] ?? []) query.append("search.method", String(item)) for (const item of args['search.payment_type_id'] ?? []) query.append("search.payment_type_id", String(item)) if (args['search.created_date_start'] != null) query.append("search.created_date_start", String(args['search.created_date_start'])) if (args['search.created_date_end'] != null) query.append("search.created_date_end", String(args['search.created_date_end'])) for (const item of args['search.payment_account_id'] ?? []) query.append("search.payment_account_id", String(item)) if (args['search.page_size'] != null) query.append("search.page_size", String(args['search.page_size'])) if (args['search.page'] != null) query.append("search.page", String(args['search.page'])) if (args['search.sort'] != null) query.append("search.sort", String(args['search.sort'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/Payments${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(revWebAPIModelsGetOrSearchOfRevAppSearchModelsResponseOfRevAppModelsPayment, await res.json()) };