import {z} from 'zod' export type CreatePaymentInstrumentVerificationPushToCard = {processor: 'DUMMY_V1' | 'FINIX_V1'}; export type CreateApiPaymentInstrumentsPaymentInstrumentIdVerifyVerificationsArgs = {body: CreatePaymentInstrumentVerificationPushToCard}; export type CreateApiPaymentInstrumentsPaymentInstrumentIdVerifyVerificationsOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const applicationId = z.string().min(1); export const raw = z.union([z.object({}).nullable(), z.string().nullable()]); export const tags = z.record(z.string(), z.unknown()).nullable(); export const paymentInstrumentVerification = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), application: applicationId.optional(), identity: z.string().nullable().optional(), merchant: z.string().nullable().optional(), merchant_identity: z.string().nullable().optional(), messages: z.array(z.string()).optional(), outcome_summary: z.string().nullable().optional(), outcomes: z.array(z.object({})).nullable().optional(), payment_instrument: z.string().optional(), payment_instrument_verification_details: z.object({pull_from_card_cross_border: z.enum(["FAST_FUNDS", "NON_FAST_FUNDS", "NOT_SUPPORTED", "UNKNOWN"]).nullable().optional(), pull_from_card_domestic: z.enum(["FAST_FUNDS", "NON_FAST_FUNDS", "NOT_SUPPORTED", "UNKNOWN"]).nullable().optional(), push_to_card_domestic: z.enum(["FAST_FUNDS", "NON_FAST_FUNDS", "NOT_SUPPORTED", "UNKNOWN"]).nullable().optional(), push_to_card_cross_border: z.enum(["FAST_FUNDS", "NON_FAST_FUNDS", "NOT_SUPPORTED", "UNKNOWN"]).nullable().optional(), card_type: z.enum(["CREDIT", "DEBIT", "HSA_FSA", "RELOADABLE_PREPAID", "UNRELOADABLE_PREPAID", "UNKNOWN"]).nullable().optional(), billing_currency: z.string().nullable().optional(), issuer_country: z.enum(["NON_USA", "USA", "UNKNOWN"]).nullable().optional(), name_verification_results: z.object({first_name: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), last_name: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), middle_name: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), name: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), first_name_verification: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), last_name_verification: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), middle_name_verification: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional(), name_verification: z.enum(["MATCH", "MATCHED", "NO_MATCH", "NOT_SUPPORTED", "PARTIAL_MATCH", "UNKNOWN"]).optional()}).nullable().optional()}).optional(), processor: z.enum(["FINIX_V1", "DUMMY_V1"]).optional(), raw: raw.optional(), reverification_reason: z.object({initiated_by: z.string().nullable().optional(), reason_description: z.string().nullable().optional(), review_type: z.string().nullable().optional()}).nullable().optional(), state: z.enum(["PENDING", "FAILED", "SUCCEEDED"]).optional(), sub_type: z.string().nullable().optional(), tags: tags.optional(), trace_id: z.string().optional(), type: z.literal("PAYMENT_INSTRUMENT").optional(), _links: z.object({self: z.object({href: z.string().optional()}).optional(), application: z.object({href: z.string().optional()}).optional(), payment_instrument: z.object({href: z.string().min(1).optional()}).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 }; /** * Verify Push-to-Card Eligibility * * POST /payment_instruments/{payment_instrument_id_verify}/verifications */ export const createApiPaymentInstrumentsPaymentInstrumentIdVerifyVerifications = async (args: CreateApiPaymentInstrumentsPaymentInstrumentIdVerifyVerificationsArgs, options?: CreateApiPaymentInstrumentsPaymentInstrumentIdVerifyVerificationsOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/payment_instruments/${encodeURIComponent(String(args.payment_instrument_id_verify))}/verifications${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paymentInstrumentVerification, await res.json()) };