import {z} from 'zod' export type StatementDescriptor = string | null; export type OnboardingData = {additional_underwriting_data?: ({annual_ach_volume?: number | undefined, average_ach_transfer_amount?: number | undefined, average_card_transfer_amount?: number | undefined, business_description?: string | undefined, card_volume_distribution?: ({card_present_percentage?: number | undefined, ecommerce_percentage?: number | undefined, mail_order_telephone_order_percentage?: number | undefined} | null) | undefined, credit_check_timestamp?: (string | null) | undefined, credit_check_user_agent?: (string | null) | undefined, merchant_agreement_accepted?: boolean | undefined, merchant_agreement_ip_address?: string | undefined, merchant_agreement_timestamp?: string | undefined, merchant_agreement_user_agent?: string | undefined, refund_policy?: ('NO_REFUNDS' | 'MERCHANDISE_EXCHANGE_ONLY' | 'WITHIN_30_DAYS' | 'OTHER') | undefined, volume_distribution_by_business_type?: ({business_to_business_volume_percentage?: number | undefined, business_to_consumer_volume_percentage?: number | undefined, consumer_to_consumer_volume_percentage?: number | undefined, other_volume_percentage?: number | undefined, person_to_person_volume_percentage?: number | undefined} | null) | undefined, amex_marketing_consent?: ({accepted?: boolean | undefined, ip_address?: string | undefined, user_agent?: string | undefined, timestamp?: string | undefined} | null) | undefined}) | undefined, associated_entities?: (Array<{annual_card_volume?: (number | string) | undefined, business_address?: ({city?: string | undefined, country?: string | undefined, line2?: string | undefined, line1?: string | undefined, postal_code?: string | undefined, region?: string | undefined} | null) | undefined, business_name?: (string | null) | undefined, business_phone?: string | undefined, business_tax_id?: string | undefined, business_type?: ('INDIVIDUAL_SOLE_PROPRIETORSHIP' | 'CORPORATION' | 'LIMITED_LIABILITY_COMPANY' | 'PARTNERSHIP' | 'ASSOCIATION_ESTATE_TRUST' | 'TAX_EXEMPT_ORGANIZATION' | 'GOVERNMENT_AGENCY') | undefined, default_statement_descriptor?: StatementDescriptor | undefined, dob?: ({day?: number | undefined, month?: number | undefined, year?: number | undefined}) | undefined, doing_business_as?: string | undefined, email?: string | undefined, first_name?: string | undefined, has_accepted_credit_cards_previously?: boolean | undefined, incorporation_date?: ({day?: number | undefined, month?: number | undefined, year?: number | undefined} | null) | undefined, last_name?: string | undefined, max_transaction_amount?: number | undefined, mcc?: string | undefined, ownership_type?: (string | null) | undefined, personal_address?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, region?: string | undefined}) | undefined, phone?: string | undefined, principal_percentage_ownership?: number | undefined, tax_id?: string | undefined, title?: string | undefined, url?: string | undefined}>) | undefined, country?: ('USA' | 'CAN') | undefined, entity?: ({amex_mid?: (number | null) | undefined, annual_card_volume?: (number | string | null) | undefined, business_address?: ({line1?: (string | null) | undefined, line2?: (string | null) | undefined, city?: (string | null) | undefined, region?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined} | null) | undefined, business_name?: (string | null) | undefined, business_phone?: (string | null) | undefined, business_tax_id_provided?: boolean | undefined, business_type?: ('INDIVIDUAL_SOLE_PROPRIETORSHIP' | 'CORPORATION' | 'LIMITED_LIABILITY_COMPANY' | 'PARTNERSHIP' | 'LIMITED_PARTNERSHIP' | 'GENERAL_PARTNERSHIP' | 'ASSOCIATION_ESTATE_TRUST' | 'TAX_EXEMPT_ORGANIZATION' | 'GOVERNMENT_AGENCY' | null) | undefined, default_statement_descriptor?: StatementDescriptor | undefined, discover_mid?: (number | null) | undefined, dob?: ({day?: number | undefined, month?: number | undefined, year?: number | undefined} | null) | undefined, doing_business_as?: (string | null) | undefined, email?: (string | null) | undefined, first_name?: (string | null) | undefined, has_accepted_credit_cards_previously?: boolean | undefined, incorporation_date?: ({day?: number | undefined, month?: number | undefined, year?: number | undefined} | null) | undefined, last_name?: (string | null) | undefined, mcc?: (string | null) | undefined, ownership_type?: ('PUBLIC' | 'PRIVATE' | null) | undefined, personal_address?: ({line1?: (string | null) | undefined, line2?: (string | null) | undefined, city?: (string | null) | undefined, region?: (string | null) | undefined, postal_code?: (string | null) | undefined, country?: (string | null) | undefined} | null) | undefined, phone?: (string | null) | undefined, principal_percentage_ownership?: (number | string | null) | undefined, short_business_name?: (string | null) | undefined, tax_authority?: (string | null) | undefined, tax_id?: (string | null) | undefined, tax_id_provided?: boolean | undefined, business_tax_id?: (string | null) | undefined, title?: (string | null) | undefined, url?: (string | null) | undefined}) | undefined, payment_instruments?: ({account_number?: string | undefined, account_type?: string | undefined, attempt_bank_account_validation_check?: ('CHECKING' | 'SAVINGS' | 'PERSONAL_CHECKING' | 'PERSONAL_SAVINGS' | 'BUSINESS_CHECKING' | 'BUSINESS_SAVINGS' | 'CORPORATE' | 'CORP_SAVINGS') | undefined, bank_code?: string | undefined, name?: string | undefined, type?: 'BANK_ACCOUNT' | undefined, country?: string | undefined, currency?: string | undefined}) | undefined, max_transaction_amount: number, ach_max_transaction_amount?: number | undefined, associated_files?: (Array<{type?: string | undefined, name?: string | undefined, id?: string | undefined, related_to?: string | undefined}>) | undefined}; export type OnboardingLinkDetails = {expiration_in_minutes?: number | undefined, expired_session_url: string, fee_details_url: string, merchant_max_transaction_amount?: number | undefined, merchant_ach_max_transaction_amount?: number | undefined, return_url: string, terms_of_service_url: string}; export type Tags = {[key: string]: unknown} | null; export type CreateOnboardingFormUSAMinimal = {merchant_processors: Array<{processor: string}>, onboarding_data: OnboardingData, onboarding_link_details: OnboardingLinkDetails, tags?: Tags | undefined}; export type CreateOnboardingFormUSAAllFields = {merchant_processors: Array<{processor: string}>, onboarding_data: OnboardingData, onboarding_link_details: OnboardingLinkDetails, tags?: Tags | undefined}; export type CreateOnboardingFormCANMinimal = {merchant_processors: Array<{processor: string}>, onboarding_data: OnboardingData, onboarding_link_details: OnboardingLinkDetails, tags?: Tags | undefined}; export type CreateOnboardingFormCANAllFields = {merchant_processors: Array<{processor: string}>, onboarding_data: OnboardingData, onboarding_link_details: OnboardingLinkDetails, tags?: Tags | undefined}; export type CreateApiOnboardingFormsArgs = {'Finix-Version'?: string | undefined, 'Content-Type'?: string | undefined, body: CreateOnboardingFormUSAMinimal | CreateOnboardingFormUSAAllFields | CreateOnboardingFormCANMinimal | CreateOnboardingFormCANAllFields}; export type CreateApiOnboardingFormsOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string().min(1); export const statementDescriptor = z.string().max(20).nullable(); export const onboardingData = z.object({additional_underwriting_data: z.object({annual_ach_volume: z.number().int().optional(), average_ach_transfer_amount: z.number().int().optional(), average_card_transfer_amount: z.number().int().optional(), business_description: z.string().min(1).optional(), card_volume_distribution: z.object({card_present_percentage: z.number().int().optional(), ecommerce_percentage: z.number().int().optional(), mail_order_telephone_order_percentage: z.number().int().optional()}).nullable().optional(), credit_check_timestamp: z.string().min(1).nullable().optional(), credit_check_user_agent: z.string().min(1).nullable().optional(), merchant_agreement_accepted: z.boolean().optional(), merchant_agreement_ip_address: z.string().min(1).optional(), merchant_agreement_timestamp: z.string().min(1).optional(), merchant_agreement_user_agent: z.string().min(1).optional(), refund_policy: z.enum(["NO_REFUNDS", "MERCHANDISE_EXCHANGE_ONLY", "WITHIN_30_DAYS", "OTHER"]).min(1).optional(), volume_distribution_by_business_type: z.object({business_to_business_volume_percentage: z.number().int().optional(), business_to_consumer_volume_percentage: z.number().int().optional(), consumer_to_consumer_volume_percentage: z.number().int().optional(), other_volume_percentage: z.number().int().optional(), person_to_person_volume_percentage: z.number().int().optional()}).nullable().optional(), amex_marketing_consent: z.object({accepted: z.boolean().optional(), ip_address: z.string().optional(), user_agent: z.string().optional(), timestamp: z.string().optional()}).nullable().optional()}).optional(), associated_entities: z.array(z.object({annual_card_volume: z.union([z.number().int(), z.string()]).optional(), business_address: z.object({city: z.string().min(1).optional(), country: z.string().min(1).optional(), line2: z.string().min(1).optional(), line1: z.string().min(1).optional(), postal_code: z.string().min(1).optional(), region: z.string().min(1).optional()}).nullable().optional(), business_name: z.string().min(1).nullable().optional(), business_phone: z.string().min(1).optional(), business_tax_id: z.string().min(1).optional(), business_type: z.enum(["INDIVIDUAL_SOLE_PROPRIETORSHIP", "CORPORATION", "LIMITED_LIABILITY_COMPANY", "PARTNERSHIP", "ASSOCIATION_ESTATE_TRUST", "TAX_EXEMPT_ORGANIZATION", "GOVERNMENT_AGENCY"]).min(1).optional(), default_statement_descriptor: statementDescriptor.optional(), dob: z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}).optional(), doing_business_as: z.string().min(1).optional(), email: z.string().min(1).optional(), first_name: z.string().min(1).optional(), has_accepted_credit_cards_previously: z.boolean().optional(), incorporation_date: z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}).nullable().optional(), last_name: z.string().min(1).optional(), max_transaction_amount: z.number().int().optional(), mcc: z.string().min(1).optional(), ownership_type: z.string().min(1).nullable().optional(), personal_address: z.object({city: z.string().min(1).optional(), country: z.string().min(1).optional(), line1: z.string().min(1).optional(), line2: z.string().min(1).optional(), postal_code: z.string().min(1).optional(), region: z.string().min(1).optional()}).optional(), phone: z.string().min(1).optional(), principal_percentage_ownership: z.number().int().optional(), tax_id: z.string().min(1).optional(), title: z.string().min(1).optional(), url: z.string().min(1).optional()})).optional(), country: z.enum(["USA", "CAN"]).optional(), entity: z.object({amex_mid: z.number().int().nullable().optional(), annual_card_volume: z.union([z.number().int(), z.string()]).nullable().optional(), business_address: z.object({line1: z.string().min(1).nullable().optional(), line2: z.string().min(1).nullable().optional(), city: z.string().min(1).nullable().optional(), region: z.string().min(1).nullable().optional(), postal_code: z.string().min(1).nullable().optional(), country: z.string().min(1).nullable().optional()}).nullable().optional(), business_name: z.string().min(1).nullable().optional(), business_phone: z.string().min(1).nullable().optional(), business_tax_id_provided: z.boolean().optional(), business_type: z.enum(["INDIVIDUAL_SOLE_PROPRIETORSHIP", "CORPORATION", "LIMITED_LIABILITY_COMPANY", "PARTNERSHIP", "LIMITED_PARTNERSHIP", "GENERAL_PARTNERSHIP", "ASSOCIATION_ESTATE_TRUST", "TAX_EXEMPT_ORGANIZATION", "GOVERNMENT_AGENCY"]).nullable().optional(), default_statement_descriptor: statementDescriptor.optional(), discover_mid: z.number().int().nullable().optional(), dob: z.object({day: z.number().int().gte(1).optional(), month: z.number().int().gte(1).optional(), year: z.number().int().gte(1900).optional()}).nullable().optional(), doing_business_as: z.string().min(1).nullable().optional(), email: z.string().min(1).nullable().optional(), first_name: z.string().min(1).nullable().optional(), has_accepted_credit_cards_previously: z.boolean().optional(), incorporation_date: z.object({day: z.number().int().optional(), month: z.number().int().optional(), year: z.number().int().optional()}).nullable().optional(), last_name: z.string().min(1).nullable().optional(), mcc: z.string().min(1).nullable().optional(), ownership_type: z.enum(["PUBLIC", "PRIVATE"]).min(1).nullable().optional(), personal_address: z.object({line1: z.string().min(1).nullable().optional(), line2: z.string().min(1).nullable().optional(), city: z.string().min(1).nullable().optional(), region: z.string().min(1).nullable().optional(), postal_code: z.string().min(1).nullable().optional(), country: z.string().min(1).nullable().optional()}).nullable().optional(), phone: z.string().min(1).nullable().optional(), principal_percentage_ownership: z.union([z.number().int(), z.string()]).nullable().optional(), short_business_name: z.string().nullable().optional(), tax_authority: z.string().nullable().optional(), tax_id: z.string().min(1).nullable().optional(), tax_id_provided: z.boolean().optional(), business_tax_id: z.string().min(1).nullable().optional(), title: z.string().min(1).nullable().optional(), url: z.string().min(1).nullable().optional()}).optional(), payment_instruments: z.object({account_number: z.string().optional(), account_type: z.string().optional(), attempt_bank_account_validation_check: z.enum(["CHECKING", "SAVINGS", "PERSONAL_CHECKING", "PERSONAL_SAVINGS", "BUSINESS_CHECKING", "BUSINESS_SAVINGS", "CORPORATE", "CORP_SAVINGS"]).optional(), bank_code: z.string().optional(), name: z.string().optional(), type: z.literal("BANK_ACCOUNT").optional(), country: z.string().optional(), currency: z.string().optional()}).optional(), max_transaction_amount: z.number().int(), ach_max_transaction_amount: z.number().int().optional(), associated_files: z.array(z.object({type: z.string().optional(), name: z.string().optional(), id: z.string().optional(), related_to: z.string().optional()})).optional()}); export const onboardingLinkDetails = z.object({expiration_in_minutes: z.number().int().optional(), expired_session_url: z.string(), fee_details_url: z.string(), merchant_max_transaction_amount: z.number().int().optional(), merchant_ach_max_transaction_amount: z.number().int().optional(), return_url: z.string(), terms_of_service_url: z.string()}); export const onboardingLink = z.object({expires_at: z.string().optional(), link_url: z.string().optional()}); export const applicationId = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const tags = z.record(z.string(), z.unknown()).nullable(); export const onboardingForm = z.object({id: id.optional(), onboarding_data: onboardingData.optional(), merchant_processors: z.array(z.object({processor: z.string().optional()})).optional(), onboarding_link_details: onboardingLinkDetails.optional(), onboarding_link: onboardingLink.optional(), status: z.enum(["IN_PROGRESS", "COMPLETED", "UPDATE_REQUESTED"]).optional(), identity_id: z.string().nullable().optional(), application_id: applicationId.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), tags: tags.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 }; /** * Create an Onboarding Form * * POST /onboarding_forms */ export const createApiOnboardingForms = async (args: CreateApiOnboardingFormsArgs, options?: CreateApiOnboardingFormsOptions) => { 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 (args['Finix-Version'] != null) headers.set("Finix-Version", String(args['Finix-Version'])) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/onboarding_forms${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(onboardingForm, await res.json()) };