import {z} from 'zod' export type OPYFxRateMarginsTranCurrencyCode = string; export type OPYFxRateMarginsEffectiveDate = string; export type OPYFxRateMarginsFeeIdentifier = 'DCC_CONV_VISA' | 'DCC_CONV_ECMC' | 'MERCH_VISA_FXMKP' | 'MERCH_MC_FXMKP'; export type OPYFxRateMarginsRateMargin = string; export type MerchantFXRateMargins = {transactionCurrency: OPYFxRateMarginsTranCurrencyCode, effectiveDate: OPYFxRateMarginsEffectiveDate, feeIdentifier: OPYFxRateMarginsFeeIdentifier, rateMargin: OPYFxRateMarginsRateMargin}; export type CreateApiFxRateMarginsArgs = {'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 CreateApiFxRateMarginsOptions = {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 }; /** * Add merchant FX rate margins * * POST /fx-rate-margins */ export const createApiFxRateMargins = async (args: CreateApiFxRateMarginsArgs, options?: CreateApiFxRateMarginsOptions) => { 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(/\/+$/, '')}/fx-rate-margins${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(inlineResponse400, await res.json()) };