import {z} from 'zod' export type GetApiReferenceDataArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, 'Institution-Number': string, Environment: string, classification?: ('legalFormIndex' | 'languageIndex' | 'accountOfficerIndex' | 'branchIndex' | 'paymentAdviceGenerationIndex' | 'paymentMethodIndex' | 'clientRegionIndex' | 'tierStructureIndex' | 'countryCode' | 'state' | 'countyIndex' | 'municipalityIndex' | 'pagobancomatIndex' | 'salesAgentId' | 'businessOwnerId' | 'salesChannelIndex' | 'deliveryMethodIndex' | 'statementTypeIndex' | 'calendarTypeIndex' | 'paymentFormatIndex' | 'clearingEntityIndex' | 'jcbStateCodeIndex' | 'jcbAreaCode1Index' | 'jcbArea2Index' | 'clientFeeIndex' | 'configOfTerminalIndex' | 'terminalTypeIndex' | 'serviceProviderIndex' | 'acquiringProfileIndex' | 'instructionTypeIndex' | 'merchantGradeIndex' | 'retailerclassification' | 'regionalTaxIndex' | 'propertyIndex' | 'viUsApIafFee' | 'requestIdIndex' | 'globalTravelB2BFeeIndIndex' | 'merchantStatusIndex' | 'amexModelIndex' | 'merchantSizeIndex' | 'accountCurrency' | 'fundingRejectStatus' | 'fxCategory' | 'mcpRateType' | 'tierPricingFlag') | undefined, offset?: number | undefined, limit?: number | undefined}; export type GetApiReferenceDataOptions = {baseUrl?: string | undefined, AppKey?: string | undefined, JWSSignature?: string | undefined, fetch?: typeof fetch | undefined}; export const pagingMetaType = z.object({count: z.number().int().optional(), totalPages: z.number().int().optional(), currentOffset: z.number().int().optional(), currentNumberOfRetrievedRecords: z.number().int().optional(), maxLimit: z.number().int().optional(), hasMoreRecords: z.boolean().optional(), pageNumber: z.number().int().optional()}); export const sortingMetaType = z.object({sort: z.string().optional()}); export const sourceType = z.object({pointer: z.string().optional(), parameter: z.string().optional(), header: z.string().optional()}); export const errorType = z.object({id: z.string().optional(), code: z.string(), title: z.string(), detail: z.string().optional(), source: sourceType.optional()}); export const metaType = z.object({paging: pagingMetaType.optional(), sorting: sortingMetaType.optional(), messages: z.array(errorType).optional()}); export const oPYAccountInternalAccountNumber = z.string().max(11); export const oPYGenericCode3 = z.string().min(1).max(3); export const oPYGenericDescription = z.string().max(100); export const oPYAccountAccountTypeObj = z.object({accountTypeIndex: oPYGenericCode3.optional(), accountTypeDescription: oPYGenericDescription.optional()}); export const oPYAccountAccountCurrencyCode = z.string().min(3).max(3); export const oPYAccountBillingLevel = z.boolean(); export const oPYAccountAccountStatus = z.enum(["ACTIVE", "CLOSED", "SUSPENDED", "COLLECT_EPS", "SUSPENSE_ACCT"]).max(16); export const oPYAccountReceiverCountryCode = z.string().min(3).max(3); export const oPYAccountPaymentReference = z.string().max(18); export const oPYAccountStatementTypeObj = z.object({statementTypeIndex: oPYGenericCode3.optional(), statementTypeDescription: oPYGenericDescription.optional()}); export const oPYAccountStatementGenerationCode = z.enum(["SUPPRESS", "GENERATE", "GENERATE_IF_ACTIVITY", "GENERATE_IF_NO_ACTIVITY"]); export const oPYAccountAnnualFeeDueDate = z.string().min(8).max(8); export const oPYAccountCalendarTypeObj = z.object({calendarTypeIndex: oPYGenericCode3.optional(), calendarTypeDescription: oPYGenericDescription.optional()}); export const oPYAccountLiabilityAccount = z.string().max(11); export const oPYAccountSepaDirectDebitSeq = z.enum(["FRST", "RCUR"]).max(32); export const oPYHierarchyParentInternalMerchantId = z.string().min(8).max(8); export const oPYMerchantTradeName = z.string().min(1).max(22); export const oPYAccountPayableBankName = z.string().max(40); export const oPYAccountPayableAccountName = z.string().max(35); export const oPYAccountPayableCounterBankNumber = z.string().max(22); export const oPYAccountPayableAccountNumber = z.string().max(35); export const oPYAccountPayableBankTelephone = z.string().max(15); export const oPYAccountPayableBankContactName = z.string().max(35); export const oPYAccountPayableCorrespondentBankNo = z.string().max(11); export const oPYAccountPayableIban = z.string().max(35); export const oPYAccountPayableCustomerPaymentText = z.string().max(18); export const oPYAccountPayableBankCity = z.string().max(35); export const oPYAccountPayablePaymentFormatObj = z.object({paymentFormatIndex: oPYGenericCode3.optional(), paymentFormatDescription: oPYGenericDescription.optional()}); export const oPYAccountPayableClearingEntityObj = z.object({clearingEntityIndex: oPYGenericCode3.optional(), clearingEntityDescription: oPYGenericDescription.optional()}); export const oPYAccountPayableCorrespondentBankAccount = z.string().max(16); export const oPYAccountPayableCalendarDays = z.string().min(3).max(3); export const oPYAccountPayablePaymentDelayDays = z.string().min(3).max(3); export const oPYAccountPayableCeilingLimit = z.string().max(16); export const merchantAccountPayable = z.object({bankName: oPYAccountPayableBankName.optional(), accountName: oPYAccountPayableAccountName.optional(), counterBankNumber: oPYAccountPayableCounterBankNumber.optional(), accountNumber: oPYAccountPayableAccountNumber.optional(), bankTelephone: oPYAccountPayableBankTelephone.optional(), bankContactName: oPYAccountPayableBankContactName.optional(), correspondentBankNo: oPYAccountPayableCorrespondentBankNo.optional(), iban: oPYAccountPayableIban.optional(), customerPaymentText: oPYAccountPayableCustomerPaymentText.optional(), bankCity: oPYAccountPayableBankCity.optional(), paymentFormat: oPYAccountPayablePaymentFormatObj.optional(), clearingEntity: oPYAccountPayableClearingEntityObj.optional(), correspondentBankAccount: oPYAccountPayableCorrespondentBankAccount.optional(), calendarDays: oPYAccountPayableCalendarDays.optional(), paymentDelayDays: oPYAccountPayablePaymentDelayDays.optional(), ceilingLimit: oPYAccountPayableCeilingLimit.optional()}); export const oPYAccountReceivableBankName = z.string().max(40); export const oPYAccountReceivableAccountName = z.string().max(35); export const oPYAccountReceivableCounterBankNumber = z.string().max(22); export const oPYAccountReceivableAccountNumber = z.string().max(35); export const oPYAccountReceivableBankTelephone = z.string().max(15); export const oPYAccountReceivableBankContactName = z.string().max(35); export const oPYAccountReceivableCorrespondentBankNo = z.string().max(11); export const oPYAccountReceivableIban = z.string().max(35); export const oPYAccountReceivableCustomerPaymentText = z.string().max(18); export const oPYAccountReceivableBankCity = z.string().max(35); export const oPYAccountReceivablePaymentFormatObj = z.object({paymentFormatIndex: oPYGenericCode3.optional(), paymentFormatDescription: oPYGenericDescription.optional()}); export const oPYAccountReceivableClearingEntityObj = z.object({clearingEntityIndex: oPYGenericCode3.optional(), clearingEntityDescription: oPYGenericDescription.optional()}); export const oPYAccountReceivableCorrespondentBankAccount = z.string().max(16); export const oPYAccountReceivableCalendarDays = z.string().min(3).max(3); export const oPYAccountReceivableCollectionDelayDays = z.string().min(3).max(3); export const oPYAccountReceivableDdMandateReference = z.string().max(35); export const merchantAccountReceivable = z.object({bankName: oPYAccountReceivableBankName.optional(), accountName: oPYAccountReceivableAccountName.optional(), counterBankNumber: oPYAccountReceivableCounterBankNumber.optional(), accountNumber: oPYAccountReceivableAccountNumber.optional(), bankTelephone: oPYAccountReceivableBankTelephone.optional(), bankContactName: oPYAccountReceivableBankContactName.optional(), correspondentBankNo: oPYAccountReceivableCorrespondentBankNo.optional(), iban: oPYAccountReceivableIban.optional(), customerPaymentText: oPYAccountReceivableCustomerPaymentText.optional(), bankCity: oPYAccountReceivableBankCity.optional(), paymentFormat: oPYAccountReceivablePaymentFormatObj.optional(), clearingEntity: oPYAccountReceivableClearingEntityObj.optional(), correspondentBankAccount: oPYAccountReceivableCorrespondentBankAccount.optional(), calendarDays: oPYAccountReceivableCalendarDays.optional(), collectionDelayDays: oPYAccountReceivableCollectionDelayDays.optional(), ddMandateReference: oPYAccountReceivableDdMandateReference.optional()}); export const linksType = z.object({self: z.string().optional(), first: z.string().optional(), last: z.string().optional(), prev: z.string().optional(), next: z.string().optional()}); export const inlineResponse200 = z.object({meta: metaType.optional(), data: z.array(z.object({internalAccountNumber: oPYAccountInternalAccountNumber.optional(), accountType: oPYAccountAccountTypeObj.optional(), accountCurrencyCode: oPYAccountAccountCurrencyCode.optional(), billingLevel: oPYAccountBillingLevel.optional(), accountStatus: oPYAccountAccountStatus.optional(), receiverCountryCode: oPYAccountReceiverCountryCode.optional(), paymentReference: oPYAccountPaymentReference.optional(), statementType: oPYAccountStatementTypeObj.optional(), statementGenerationCode: oPYAccountStatementGenerationCode.optional(), annualFeeDueDate: oPYAccountAnnualFeeDueDate.optional(), calendarTypeIndex: oPYAccountCalendarTypeObj.optional(), liabilityAccount: oPYAccountLiabilityAccount.optional(), sepaDirectDebitSeq: oPYAccountSepaDirectDebitSeq.optional(), parentInternalMerchantId: oPYHierarchyParentInternalMerchantId.optional(), parentTradeName: oPYMerchantTradeName.optional(), payable: merchantAccountPayable.optional(), receivable: merchantAccountReceivable.optional()})).optional(), errors: z.array(errorType).optional(), links: linksType.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 }; /** * Retrieve Reference Data * * GET /reference-data */ export const getApiReferenceData = async (args: GetApiReferenceDataArgs, options?: GetApiReferenceDataOptions) => { const {baseUrl = "https://prod.emea.api.fiservapps.com/ipp/omnipay/acquirerprofile/v1.0", fetch: fetchFn = fetch, AppKey, JWSSignature} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args['FSV-Interaction-Id'] != null) headers.set("FSV-Interaction-Id", String(args['FSV-Interaction-Id'])) if (args['Institution-Number'] != null) headers.set("Institution-Number", String(args['Institution-Number'])) if (args.Environment != null) headers.set("Environment", String(args.Environment)) if (args.classification != null) query.append("classification", String(args.classification)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (AppKey !== undefined) headers.set("Api-Key", AppKey) if (JWSSignature !== undefined) headers.set("JWS-Signature", JWSSignature) const url = `${baseUrl.replace(/\/+$/, '')}/reference-data${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(inlineResponse200, await res.json()) };