import {z} from 'zod' export type CreateApiProfileVirtualAccountsRequestsCadArgs = {body: {accountType: 'individual', currency: 'CAD', meansOfId: string, utilityBill: string, isTermsAccepted: boolean, termsAndConditionAcceptance: {date: string, ipAddress: string}, KYCInformation: {firstName: string, lastName: string, email?: string | undefined, phone: string, birthDate: string, nationality: string, occupation: string, address: {countryOfResidence: string, number: string, street: string, city: string, state: string, zip: string}, document: {type: string, number: string, issuedCountryCode: string, issuedBy: string, issuedDate: string, expirationDate: string}, taxCountry: string, monthlyTransactionVolume: string, monthlyTransactionCount: string, sourceOfIncome: string, employmentStatus: string, accountDesignation: string, incomeBand: {lower: string, upper: string}}} | {accountType: 'corporate', currency: 'CAD', purpose: string, entityName: string, paymentFlowDescription: string, incorporationDocuments: string, articleOfIncorporation: string, beneficialOwnershipCertificate: string, sourceOfFunds: string, utilityBill?: string | undefined, bankStatement?: string | undefined, leaseAgreement?: string | undefined, isTermsAccepted: boolean, termsAndConditionAcceptance: {date: string, ipAddress: string}, KYCInformation: {address: {countryOfResidence: string, number: string, street: string, city: string, state: string, zip: string}, email: string, phone: string, website: string, tradingName: string, businessRegistrationName: string, businessRegistrationNumber: string, businessRegistrationCountry: string, incorporationCountryCode: string, incorporationDate: string, directorsName: string, taxIdentificationNumber: string, taxCountry: string, estimatedMonthlyTurnover: string, projectedMonthlyInflow: string, projectedMonthlyOutflow: string, projectedTransactionFrequency: string, projectedMonthlyTransactionCount: string, riskRating: string, companyType: string, primarySourceOfFunds: string, businessCategory: string, businessCategoryDescription: string, primaryBusiness: string, primaryBusinessDescription: string, regulationStatus: string, fundsTransferCorridors: Array, tradeInternationally: boolean, businessPartners: Array<{[key: string]: unknown}>, ultimateBeneficialOwners: Array<{firstName: string, lastName: string, title: string, emailAddress: string, phoneNumber: string, address: {countryOfResidence: string, number: string, street: string, city: string, state: string, zip: string}, dateOfBirth: string, nationality: string, citizenships: Array, taxCountry: string, percentageOwnership: string, beneficialOwnerType: string, politicallyExposedPerson: boolean, usResidencyStatus: string, document: {type: string, number: string, issuedCountryCode: string, issuedBy: string, issuedDate: string, expirationDate: string}, meansOfId: string, utilityBill: string}>}}}; export type CreateApiProfileVirtualAccountsRequestsCadOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiProfileVirtualAccountsRequestsCadResponse = z.object({success: z.boolean().optional(), message: z.string().optional(), data: z.object({_id: z.string().optional(), business: z.string().optional(), customerId: z.string().optional(), currency: z.string().optional(), currencyType: z.string().optional(), status: z.string().optional(), isActive: z.boolean().optional(), accountNumber: z.string().nullable().optional(), alternateAccountNumbers: z.array(z.unknown()).optional(), accountType: z.string().optional(), merchantReference: z.string().nullable().optional(), entityType: z.string().optional(), KYCInformation: z.record(z.string(), z.unknown()).optional(), accountInformation: z.record(z.string(), z.unknown()).nullable().optional(), note: z.string().nullable().optional(), accountOpeningFee: z.number().optional(), pendingAdditionalInfoCount: z.number().optional(), isPermanent: z.boolean().optional(), expiresAt: z.string().nullable().optional(), isSuspended: z.boolean().optional(), reason: z.string().nullable().optional(), meansOfId: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), bankStatement: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), utilityBill: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), virtualAccountType: z.string().optional(), metadata: z.object({}).nullable().optional(), phoneNumber: z.string().nullable().optional(), sourceOfFunds: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), leaseAgreement: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), beneficialOwnershipCertificate: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), articleOfIncorporation: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), incorporationDocuments: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), registerOfDirectors: z.array(z.object({name: z.string().optional(), url: z.string().optional()})).nullable().optional(), accountOpeningDate: z.string().nullable().optional(), regulatoryEvidence: z.union([z.object({}), z.array(z.unknown())]).nullable().optional(), consentId: z.string().nullable().optional(), createdAt: z.string().optional(), updatedAt: z.string().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 CAD Collection Account * * POST /profile/virtual-accounts/requests#cad */ export const createApiProfileVirtualAccountsRequestsCad = async (args: CreateApiProfileVirtualAccountsRequestsCadArgs, options?: CreateApiProfileVirtualAccountsRequestsCadOptions) => { const {baseUrl = "https://sandboxapi.fincra.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set("api-key", sec0) const url = `${baseUrl.replace(/\/+$/, '')}/profile/virtual-accounts/requests#cad${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(createApiProfileVirtualAccountsRequestsCadResponse, await res.json()) };