import {z} from 'zod' export type StatementDescriptor = string | null; export type Country = 'ABW' | 'AFG' | 'AGO' | 'AIA' | 'ALA' | 'ALB' | 'AND' | 'ARE' | 'ARG' | 'ARM' | 'ASM' | 'ATA' | 'ATF' | 'ATG' | 'AUS' | 'AUT' | 'AZE' | 'BDI' | 'BEL' | 'BEN' | 'BES' | 'BFA' | 'BGD' | 'BGR' | 'BHR' | 'BHS' | 'BIH' | 'BLM' | 'BLR' | 'BLZ' | 'BMU' | 'BOL' | 'BRA' | 'BRB' | 'BRN' | 'BTN' | 'BVT' | 'BWA' | 'CAF' | 'CAN' | 'CCK' | 'CHE' | 'CHL' | 'CHN' | 'CIV' | 'CMR' | 'COD' | 'COG' | 'COK' | 'COL' | 'COM' | 'CPV' | 'CRI' | 'CUB' | 'CUW' | 'CXR' | 'CYM' | 'CYP' | 'CZE' | 'DEU' | 'DJI' | 'DMA' | 'DNK' | 'DOM' | 'DZA' | 'ECU' | 'EGY' | 'ERI' | 'ESH' | 'ESP' | 'EST' | 'ETH' | 'FIN' | 'FJI' | 'FLK' | 'FRA' | 'FRO' | 'FSM' | 'GAB' | 'GBR' | 'GEO' | 'GGY' | 'GHA' | 'GIB' | 'GIN' | 'GLP' | 'GMB' | 'GNB' | 'GNQ' | 'GRC' | 'GRD' | 'GRL' | 'GTM' | 'GUF' | 'GUM' | 'GUY' | 'HKG' | 'HMD' | 'HND' | 'HRV' | 'HTI' | 'HUN' | 'IDN' | 'IMN' | 'IND' | 'IOT' | 'IRL' | 'IRN' | 'IRQ' | 'ISL' | 'ISR' | 'ITA' | 'JAM' | 'JEY' | 'JOR' | 'JPN' | 'KAZ' | 'KEN' | 'KGZ' | 'KHM' | 'KIR' | 'KNA' | 'KOR' | 'KWT' | 'LAO' | 'LBN' | 'LBR' | 'LBY' | 'LCA' | 'LIE' | 'LKA' | 'LSO' | 'LTU' | 'LUX' | 'LVA' | 'MAC' | 'MAF' | 'MAR' | 'MCO' | 'MDA' | 'MDG' | 'MDV' | 'MEX' | 'MHL' | 'MKD' | 'MLI' | 'MLT' | 'MMR' | 'MNE' | 'MNG' | 'MNP' | 'MRT' | 'MSR' | 'MTQ' | 'MUS' | 'MWI' | 'MYS' | 'MYT' | 'NAM' | 'NCL' | 'NER' | 'NFK' | 'NGA' | 'NIC' | 'NIU' | 'NLD' | 'NOR' | 'NPL' | 'NRU' | 'NZL' | 'OMN' | 'PAK' | 'PAN' | 'PCN' | 'PER' | 'PHL' | 'PLW' | 'PNG' | 'POL' | 'PRI' | 'PRK' | 'PRT' | 'PRY' | 'PSE' | 'PYF' | 'QAT' | 'REU' | 'ROU' | 'RUS' | 'RWA' | 'SAU' | 'SDN' | 'SEN' | 'SGP' | 'SGS' | 'SHN' | 'SJM' | 'SLB' | 'SLE' | 'SLV' | 'SMR' | 'SOM' | 'SPM' | 'SRB' | 'SSD' | 'STP' | 'SUR' | 'SVK' | 'SVN' | 'SWE' | 'SWZ' | 'SXM' | 'SYC' | 'SYR' | 'TCA' | 'TCD' | 'TGO' | 'THA' | 'TJK' | 'TKL' | 'TKM' | 'TLS' | 'TON' | 'TTO' | 'TUN' | 'TUR' | 'TUV' | 'TWN' | 'TZA' | 'UGA' | 'UKR' | 'UMI' | 'URY' | 'USA' | 'UZB' | 'VAT' | 'VCT' | 'VEN' | 'VGB' | 'VIR' | 'VNM' | 'VUT' | 'WLF' | 'WSM' | 'XKX' | 'YEM' | 'ZAF' | 'ZMB' | 'ZWE' | null; export type Address = {line1: string | null, line2?: (string | null) | undefined, city: string | null, region: string | null, postal_code: string | null, country: Country}; export type Tags = {[key: string]: unknown} | null; export type CreateIdentitySellerUSA = {additional_underwriting_data: {annual_ach_volume: number, average_ach_transfer_amount: number, average_card_transfer_amount: number, business_description: string, card_volume_distribution: {card_present_percentage?: number | undefined, ecommerce_percentage?: number | undefined, mail_order_telephone_order_percentage?: number | undefined} | null, credit_check_allowed?: boolean | undefined, credit_check_ip_address?: string | undefined, credit_check_timestamp?: string | undefined, credit_check_user_agent?: string | undefined, merchant_agreement_accepted: boolean, merchant_agreement_ip_address: string, merchant_agreement_timestamp: string, merchant_agreement_user_agent: string, refund_policy: 'MERCHANDISE_EXCHANGE_ONLY' | 'NO_REFUNDS' | 'OTHER' | 'WITHIN_30_DAYS', 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}, entity?: ({ach_max_transaction_amount?: number | undefined, amex_mid?: number | undefined, annual_card_volume?: number | undefined, business_address?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: string | undefined, postal_code?: string | undefined, region?: string | undefined}) | undefined, business_name?: string | undefined, business_phone?: string | undefined, business_tax_id?: string | undefined, business_type?: ('ASSOCIATION_ESTATE_TRUST' | 'CORPORATION' | 'GENERAL_PARTNERSHIP' | 'GOVERNMENT_AGENCY' | 'INDIVIDUAL_SOLE_PROPRIETORSHIP' | 'LIMITED_LIABILITY_COMPANY' | 'LIMITED_PARTNERSHIP' | 'PARTNERSHIP' | 'TAX_EXEMPT_ORGANIZATION') | undefined, default_statement_descriptor?: StatementDescriptor | undefined, discover_mid?: number | 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}) | undefined, last_name?: string | undefined, max_transaction_amount?: number | undefined, mcc?: string | undefined, ownership_type?: ('PRIVATE' | 'PUBLIC') | undefined, personal_address?: Address | undefined, phone?: string | undefined, principal_percentage_ownership?: number | undefined, short_business_name?: string | undefined, tax_authority?: string | undefined, tax_id?: string | undefined, title?: string | undefined, url?: string | undefined}) | undefined, identity_roles?: Array<'SELLER'> | undefined, tags?: Tags | undefined, type?: 'BUSINESS' | undefined}; export type CreateIdentitySellerCAN = {additional_underwriting_data: {average_card_transfer_amount: number, business_description: string, card_volume_distribution: {card_present_percentage?: number | undefined, ecommerce_percentage?: number | undefined, mail_order_telephone_order_percentage?: number | undefined}, credit_check_allowed?: boolean | undefined, credit_check_ip_address?: string | undefined, credit_check_timestamp?: string | undefined, credit_check_user_agent?: string | undefined, merchant_agreement_accepted: boolean, merchant_agreement_ip_address: string, merchant_agreement_timestamp: string, merchant_agreement_user_agent: string, refund_policy: 'MERCHANDISE_EXCHANGE_ONLY' | 'NO_REFUNDS' | 'OTHER' | 'WITHIN_30_DAYS', 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}}, entity?: ({ach_max_transaction_amount?: number | undefined, amex_mid?: number | undefined, annual_card_volume?: number | undefined, business_address?: ({city?: string | undefined, country?: string | undefined, line1?: string | undefined, line2?: (string | null) | undefined, postal_code?: string | undefined, region?: string | undefined}) | undefined, business_name?: string | undefined, business_phone?: string | undefined, business_tax_id?: string | undefined, business_type?: ('ASSOCIATION_ESTATE_TRUST' | 'CORPORATION' | 'GENERAL_PARTNERSHIP' | 'GOVERNMENT_AGENCY' | 'INDIVIDUAL_SOLE_PROPRIETORSHIP' | 'LIMITED_LIABILITY_COMPANY' | 'LIMITED_PARTNERSHIP' | 'PARTNERSHIP' | 'TAX_EXEMPT_ORGANIZATION') | undefined, default_statement_descriptor?: StatementDescriptor | undefined, discover_mid?: number | 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}) | undefined, last_name?: string | undefined, max_transaction_amount?: number | undefined, mcc?: string | undefined, ownership_type?: ('PRIVATE' | 'PUBLIC') | undefined, personal_address?: Address | undefined, phone?: string | undefined, principal_percentage_ownership?: number | undefined, short_business_name?: string | undefined, tax_id?: string | undefined, title?: string | undefined, url?: string | undefined}) | undefined, identity_roles?: Array<'SELLER'> | undefined, tags?: Tags | undefined, type?: 'BUSINESS' | undefined}; export type CreateIdentityRecipientBusiness = {entity: {business_address: Address, business_name: string | null, doing_business_as: string | null, first_name: string | null, last_name: string | null, personal_address: Address}, identity_roles?: Array<'RECIPIENT'> | undefined, tags?: Tags | undefined, type?: 'BUSINESS' | undefined}; export type CreateIdentityRecipientPersonal = {entity: {email?: string | undefined, first_name: string, last_name: string, personal_address: Address, phone?: string | undefined}, identity_roles?: Array<'RECIPIENT'> | undefined, tags?: Tags | undefined, type?: 'PERSONAL' | undefined}; export type CreateIdentityBuyer = {entity: {email?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, personal_address?: Address | undefined, phone?: string | undefined}, identity_roles?: Array<'BUYER'> | undefined, tags?: Tags | undefined, type?: ('BUSINESS' | 'PERSONAL') | undefined}; export type CreateIdentityBuyerBlank = {entity: {email?: string | undefined, first_name?: string | undefined, last_name?: string | undefined, personal_address?: Address | undefined, phone?: string | undefined}, identity_roles?: Array<'BUYER'> | undefined, tags?: Tags | undefined, type?: ('BUSINESS' | 'PERSONAL') | undefined}; export type CreateIdentitySenderAndRecipientPersonal = {entity: {first_name: string, last_name: string, personal_address: Address}, identity_roles: Array<'RECIPIENT' | 'SENDER'>, type: 'PERSONAL'}; export type CreateIdentitySenderAndRecipientBusiness = {entity: {business_address: Address, business_name: string | null, doing_business_as: string | null, first_name: string | null, last_name: string | null, personal_address: Address}, identity_roles: Array<'RECIPIENT' | 'SENDER'>, type: 'BUSINESS'}; export type CreateApiIdentitiesArgs = {'Finix-Version'?: string | undefined, 'Content-Type'?: string | undefined, body: CreateIdentitySellerUSA | CreateIdentitySellerCAN | CreateIdentityRecipientBusiness | CreateIdentityRecipientPersonal | CreateIdentityBuyer | CreateIdentityBuyerBlank | CreateIdentitySenderAndRecipientPersonal | CreateIdentitySenderAndRecipientBusiness}; export type CreateApiIdentitiesOptions = {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 additionalUnderwritingData = z.object({annual_ach_volume: z.number().int().optional(), annual_card_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_allowed: z.boolean().optional(), credit_check_ip_address: z.string().min(1).optional(), credit_check_timestamp: z.string().min(1).optional(), credit_check_user_agent: z.string().min(1).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()}); export const statementDescriptor = z.string().max(20).nullable(); export const country = z.enum(["ABW", "AFG", "AGO", "AIA", "ALA", "ALB", "AND", "ARE", "ARG", "ARM", "ASM", "ATA", "ATF", "ATG", "AUS", "AUT", "AZE", "BDI", "BEL", "BEN", "BES", "BFA", "BGD", "BGR", "BHR", "BHS", "BIH", "BLM", "BLR", "BLZ", "BMU", "BOL", "BRA", "BRB", "BRN", "BTN", "BVT", "BWA", "CAF", "CAN", "CCK", "CHE", "CHL", "CHN", "CIV", "CMR", "COD", "COG", "COK", "COL", "COM", "CPV", "CRI", "CUB", "CUW", "CXR", "CYM", "CYP", "CZE", "DEU", "DJI", "DMA", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "FRO", "FSM", "GAB", "GBR", "GEO", "GGY", "GHA", "GIB", "GIN", "GLP", "GMB", "GNB", "GNQ", "GRC", "GRD", "GRL", "GTM", "GUF", "GUM", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IMN", "IND", "IOT", "IRL", "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JEY", "JOR", "JPN", "KAZ", "KEN", "KGZ", "KHM", "KIR", "KNA", "KOR", "KWT", "LAO", "LBN", "LBR", "LBY", "LCA", "LIE", "LKA", "LSO", "LTU", "LUX", "LVA", "MAC", "MAF", "MAR", "MCO", "MDA", "MDG", "MDV", "MEX", "MHL", "MKD", "MLI", "MLT", "MMR", "MNE", "MNG", "MNP", "MRT", "MSR", "MTQ", "MUS", "MWI", "MYS", "MYT", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NIU", "NLD", "NOR", "NPL", "NRU", "NZL", "OMN", "PAK", "PAN", "PCN", "PER", "PHL", "PLW", "PNG", "POL", "PRI", "PRK", "PRT", "PRY", "PSE", "PYF", "QAT", "REU", "ROU", "RUS", "RWA", "SAU", "SDN", "SEN", "SGP", "SGS", "SHN", "SJM", "SLB", "SLE", "SLV", "SMR", "SOM", "SPM", "SRB", "SSD", "STP", "SUR", "SVK", "SVN", "SWE", "SWZ", "SXM", "SYC", "SYR", "TCA", "TCD", "TGO", "THA", "TJK", "TKL", "TKM", "TLS", "TON", "TTO", "TUN", "TUR", "TUV", "TWN", "TZA", "UGA", "UKR", "UMI", "URY", "USA", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "XKX", "YEM", "ZAF", "ZMB", "ZWE"]).nullable(); export const entity = z.object({amex_mid: z.number().int().nullable().optional(), annual_card_volume: z.number().int().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: z.string().optional(), business_tax_id_fingerprint: z.string().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(), max_transaction_amount: z.number().int().nullable().optional(), ach_max_transaction_amount: z.number().int().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(), line2: z.string().min(1).nullable().optional(), city: z.string().min(1).nullable(), region: z.string().min(1).nullable(), postal_code: z.string().min(1).nullable(), country: country}).nullable().optional(), phone: z.string().min(1).nullable().optional(), principal_percentage_ownership: z.number().int().nullable().optional(), short_business_name: z.string().nullable().optional(), tax_authority: z.string().nullable().optional(), tax_id: z.string().nullable().optional(), tax_id_fingerprint: z.string().nullable().optional(), tax_id_provided: z.boolean().optional(), title: z.string().min(1).nullable().optional(), url: z.string().min(1).nullable().optional()}); export const identityRoles = z.array(z.enum(["APPLICATION_OWNER", "BENEFICIAL_OWNER", "BUYER", "PLATFORM_OWNER", "RECIPIENT", "SELLER", "SENDER"])); export const tags = z.record(z.string(), z.unknown()).nullable(); export const self = z.object({href: z.string().min(1).optional()}); export const verifications = z.object({href: z.string().min(1).optional()}); export const merchants = z.object({href: z.string().min(1).optional()}); export const settlements = z.object({href: z.string().min(1).optional()}); export const authorizations = z.object({href: z.string().min(1).optional()}); export const transfers = z.object({href: z.string().min(1).optional()}); export const paymentInstruments = z.object({href: z.string().min(1).optional()}); export const associatedIdentities = z.object({href: z.string().min(1).optional()}); export const disputes = z.object({href: z.string().min(1).optional()}); export const applicationLink = z.object({href: z.string().min(1).optional()}); export const identity = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), additional_underwriting_data: additionalUnderwritingData.optional(), application: z.string().min(1).optional(), entity: entity.optional(), identity_roles: identityRoles.optional(), type: z.enum(["PERSONAL", "BUSINESS"]).optional(), tags: tags.optional(), _links: z.object({self: self.optional(), verifications: verifications.optional(), merchants: merchants.optional(), settlements: settlements.optional(), authorizations: authorizations.optional(), transfers: transfers.optional(), payment_instruments: paymentInstruments.optional(), associated_identities: associatedIdentities.optional(), disputes: disputes.optional(), application: applicationLink.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 }; /** * Create an Identity * * POST /identities */ export const createApiIdentities = async (args: CreateApiIdentitiesArgs, options?: CreateApiIdentitiesOptions) => { 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(/\/+$/, '')}/identities${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(identity, await res.json()) };