import {z} from 'zod' export type Amount = {currency?: string | undefined, value?: number | undefined}; export type CapabilitySettings = {amountPerIndustry?: {[key: string]: Amount} | undefined, authorizedCardUsers?: boolean | undefined, fundingSource?: (Array<'credit' | 'debit' | 'prepaid'>) | undefined, interval?: ('daily' | 'monthly' | 'weekly') | undefined, maxAmount?: Amount | undefined}; export type CapabilityProblemEntityRecursive = {documents?: Array | undefined, id?: string | undefined, type?: ('BankAccount' | 'Document' | 'LegalEntity' | 'product') | undefined}; export type CapabilityProblemEntity = {documents?: Array | undefined, id?: string | undefined, owner?: CapabilityProblemEntityRecursive | undefined, type?: ('BankAccount' | 'Document' | 'LegalEntity' | 'product') | undefined}; export type RemediatingAction = {code?: string | undefined, message?: string | undefined}; export type VerificationErrorRecursive = {capabilities?: (Array<'acceptExternalFunding' | 'acceptPspFunding' | 'acceptTransactionInRestrictedCountries' | 'acceptTransactionInRestrictedCountriesCommercial' | 'acceptTransactionInRestrictedCountriesConsumer' | 'acceptTransactionInRestrictedIndustries' | 'acceptTransactionInRestrictedIndustriesCommercial' | 'acceptTransactionInRestrictedIndustriesConsumer' | 'acquiring' | 'atmWithdrawal' | 'atmWithdrawalCommercial' | 'atmWithdrawalConsumer' | 'atmWithdrawalInRestrictedCountries' | 'atmWithdrawalInRestrictedCountriesCommercial' | 'atmWithdrawalInRestrictedCountriesConsumer' | 'authorisedPaymentInstrumentUser' | 'getGrantOffers' | 'issueBankAccount' | 'issueCard' | 'issueCardCommercial' | 'issueCardConsumer' | 'issueChargeCard' | 'issueChargeCardCommercial' | 'issueCreditLimit' | 'localAcceptance' | 'payout' | 'payoutToTransferInstrument' | 'processing' | 'receiveFromBalanceAccount' | 'receiveFromPlatformPayments' | 'receiveFromThirdParty' | 'receiveFromTransferInstrument' | 'receiveGrants' | 'receivePayments' | 'sendToBalanceAccount' | 'sendToThirdParty' | 'sendToTransferInstrument' | 'thirdPartyFunding' | 'useCard' | 'useCardCommercial' | 'useCardConsumer' | 'useCardInRestrictedCountries' | 'useCardInRestrictedCountriesCommercial' | 'useCardInRestrictedCountriesConsumer' | 'useCardInRestrictedIndustries' | 'useCardInRestrictedIndustriesCommercial' | 'useCardInRestrictedIndustriesConsumer' | 'useChargeCard' | 'useChargeCardCommercial' | 'withdrawFromAtm' | 'withdrawFromAtmCommercial' | 'withdrawFromAtmConsumer' | 'withdrawFromAtmInRestrictedCountries' | 'withdrawFromAtmInRestrictedCountriesCommercial' | 'withdrawFromAtmInRestrictedCountriesConsumer'>) | undefined, code?: string | undefined, message?: string | undefined, type?: ('dataMissing' | 'dataReview' | 'invalidInput' | 'pendingStatus' | 'rejected') | undefined, remediatingActions?: Array | undefined}; export type VerificationError = {capabilities?: (Array<'acceptExternalFunding' | 'acceptPspFunding' | 'acceptTransactionInRestrictedCountries' | 'acceptTransactionInRestrictedCountriesCommercial' | 'acceptTransactionInRestrictedCountriesConsumer' | 'acceptTransactionInRestrictedIndustries' | 'acceptTransactionInRestrictedIndustriesCommercial' | 'acceptTransactionInRestrictedIndustriesConsumer' | 'acquiring' | 'atmWithdrawal' | 'atmWithdrawalCommercial' | 'atmWithdrawalConsumer' | 'atmWithdrawalInRestrictedCountries' | 'atmWithdrawalInRestrictedCountriesCommercial' | 'atmWithdrawalInRestrictedCountriesConsumer' | 'authorisedPaymentInstrumentUser' | 'getGrantOffers' | 'issueBankAccount' | 'issueCard' | 'issueCardCommercial' | 'issueCardConsumer' | 'issueChargeCard' | 'issueChargeCardCommercial' | 'issueCreditLimit' | 'localAcceptance' | 'payout' | 'payoutToTransferInstrument' | 'processing' | 'receiveFromBalanceAccount' | 'receiveFromPlatformPayments' | 'receiveFromThirdParty' | 'receiveFromTransferInstrument' | 'receiveGrants' | 'receivePayments' | 'sendToBalanceAccount' | 'sendToThirdParty' | 'sendToTransferInstrument' | 'thirdPartyFunding' | 'useCard' | 'useCardCommercial' | 'useCardConsumer' | 'useCardInRestrictedCountries' | 'useCardInRestrictedCountriesCommercial' | 'useCardInRestrictedCountriesConsumer' | 'useCardInRestrictedIndustries' | 'useCardInRestrictedIndustriesCommercial' | 'useCardInRestrictedIndustriesConsumer' | 'useChargeCard' | 'useChargeCardCommercial' | 'withdrawFromAtm' | 'withdrawFromAtmCommercial' | 'withdrawFromAtmConsumer' | 'withdrawFromAtmInRestrictedCountries' | 'withdrawFromAtmInRestrictedCountriesCommercial' | 'withdrawFromAtmInRestrictedCountriesConsumer'>) | undefined, code?: string | undefined, message?: string | undefined, remediatingActions?: Array | undefined, subErrors?: Array | undefined, type?: ('dataMissing' | 'dataReview' | 'invalidInput' | 'pendingStatus' | 'rejected') | undefined}; export type CapabilityProblem = {entity?: CapabilityProblemEntity | undefined, verificationErrors?: Array | undefined}; export type LegalEntityCapability = {allowed?: boolean | undefined, allowedLevel?: ('high' | 'low' | 'medium' | 'notApplicable') | undefined, allowedSettings?: CapabilitySettings | undefined, problems?: Array | undefined, requested?: boolean | undefined, requestedLevel?: ('high' | 'low' | 'medium' | 'notApplicable') | undefined, requestedSettings?: CapabilitySettings | undefined, verificationStatus?: string | undefined}; export type LegalEntityAssociation = {associatorId?: string | undefined, entityType?: string | undefined, jobTitle?: string | undefined, legalEntityId: string, name?: string | undefined, nominee?: boolean | undefined, relationship?: string | undefined, settlorExemptionReason?: Array | undefined, type: 'definedBeneficiary' | 'director' | 'protector' | 'secondaryPartner' | 'secondaryTrustee' | 'settlor' | 'signatory' | 'trust' | 'uboThroughControl' | 'uboThroughOwnership' | 'undefinedBeneficiary'}; export type BirthData = {dateOfBirth?: string | undefined}; export type IdentificationData = {cardNumber?: string | undefined, expiryDate?: string | undefined, issuerCountry?: string | undefined, issuerState?: string | undefined, nationalIdExempt?: boolean | undefined, number?: string | undefined, type: 'nationalIdNumber'}; export type Name = {firstName: string, infix?: string | undefined, lastName: string}; export type PhoneNumber = {countryCode?: string | undefined, number: string, type: string}; export type Address = {city?: string | undefined, country: string, postalCode?: string | undefined, stateOrProvince?: string | undefined, street?: string | undefined, street2?: string | undefined}; export type WebData = {webAddress?: string | undefined, webAddressId?: string | undefined}; export type Individual = {birthData?: BirthData | undefined, email?: string | undefined, identificationData?: IdentificationData | undefined, name: Name, nationality?: string | undefined, phone?: PhoneNumber | undefined, residentialAddress: Address, webData?: WebData | undefined}; export type StockData = {marketIdentifier?: string | undefined, stockNumber?: string | undefined, tickerSymbol?: string | undefined}; export type Organization = {description?: string | undefined, doingBusinessAs?: string | undefined, email?: string | undefined, legalName: string, phone?: PhoneNumber | undefined, principalPlaceOfBusiness?: Address | undefined, registeredAddress: Address, registrationNumber?: string | undefined, stockData?: StockData | undefined, taxExempt?: boolean | undefined, taxId?: string | undefined, taxIdAbsenceReason?: ('industryExemption' | 'belowTaxThreshold') | undefined, type?: ('associationIncorporated' | 'governmentalOrganization' | 'listedPublicCompany' | 'nonProfit' | 'partnershipIncorporated' | 'privateCompany') | undefined, webData?: WebData | undefined}; export type Trust = {countryOfGoverningLaw: string, doingBusinessAs?: string | undefined, name: string, principalPlaceOfBusiness?: Address | undefined, registeredAddress: Address, registrationNumber?: string | undefined, type: 'businessTrust' | 'cashManagementTrust' | 'charitableTrust' | 'corporateUnitTrust' | 'deceasedEstate' | 'discretionaryTrust' | 'discretionaryInvestmentTrust' | 'discretionaryServicesManagementTrust' | 'discretionaryTradingTrust' | 'familyTrust' | 'firstHomeSaverAccountsTrust' | 'fixedTrust' | 'fixedUnitTrust' | 'hybridTrust' | 'listedPublicUnitTrust' | 'otherTrust' | 'pooledSuperannuationTrust' | 'publicTradingTrust' | 'unlistedPublicUnitTrust', vatAbsenceReason?: ('industryExemption' | 'belowTaxThreshold') | undefined, vatNumber?: string | undefined}; export type UnincorporatedPartnership = {countryOfGoverningLaw: string, doingBusinessAs?: string | undefined, name: string, principalPlaceOfBusiness?: Address | undefined, registeredAddress: Address, registrationNumber?: string | undefined, type?: ('limitedPartnership' | 'generalPartnership' | 'familyPartnership' | 'commercialPartnership' | 'publicPartnership' | 'otherPartnership' | 'gbr' | 'gmbh' | 'kgaa' | 'cv' | 'vof' | 'maatschap' | 'privateFundLimitedPartnership' | 'businessTrustEntity' | 'businessPartnership' | 'limitedLiabilityPartnership' | 'eg' | 'cooperative' | 'vos' | 'comunidadDeBienes' | 'herenciaYacente' | 'comunidadDePropietarios' | 'sep' | 'sca' | 'bt' | 'kkt' | 'scs' | 'snc') | undefined, vatAbsenceReason?: ('industryExemption' | 'belowTaxThreshold') | undefined, vatNumber?: string | undefined}; export type LegalEntityInfoRequiredType = {capabilities?: {[key: string]: LegalEntityCapability} | undefined, entityAssociations?: Array | undefined, individual?: Individual | undefined, organization?: Organization | undefined, reference?: string | undefined, trust?: Trust | undefined, type: 'individual' | 'organization', unincorporatedPartnership?: UnincorporatedPartnership | undefined, verificationPlan?: string | undefined}; export type CreateApiLegalEntitiesArgs = {'x-requested-verification-code'?: string | undefined, body: LegalEntityInfoRequiredType}; export type CreateApiLegalEntitiesOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const amount = z.object({currency: z.string().optional(), value: z.number().int().optional()}); export const capabilitySettings = z.object({amountPerIndustry: z.record(z.string(), amount).optional(), authorizedCardUsers: z.boolean().optional(), fundingSource: z.array(z.enum(["credit", "debit", "prepaid"])).optional(), interval: z.enum(["daily", "monthly", "weekly"]).optional(), maxAmount: amount.optional()}); export const capabilityProblemEntityRecursive = z.object({documents: z.array(z.string()).optional(), id: z.string().optional(), type: z.enum(["BankAccount", "Document", "LegalEntity", "product"]).optional()}); export const capabilityProblemEntity = z.object({documents: z.array(z.string()).optional(), id: z.string().optional(), owner: capabilityProblemEntityRecursive.optional(), type: z.enum(["BankAccount", "Document", "LegalEntity", "product"]).optional()}); export const remediatingAction = z.object({code: z.string().optional(), message: z.string().optional()}); export const verificationErrorRecursive = z.object({capabilities: z.array(z.enum(["acceptExternalFunding", "acceptPspFunding", "acceptTransactionInRestrictedCountries", "acceptTransactionInRestrictedCountriesCommercial", "acceptTransactionInRestrictedCountriesConsumer", "acceptTransactionInRestrictedIndustries", "acceptTransactionInRestrictedIndustriesCommercial", "acceptTransactionInRestrictedIndustriesConsumer", "acquiring", "atmWithdrawal", "atmWithdrawalCommercial", "atmWithdrawalConsumer", "atmWithdrawalInRestrictedCountries", "atmWithdrawalInRestrictedCountriesCommercial", "atmWithdrawalInRestrictedCountriesConsumer", "authorisedPaymentInstrumentUser", "getGrantOffers", "issueBankAccount", "issueCard", "issueCardCommercial", "issueCardConsumer", "issueChargeCard", "issueChargeCardCommercial", "issueCreditLimit", "localAcceptance", "payout", "payoutToTransferInstrument", "processing", "receiveFromBalanceAccount", "receiveFromPlatformPayments", "receiveFromThirdParty", "receiveFromTransferInstrument", "receiveGrants", "receivePayments", "sendToBalanceAccount", "sendToThirdParty", "sendToTransferInstrument", "thirdPartyFunding", "useCard", "useCardCommercial", "useCardConsumer", "useCardInRestrictedCountries", "useCardInRestrictedCountriesCommercial", "useCardInRestrictedCountriesConsumer", "useCardInRestrictedIndustries", "useCardInRestrictedIndustriesCommercial", "useCardInRestrictedIndustriesConsumer", "useChargeCard", "useChargeCardCommercial", "withdrawFromAtm", "withdrawFromAtmCommercial", "withdrawFromAtmConsumer", "withdrawFromAtmInRestrictedCountries", "withdrawFromAtmInRestrictedCountriesCommercial", "withdrawFromAtmInRestrictedCountriesConsumer"])).optional(), code: z.string().optional(), message: z.string().optional(), type: z.enum(["dataMissing", "dataReview", "invalidInput", "pendingStatus", "rejected"]).optional(), remediatingActions: z.array(remediatingAction).optional()}); export const verificationError = z.object({capabilities: z.array(z.enum(["acceptExternalFunding", "acceptPspFunding", "acceptTransactionInRestrictedCountries", "acceptTransactionInRestrictedCountriesCommercial", "acceptTransactionInRestrictedCountriesConsumer", "acceptTransactionInRestrictedIndustries", "acceptTransactionInRestrictedIndustriesCommercial", "acceptTransactionInRestrictedIndustriesConsumer", "acquiring", "atmWithdrawal", "atmWithdrawalCommercial", "atmWithdrawalConsumer", "atmWithdrawalInRestrictedCountries", "atmWithdrawalInRestrictedCountriesCommercial", "atmWithdrawalInRestrictedCountriesConsumer", "authorisedPaymentInstrumentUser", "getGrantOffers", "issueBankAccount", "issueCard", "issueCardCommercial", "issueCardConsumer", "issueChargeCard", "issueChargeCardCommercial", "issueCreditLimit", "localAcceptance", "payout", "payoutToTransferInstrument", "processing", "receiveFromBalanceAccount", "receiveFromPlatformPayments", "receiveFromThirdParty", "receiveFromTransferInstrument", "receiveGrants", "receivePayments", "sendToBalanceAccount", "sendToThirdParty", "sendToTransferInstrument", "thirdPartyFunding", "useCard", "useCardCommercial", "useCardConsumer", "useCardInRestrictedCountries", "useCardInRestrictedCountriesCommercial", "useCardInRestrictedCountriesConsumer", "useCardInRestrictedIndustries", "useCardInRestrictedIndustriesCommercial", "useCardInRestrictedIndustriesConsumer", "useChargeCard", "useChargeCardCommercial", "withdrawFromAtm", "withdrawFromAtmCommercial", "withdrawFromAtmConsumer", "withdrawFromAtmInRestrictedCountries", "withdrawFromAtmInRestrictedCountriesCommercial", "withdrawFromAtmInRestrictedCountriesConsumer"])).optional(), code: z.string().optional(), message: z.string().optional(), remediatingActions: z.array(remediatingAction).optional(), subErrors: z.array(verificationErrorRecursive).optional(), type: z.enum(["dataMissing", "dataReview", "invalidInput", "pendingStatus", "rejected"]).optional()}); export const capabilityProblem = z.object({entity: capabilityProblemEntity.optional(), verificationErrors: z.array(verificationError).optional()}); export const legalEntityCapability = z.object({allowed: z.boolean().optional(), allowedLevel: z.enum(["high", "low", "medium", "notApplicable"]).optional(), allowedSettings: capabilitySettings.optional(), problems: z.array(capabilityProblem).optional(), requested: z.boolean().optional(), requestedLevel: z.enum(["high", "low", "medium", "notApplicable"]).optional(), requestedSettings: capabilitySettings.optional(), verificationStatus: z.string().optional()}); export const entityReference = z.object({id: z.string().optional()}); export const legalEntityAssociation = z.object({associatorId: z.string().optional(), entityType: z.string().optional(), jobTitle: z.string().optional(), legalEntityId: z.string(), name: z.string().optional(), nominee: z.boolean().optional(), relationship: z.string().optional(), settlorExemptionReason: z.array(z.string()).optional(), type: z.enum(["definedBeneficiary", "director", "protector", "secondaryPartner", "secondaryTrustee", "settlor", "signatory", "trust", "uboThroughControl", "uboThroughOwnership", "undefinedBeneficiary"])}); export const birthData = z.object({dateOfBirth: z.string().optional()}); export const identificationData = z.object({cardNumber: z.string().optional(), expiryDate: z.string().optional(), issuerCountry: z.string().optional(), issuerState: z.string().optional(), nationalIdExempt: z.boolean().optional(), number: z.string().optional(), type: z.literal("nationalIdNumber")}); export const name = z.object({firstName: z.string(), infix: z.string().optional(), lastName: z.string()}); export const phoneNumber = z.object({countryCode: z.string().optional(), number: z.string(), type: z.string()}); export const address = z.object({city: z.string().optional(), country: z.string(), postalCode: z.string().optional(), stateOrProvince: z.string().optional(), street: z.string().optional(), street2: z.string().optional()}); export const webData = z.object({webAddress: z.string().optional(), webAddressId: z.string().optional()}); export const individual = z.object({birthData: birthData.optional(), email: z.string().optional(), identificationData: identificationData.optional(), name: name, nationality: z.string().optional(), phone: phoneNumber.optional(), residentialAddress: address, webData: webData.optional()}); export const stockData = z.object({marketIdentifier: z.string().optional(), stockNumber: z.string().optional(), tickerSymbol: z.string().optional()}); export const organization = z.object({description: z.string().optional(), doingBusinessAs: z.string().optional(), email: z.string().optional(), legalName: z.string(), phone: phoneNumber.optional(), principalPlaceOfBusiness: address.optional(), registeredAddress: address, registrationNumber: z.string().optional(), stockData: stockData.optional(), taxExempt: z.boolean().optional(), taxId: z.string().optional(), taxIdAbsenceReason: z.enum(["industryExemption", "belowTaxThreshold"]).optional(), type: z.enum(["associationIncorporated", "governmentalOrganization", "listedPublicCompany", "nonProfit", "partnershipIncorporated", "privateCompany"]).optional(), webData: webData.optional()}); export const transferInstrumentReference = z.object({accountIdentifier: z.string(), id: z.string(), realLastFour: z.string().optional(), trustedSource: z.boolean().optional()}); export const trust = z.object({countryOfGoverningLaw: z.string(), doingBusinessAs: z.string().optional(), name: z.string(), principalPlaceOfBusiness: address.optional(), registeredAddress: address, registrationNumber: z.string().optional(), type: z.enum(["businessTrust", "cashManagementTrust", "charitableTrust", "corporateUnitTrust", "deceasedEstate", "discretionaryTrust", "discretionaryInvestmentTrust", "discretionaryServicesManagementTrust", "discretionaryTradingTrust", "familyTrust", "firstHomeSaverAccountsTrust", "fixedTrust", "fixedUnitTrust", "hybridTrust", "listedPublicUnitTrust", "otherTrust", "pooledSuperannuationTrust", "publicTradingTrust", "unlistedPublicUnitTrust"]), vatAbsenceReason: z.enum(["industryExemption", "belowTaxThreshold"]).optional(), vatNumber: z.string().optional()}); export const unincorporatedPartnership = z.object({countryOfGoverningLaw: z.string(), doingBusinessAs: z.string().optional(), name: z.string(), principalPlaceOfBusiness: address.optional(), registeredAddress: address, registrationNumber: z.string().optional(), type: z.enum(["limitedPartnership", "generalPartnership", "familyPartnership", "commercialPartnership", "publicPartnership", "otherPartnership", "gbr", "gmbh", "kgaa", "cv", "vof", "maatschap", "privateFundLimitedPartnership", "businessTrustEntity", "businessPartnership", "limitedLiabilityPartnership", "eg", "cooperative", "vos", "comunidadDeBienes", "herenciaYacente", "comunidadDePropietarios", "sep", "sca", "bt", "kkt", "scs", "snc"]).optional(), vatAbsenceReason: z.enum(["industryExemption", "belowTaxThreshold"]).optional(), vatNumber: z.string().optional()}); export const legalEntity = z.object({capabilities: z.record(z.string(), legalEntityCapability).optional(), documents: z.array(entityReference).optional(), entityAssociations: z.array(legalEntityAssociation).optional(), id: z.string(), individual: individual.optional(), organization: organization.optional(), reference: z.string().max(150).optional(), transferInstruments: z.array(transferInstrumentReference).optional(), trust: trust.optional(), type: z.enum(["individual", "organization"]).optional(), unincorporatedPartnership: unincorporatedPartnership.optional(), verificationPlan: z.string().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 a legal entity * * POST /legalEntities * * Also accepts auth: ApiKeyAuth */ export const createApiLegalEntities = async (args: CreateApiLegalEntitiesArgs, options?: CreateApiLegalEntitiesOptions) => { const {baseUrl = "https://kyc-test.adyen.com/lem/v1", 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['x-requested-verification-code'] != null) headers.set("x-requested-verification-code", String(args['x-requested-verification-code'])) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/legalEntities${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(legalEntity, await res.json()) };