import {z} from 'zod' export type GetApiPaymentInstructionsArgs = {'Content-Type': 'application/json' | 'application/json;charset=UTF-8', 'FSV-Interaction-Id': string, Environment: string, 'Institution-Number': string, 'Internal-Merchant-Id': string, accountTypes?: string | undefined, accountCurrency?: string | undefined, status?: ('ACTIVE' | 'FUTURE' | 'EXPIRED' | 'ALL') | undefined, instructionTypeIndex?: string | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiPaymentInstructionsOptions = {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 oPYPaymentInstructionAccountTypeIndex = z.string().min(3).max(3); export const oPYGenericDescription = z.string().max(100); export const oPYPaymentInstructionAccountCurrencyCode = z.string().min(3).max(3); export const oPYPaymentInstructionAccountTypeSourceObj = z.object({accountTypeIndex: oPYPaymentInstructionAccountTypeIndex.optional(), accountTypeDescription: oPYGenericDescription.optional(), accountCurrencyCode: oPYPaymentInstructionAccountCurrencyCode.optional()}); export const oPYPaymentInstructionAccountTypeDestObj = z.object({accountTypeIndex: z.string().min(3).max(3).optional(), accountTypeDescription: oPYGenericDescription.optional(), accountCurrencyCode: z.string().min(3).max(3).optional()}); export const oPYPaymentInstructionInstructionTypeIndex = z.string().min(3).max(3); export const oPYPaymentInstructionInstructionTypeObj = z.object({instructionTypeIndex: oPYPaymentInstructionInstructionTypeIndex.optional(), instructionTypeDescription: oPYGenericDescription.optional()}); export const oPYPaymentInstructionStatus = z.enum(["ACTIVE", "FUTURE", "EXPIRED", "ALL"]); export const oPYPaymentInstructionInstructionIdNumber = z.string().max(10); export const oPYPaymentInstructionDeductionStartDate = z.string().min(8).max(8); export const oPYPaymentInstructionDeductionEndDate = z.string().min(8).max(8); export const oPYPaymentInstructionDeductionPercentage = z.string().max(11); export const oPYPaymentInstructionDeductionMinAmount = z.string().max(11); export const oPYPaymentInstructionDeductionMaxAmount = z.string().max(11); export const oPYPaymentInstructionDeductionBaseAmount = z.string().max(11); export const oPYPaymentInstructionDeductionTotalCnt = z.string().max(11); export const oPYPaymentInstructionDeductionTotalAmount = z.string().max(18); export const oPYPaymentInstructionFactorAgent = z.string().max(24); export const oPYPaymentInstructionNote = z.string().max(674); export const oPYPaymentInstructionDeductionFrequency = z.string().max(16); export const oPYPaymentInstructionLastExecutionDate = z.string().min(8).max(8); export const oPYPaymentInstructionExecutionCount = z.string().max(11); export const oPYPaymentInstructionAmountPaid = z.string().max(18); export const oPYPaymentInstructionLastUpdatedBy = z.string().max(60); export const oPYPaymentInstructionLastUpdatedDate = z.string().min(8).max(8); 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 inlineResponse20010 = z.object({meta: metaType.optional(), data: z.array(z.object({sourceAccount: oPYPaymentInstructionAccountTypeSourceObj.optional(), destinationAccount: oPYPaymentInstructionAccountTypeDestObj.optional(), instructionType: oPYPaymentInstructionInstructionTypeObj.optional(), status: oPYPaymentInstructionStatus.optional(), instructionIdNumber: oPYPaymentInstructionInstructionIdNumber.optional(), deductionStartDate: oPYPaymentInstructionDeductionStartDate.optional(), deductionEndDate: oPYPaymentInstructionDeductionEndDate.optional(), deductionPercentage: oPYPaymentInstructionDeductionPercentage.optional(), deductionMinAmount: oPYPaymentInstructionDeductionMinAmount.optional(), deductionMaxAmount: oPYPaymentInstructionDeductionMaxAmount.optional(), deductionBaseAmount: oPYPaymentInstructionDeductionBaseAmount.optional(), deductionTotalCnt: oPYPaymentInstructionDeductionTotalCnt.optional(), deductionTotalAmount: oPYPaymentInstructionDeductionTotalAmount.optional(), factorAgent: oPYPaymentInstructionFactorAgent.optional(), note: oPYPaymentInstructionNote.optional(), deductionFrequency: oPYPaymentInstructionDeductionFrequency.optional(), lastExecutionDate: oPYPaymentInstructionLastExecutionDate.optional(), executionCount: oPYPaymentInstructionExecutionCount.optional(), amountPaid: oPYPaymentInstructionAmountPaid.optional(), lastUpdatedBy: oPYPaymentInstructionLastUpdatedBy.optional(), lastUpdatedDate: oPYPaymentInstructionLastUpdatedDate.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 payment instructions * * GET /payment-instructions */ export const getApiPaymentInstructions = async (args: GetApiPaymentInstructionsArgs, options?: GetApiPaymentInstructionsOptions) => { 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.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 (args.accountTypes != null) query.append("accountTypes", String(args.accountTypes)) if (args.accountCurrency != null) query.append("accountCurrency", String(args.accountCurrency)) if (args.status != null) query.append("status", String(args.status)) if (args.instructionTypeIndex != null) query.append("instructionTypeIndex", String(args.instructionTypeIndex)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (AppKey !== undefined) headers.set("Api-Key", AppKey) if (JWSSignature !== undefined) headers.set("JWS-Signature", JWSSignature) const url = `${baseUrl.replace(/\/+$/, '')}/payment-instructions${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(inlineResponse20010, await res.json()) };