import {z} from 'zod' export type Product = {NayaxProductID?: (number | null) | undefined, ProductGroupID?: (number | null) | undefined, ActorID?: (number | null) | undefined, ProductManufacturerID?: (number | null) | undefined, ProductName?: (string | null) | undefined, ProductCatalogNumber?: (string | null) | undefined, ProductBarcode?: (string | null) | undefined, ProductPackageQuantity?: (number | null) | undefined, ProductDescription?: (string | null) | undefined, ProductVolumeTypeID?: (number | null) | undefined, DEXProductName?: (string | null) | undefined, ProductCostPrice?: (number | null) | undefined, ProductDefaultRetailPrice?: (number | null) | undefined, ProductMinimumPickQTY?: (number | null) | undefined, ProductStatus?: (number | null) | undefined, ProductCashPrice?: (number | null) | undefined, ProductCreditCardPrice?: (number | null) | undefined, ProductPrepaidCardPrice?: (number | null) | undefined, ProductExternalPrepaidCardPrice?: (number | null) | undefined, ProductMemberTypePriceBit?: (boolean | null) | undefined, ProductPictureURL?: (string | null) | undefined, CaloriesPer100g?: (number | null) | undefined, CaloriesPerServing?: (number | null) | undefined, EANCode?: (string | null) | undefined, ProductCreatedBy?: (number | null) | undefined, ProductCreationDate?: (string | null) | undefined, ProductUpdatedBy?: (number | null) | undefined, ProductLastUpdated?: (string | null) | undefined, VatId?: (number | null) | undefined, SequenceNumber?: (number | null) | undefined, AgeVerificationEnableBit?: (boolean | null) | undefined, DepositTypeID?: (number | null) | undefined, DepositFee?: (number | null) | undefined, DepositTax?: (number | null) | undefined, Refs?: ({[key: string]: string | null} | null) | undefined}; export type StaticNotifyRequest = {AppUserId?: string | undefined, Balance?: number | undefined, Data?: string | undefined, Products?: Array | undefined, SecretToken?: string | undefined, TerminalId?: string | undefined, TransactionId?: string | undefined, UniQR?: string | undefined}; export type CreateApiCortinaIntegratorNameStartArgs = {integratorName: string, body: StaticNotifyRequest}; export type CreateApiCortinaIntegratorNameStartOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const status = z.object({Verdict: z.string().optional(), ErrorCode: z.number().int().nullable().optional(), ErrorDescription: z.string().nullable().optional(), StatusMessage: z.string().nullable().optional()}); export const staticNotifyResponse = z.object({Status: status.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 }; /** * Cortina StaticQR Start * * POST /Cortina/{integratorName}/start */ export const createApiCortinaIntegratorNameStart = async (args: CreateApiCortinaIntegratorNameStartArgs, options?: CreateApiCortinaIntegratorNameStartOptions) => { const {baseUrl = "https://lynx.nayax.com/payment/v2/transactions", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/Cortina/${encodeURIComponent(String(args.integratorName))}/start${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(staticNotifyResponse, await res.json()) };