import {z} from 'zod' export type Limit = number; export type Offset = number; export type GetApiTransactionsTransactionSummariesArgs = {postedAfter?: string | undefined, postedBefore?: string | undefined, limit?: Limit | undefined, offset?: Offset | undefined, 'Partner-Code'?: string | undefined, 'Merchant-Id'?: string | undefined}; export type GetApiTransactionsTransactionSummariesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const externalMerchantId = z.string().max(30); export const allianceCode = z.string().min(1).max(50).nullable(); export const partnerCode = z.string().min(1).max(50).nullable(); export const transactionType = z.enum(["PURCHASE", "PAYMENT", "CASH_ADVANCE", "REFUND", "PURCHASE_WITH_CASHBACK", "CARD_VERIFICATION", "PREPAID_LOAD", "BALANCE_ENQUIRY", "CHECK_VERIFICATION", "CHECK_GUARANTEE", "PURCHASE_ADJUSTMENT", "MOBILE_TOPUP", "PURCHASE_WITH_TIP", "ADMIN", "ACCOUNT_FUNDING_TRANSACTION", "ORIGINAL_CREDIT", "MONEY_TRANSFER"]); export const paymentInstrumentCategory = z.enum(["CARD", "CASH", "ALTERNATIVE"]); export const transactionSummary = z.object({combined: z.object({total: z.string().optional(), merchant: z.object({id: externalMerchantId.optional(), allianceCode: allianceCode.optional(), partnerCode: partnerCode.optional()}).optional()}).optional(), daily: z.array(z.object({day: z.string().optional(), total: z.string(), currencyCode: z.string().min(3).max(3).nullable().optional(), transactionType: transactionType.optional(), paymentInstrument: z.object({category: paymentInstrumentCategory, brand: z.enum(["AMEX", "CUP", "DINERS", "GIRO", "JCB", "MAESTRO", "MC", "PAGO", "PP", "PRIV", "VISA", "VPAY", "GIFT", "C_EGIFT", "CARTBLANC", "RUPAY"]).nullable().optional(), service: z.enum(["BLIK", "ELV", "IDEAL", "KLARNA", "PAYPAL", "PBL", "SEPADD", "SOFORT", "TOPUP", "EASYCASH", "VIPP", "MOBILEPAY", "TWINT", "SWISH", "ALIPAY", "WECHATPAY", "POSTFINANCE", "OTHER"]).nullable().optional()}).optional(), _links: z.object({transactions: z.object({href: z.string().optional()}).optional()}).optional()})).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 }; /** * List the daily transaction summaries * * GET /transactions/transaction-summaries */ export const getApiTransactionsTransactionSummaries = async (args: GetApiTransactionsTransactionSummariesArgs, options?: GetApiTransactionsTransactionSummariesOptions) => { const {baseUrl = "https://prod.emea.api.fiservapps.com/ipp/omnipay/acquirerprofile/v1.0", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.postedAfter != null) query.append("postedAfter", String(args.postedAfter)) if (args.postedBefore != null) query.append("postedBefore", String(args.postedBefore)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args['Partner-Code'] != null) headers.set("Partner-Code", String(args['Partner-Code'])) if (args['Merchant-Id'] != null) headers.set("Merchant-Id", String(args['Merchant-Id'])) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/transaction-summaries${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(transactionSummary, await res.json()) };