import {z} from 'zod' export type GetApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryArgs = {payment_instrument_id: string, 'Finix-Version'?: string | undefined, after_cursor?: string | undefined, before_cursor?: string | undefined, limit?: number | undefined}; export type GetApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const page = z.object({limit: z.number().int().optional(), next_cursor: z.string().nullable().optional()}); export const createdAt = z.string(); export const instrumentHistoryEntry = z.object({id: z.string().optional(), created_at: createdAt.optional(), type: z.enum(["CONTACT_CARDHOLDER", "FRAUD_REPORTED", "NOT_FOUND", "NUMBER_AND_EXPIRATION_UPDATED", "NUMBER_UPDATED"]).optional(), application_id: z.string().optional(), payment_instrument_id: z.string().optional(), payment_instrument_type: z.literal("PAYMENT_CARD").optional(), old_instrument_details: z.object({bin: z.string().optional(), brand: z.enum(["UNKNOWN", "DINERS_CLUB_INTERNATIONAL", "DANKORT", "MIR", "TROY", "UATP", "CHINA_T_UNION", "CHINA_UNION_PAY", "AMERICAN_EXPRESS", "VERVE", "RUPAY", "DISCOVER", "JCB", "MASTERCARD", "INTERPAYMENT", "INSTAPAYMENT", "MAESTRO", "VISA", "LANKAPAY", "DINERS_CLUB", "INTERAC"]).optional(), expiration_month: z.number().int().optional(), expiration_year: z.number().int().optional(), last_four: z.string().optional(), fingerprint: z.string().optional()}).optional(), new_instrument_details: z.object({bin: z.string().optional(), brand: z.enum(["UNKNOWN", "DINERS_CLUB_INTERNATIONAL", "DANKORT", "MIR", "TROY", "UATP", "CHINA_T_UNION", "CHINA_UNION_PAY", "AMERICAN_EXPRESS", "VERVE", "RUPAY", "DISCOVER", "JCB", "MASTERCARD", "INTERPAYMENT", "INSTAPAYMENT", "MAESTRO", "VISA", "LANKAPAY", "DINERS_CLUB", "INTERAC"]).optional(), expiration_month: z.number().int().optional(), expiration_year: z.number().int().optional(), last_four: z.string().optional(), fingerprint: z.string().optional()}).optional(), _links: z.object({self: z.object({href: z.string().optional()}).optional()}).optional()}); export const self = z.object({href: z.string().min(1).optional()}); export const next = z.object({href: z.string().optional()}); export const getApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryResponse = z.object({page: page.optional(), _embedded: z.object({instrument_history_entries: z.array(instrumentHistoryEntry).optional()}).optional(), _links: z.object({self: self.optional(), next: next.optional()}).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 }; /** * List Instrument History Entries * * GET /payment_instruments/{payment_instrument_id}/instrument_history */ export const getApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistory = async (args: GetApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryArgs, options?: GetApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Finix-Version'] != null) headers.set("Finix-Version", String(args['Finix-Version'])) if (args.after_cursor != null) query.append("after_cursor", String(args.after_cursor)) if (args.before_cursor != null) query.append("before_cursor", String(args.before_cursor)) if (args.limit != null) query.append("limit", String(args.limit)) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payment_instruments/${encodeURIComponent(String(args.payment_instrument_id))}/instrument_history${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(getApiPaymentInstrumentsPaymentInstrumentIdInstrumentHistoryResponse, await res.json()) };