import {z} from 'zod' export type CreateApiTransactionMerchantidMerchantIdTerminalidTerminalIdArgs = {merchantId: string, terminalId: string, body: {amount: number, type: string, vaultCard?: boolean | undefined, replayId: string}}; export type CreateApiTransactionMerchantidMerchantIdTerminalidTerminalIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const createApiTransactionMerchantidMerchantIdTerminalidTerminalIdResponse = z.union([z.object({message: z.string().optional(), prioritypaymentsystems: z.object({mxmerchant: z.object({merchant: z.object({devicePaymentAuditId: z.string().optional()}).optional(), transaction: z.object({}).optional()}).optional()}).optional(), provider: z.object({key: z.string().optional(), name: z.string().optional(), transaction: z.object({terminalID: z.string().optional(), status: z.string().optional(), transactionType: z.string().optional(), totalAmount: z.string().optional(), callbackUrl: z.string().optional(), uuid: z.string().optional(), id: z.string().optional(), portfolio: z.string().optional(), dateCreated: z.string().optional(), clientReference: z.string().optional(), currency: z.string().optional(), merchantId: z.string().optional(), source: z.string().optional(), replayId: z.string().optional()}).optional()}).optional(), status: z.string().optional()}), z.object({message: z.string().optional(), prioritypaymentsystems: z.object({mxmerchant: z.object({merchant: z.object({devicePaymentAuditId: z.string().optional()}).optional(), transaction: z.object({}).optional()}).optional()}).optional(), provider: z.object({key: z.string().optional(), name: z.string().optional(), transaction: z.object({message: z.string().optional()}).optional()}).optional(), status: z.string().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 }; /** * Terminal Transaction - Create * * POST /transaction/merchantid/{merchantId}/terminalid/{terminalId} */ export const createApiTransactionMerchantidMerchantIdTerminalidTerminalId = async (args: CreateApiTransactionMerchantidMerchantIdTerminalidTerminalIdArgs, options?: CreateApiTransactionMerchantidMerchantIdTerminalidTerminalIdOptions) => { const {baseUrl = "https://sandbox.api.mxmerchant.com/checkout", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/transaction/merchantid/${encodeURIComponent(String(args.merchantId))}/terminalid/${encodeURIComponent(String(args.terminalId))}${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(createApiTransactionMerchantidMerchantIdTerminalidTerminalIdResponse, await res.json()) };