import {z} from 'zod' export type GetApiV102PayoutsTransactionsTridArgs = {trid: string}; export type GetApiV102PayoutsTransactionsTridOptions = {baseUrl?: string | undefined, sec0?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiV102PayoutsTransactionsTridResponse = z.object({transactionStatus: z.string().optional(), transactionInfo: z.object({trid: z.string().optional(), reference: z.string().optional(), amount: z.number().int().optional(), commission: z.number().optional(), commissionIva: z.number().optional(), status: z.string().optional(), service: z.string().optional(), local: z.string().optional(), totalCommission: z.number().optional(), bookingDate: z.string().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 }; /** * TRID Information * * GET /v1.02/payouts/transactions/{trid} */ export const getApiV102PayoutsTransactionsTrid = async (args: GetApiV102PayoutsTransactionsTridArgs, options?: GetApiV102PayoutsTransactionsTridOptions) => { const {baseUrl = "https://sandbox.eupago.pt/api/management", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Bearer ${sec0}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1.02/payouts/transactions/${encodeURIComponent(String(args.trid))}${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(getApiV102PayoutsTransactionsTridResponse, await res.json()) };