import {z} from 'zod' export type OPYAccountInternalAccountNumber = string; export type OPYAccountAccountStatus = 'ACTIVE' | 'CLOSED' | 'SUSPENDED' | 'COLLECT_EPS' | 'SUSPENSE_ACCT'; export type OPYAccountReceiverCountryCode = string; export type OPYAccountPaymentReference = string; export type OPYAccountStatementTypeIndex = string; export type OPYAccountStatementGenerationCode = 'SUPPRESS' | 'GENERATE' | 'GENERATE_IF_ACTIVITY' | 'GENERATE_IF_NO_ACTIVITY'; export type OPYAccountAnnualFeeDueDate = string; export type OPYAccountCalendarTypeIndex = string; export type OPYAccountAccountCurrencyCode = string; export type OPYAccountSepaDirectDebitSeq = 'FRST' | 'RCUR'; export type OPYAccountPayableBankName = string; export type OPYAccountPayableAccountName = string; export type OPYAccountPayableCounterBankNumber = string; export type OPYAccountPayableAccountNumber = string; export type OPYAccountPayableBankTelephone = string; export type OPYAccountPayableBankContactName = string; export type OPYAccountPayableCorrespondentBankNo = string; export type OPYAccountPayableIban = string; export type OPYAccountPayableCustomerPaymentText = string; export type OPYAccountPayableBankCity = string; export type OPYAccountPayablePaymentFormatIndex = string; export type OPYAccountPayableClearingEntityIndex = string; export type OPYAccountPayableCorrespondentBankAccount = string; export type OPYAccountPayableCalendarDays = string; export type OPYAccountPayablePaymentDelayDays = string; export type OPYAccountPayableCeilingLimit = string; export type MerchantAccountUpdatePayable = {bankName?: OPYAccountPayableBankName | undefined, accountName?: OPYAccountPayableAccountName | undefined, counterBankNumber?: OPYAccountPayableCounterBankNumber | undefined, accountNumber?: OPYAccountPayableAccountNumber | undefined, bankTelephone?: OPYAccountPayableBankTelephone | undefined, bankContactName?: OPYAccountPayableBankContactName | undefined, correspondentBankNo?: OPYAccountPayableCorrespondentBankNo | undefined, iban?: OPYAccountPayableIban | undefined, customerPaymentText?: OPYAccountPayableCustomerPaymentText | undefined, bankCity?: OPYAccountPayableBankCity | undefined, paymentFormatIndex?: OPYAccountPayablePaymentFormatIndex | undefined, clearingEntityIndex?: OPYAccountPayableClearingEntityIndex | undefined, correspondentBankAccount?: OPYAccountPayableCorrespondentBankAccount | undefined, calendarDays?: OPYAccountPayableCalendarDays | undefined, paymentDelayDays?: OPYAccountPayablePaymentDelayDays | undefined, ceilingLimit?: OPYAccountPayableCeilingLimit | undefined}; export type OPYAccountReceivableBankName = string; export type OPYAccountReceivableAccountName = string; export type OPYAccountReceivableCounterBankNumber = string; export type OPYAccountReceivableAccountNumber = string; export type OPYAccountReceivableBankTelephone = string; export type OPYAccountReceivableBankContactName = string; export type OPYAccountReceivableCorrespondentBankNo = string; export type OPYAccountReceivableIban = string; export type OPYAccountReceivableCustomerPaymentText = string; export type OPYAccountReceivableBankCity = string; export type OPYAccountReceivablePaymentFormatIndex = string; export type OPYAccountReceivableClearingEntityIndex = string; export type OPYAccountReceivableCorrespondentBankAccount = string; export type OPYAccountReceivableCalendarDays = string; export type OPYAccountReceivableCollectionDelayDays = string; export type OPYAccountReceivableDdMandateReference = string; export type MerchantAccountUpdateReceivable = {bankName?: OPYAccountReceivableBankName | undefined, accountName?: OPYAccountReceivableAccountName | undefined, counterBankNumber?: OPYAccountReceivableCounterBankNumber | undefined, accountNumber?: OPYAccountReceivableAccountNumber | undefined, bankTelephone?: OPYAccountReceivableBankTelephone | undefined, bankContactName?: OPYAccountReceivableBankContactName | undefined, correspondentBankNo?: OPYAccountReceivableCorrespondentBankNo | undefined, iban?: OPYAccountReceivableIban | undefined, customerPaymentText?: OPYAccountReceivableCustomerPaymentText | undefined, bankCity?: OPYAccountReceivableBankCity | undefined, paymentFormatIndex?: OPYAccountReceivablePaymentFormatIndex | undefined, clearingEntityIndex?: OPYAccountReceivableClearingEntityIndex | undefined, correspondentBankAccount?: OPYAccountReceivableCorrespondentBankAccount | undefined, calendarDays?: OPYAccountReceivableCalendarDays | undefined, collectionDelayDays?: OPYAccountReceivableCollectionDelayDays | undefined, ddMandateReference?: OPYAccountReceivableDdMandateReference | undefined}; export type MerchantAccountUpdate = {internalAccountNumber: OPYAccountInternalAccountNumber, accountStatus?: OPYAccountAccountStatus | undefined, receiverCountryCode?: OPYAccountReceiverCountryCode | undefined, paymentReference?: OPYAccountPaymentReference | undefined, statementTypeIndex?: OPYAccountStatementTypeIndex | undefined, statementGenerationCode?: OPYAccountStatementGenerationCode | undefined, annualFeeDueDate?: OPYAccountAnnualFeeDueDate | undefined, calendarTypeIndex?: OPYAccountCalendarTypeIndex | undefined, liabilityAccount?: OPYAccountAccountCurrencyCode | undefined, sepaDirectDebitSeq?: OPYAccountSepaDirectDebitSeq | undefined, payable?: MerchantAccountUpdatePayable | undefined, receivable?: MerchantAccountUpdateReceivable | undefined}; export type UpdateApiAccountsArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, Environment: string, 'Institution-Number': string, 'Internal-Merchant-Id': string, body: Array}; export type UpdateApiAccountsOptions = {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 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 inlineResponse400 = z.object({meta: metaType.optional(), data: z.array(z.object({})).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 }; /** * Modify merchant accounts * * PUT /accounts */ export const updateApiAccounts = async (args: UpdateApiAccountsArgs, options?: UpdateApiAccountsOptions) => { 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('content-type', "application/json") 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.Environment != null) headers.set("Environment", String(args.Environment)) if (args['Institution-Number'] != null) headers.set("Institution-Number", String(args['Institution-Number'])) if (args['Internal-Merchant-Id'] != null) headers.set("Internal-Merchant-Id", String(args['Internal-Merchant-Id'])) if (AppKey !== undefined) headers.set("Api-Key", AppKey) if (JWSSignature !== undefined) headers.set("JWS-Signature", JWSSignature) const url = `${baseUrl.replace(/\/+$/, '')}/accounts${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(inlineResponse400, await res.json()) };