import {z} from 'zod' export type DenyListIndication = 0 | 1 | 2; export type TransitTransactionType = 1 | 2 | 3 | 7; export type TransitElement = {DenyListIndication?: DenyListIndication | undefined, TransitTransactionType?: TransitTransactionType | undefined}; export type BasicInfo = {AgeLimitation?: number | undefined, Amount: number, AuditNumber?: number | undefined, BillingProviderId?: number | undefined, CurrencyCode: string, CurrencyNumeric: string, IsDeferredAuthorization?: boolean | undefined, IsProductSelected?: boolean | undefined, IsSoftDeclineCompletion?: boolean | undefined, MachineAuTime?: string | undefined, NayaxRRN?: string | undefined, NayaxTransactionId?: number | undefined, PaymentMethodID?: number | undefined, SiteId?: number | undefined, TimeoutMS?: number | undefined, TransactionId: string, TransitElement?: TransitElement | undefined}; export type DeviceInfo = {FWVersion?: string | undefined, HwSerial?: string | undefined, Type?: string | undefined}; export type LanguageIdEnum = unknown; export type MachineTypeIDEnum = 555001 | 555002 | 555003 | 555004 | 555005 | 555006 | 555007 | 555008 | 556017 | 556018 | 30000514 | 30000515 | 30000516 | 30000517 | 30000518 | 30000519 | 30000520 | 30000521 | 30000522 | 30000523 | 30000524 | 30000525 | 30000526 | 30000527 | 30000561 | 30000578 | 30000579 | 30000580 | 30000581 | 30000582 | 30000583 | 30000602 | 30000611 | 30000612 | 30000617 | 30000618 | 30000619 | 30000620 | 30000623 | 176649542 | 227707459 | 227707460 | 504059468 | 529079224 | 363311433 | 244797254; export type MachineInfo = {MachineID?: (number | null) | undefined, ActorID?: (number | null) | undefined, CountryID?: (number | null) | undefined, CurrencyID?: (number | null) | undefined, InstituteID?: (number | null) | undefined, LocationID?: (number | null) | undefined, MachineGroupID?: (number | null) | undefined, MachineModelID?: (number | null) | undefined, MachineName?: (string | null) | undefined, MachineNumber?: (string | null) | undefined, MachineStatusBit?: number | undefined, LanguageID?: LanguageIdEnum | undefined, OperatorActorID?: (number | null) | undefined, DistributorActorID?: (number | null) | undefined, AreaActorID?: (number | null) | undefined, SalesSourceID?: (number | null) | undefined, MachineTypeID?: MachineTypeIDEnum | undefined, SerialNumber?: (string | null) | undefined, VPOSSerialNumber?: (string | null) | undefined, DeviceSerialNumber?: (string | null) | undefined, VPOSID?: (number | null) | undefined, DeviceID?: (number | null) | undefined, UseLocationFrom?: (number | null) | undefined, GeoCountry?: (number | null) | undefined, GeoState?: (string | null) | undefined, GeoCity?: (string | null) | undefined, GeoAddress?: (string | null) | undefined, GeoStreetNumber?: (string | null) | undefined, GeoLongitude?: (number | null) | undefined, GeoLatitude?: (number | null) | undefined, GeoZoom?: (number | null) | undefined, GeoZipCode?: (string | null) | undefined, SearchAddress?: (string | null) | undefined, Remarks?: (string | null) | undefined, DexType?: (number | null) | undefined, DexMidnightReadsEnableBit?: (boolean | null) | undefined, DexG85CheckEnableBit?: (boolean | null) | undefined, DexDivideBillsBy?: (number | null) | undefined, DexG85CheckParsingFilterEnableBit?: (boolean | null) | undefined, UseCardPriceCorrectCashPriceBit?: (boolean | null) | undefined, MachineTimeZoneOffset?: (number | null) | undefined, DexReadInterval?: (number | null) | undefined, LocationType?: (number | null) | undefined, ApplyDisplayPickListSelectionsToReportsBit?: (boolean | null) | undefined, DisplayPickListSelectionsAs?: (number | null) | undefined, LastUpdated?: (string | null) | undefined, MachineProfile?: (number | null) | undefined, CityID?: (number | null) | undefined, RegionID?: (number | null) | undefined, CountryDialingCode?: (number | null) | undefined, DexIgnoreCRCCheckBit?: (boolean | null) | undefined, DexParseLABit?: (boolean | null) | undefined, ProductMapID?: (number | null) | undefined, Longitude?: (number | null) | undefined, Latitude?: (number | null) | undefined, DexTotalSalesMinusCardSalesBit?: (boolean | null) | undefined, RouteActorID?: (number | null) | undefined, MachineLogicAlertEnableBit?: (boolean | null) | undefined, AlertRuleSetId?: (number | null) | undefined, MachineMemberTypePricingEnableBit?: (boolean | null) | undefined, DexMultiplyCoinsBy?: (number | null) | undefined, DexMultiplyTubesBy?: (number | null) | undefined, CustomerID?: (number | null) | undefined, CommissionType?: (number | null) | undefined, CommissionDefaultValue?: (number | null) | undefined, CreatedBy?: (number | null) | undefined, CreatedOn?: (string | null) | undefined, UpdateBy?: (number | null) | undefined, TubeSource?: (number | null) | undefined, BillSource?: (number | null) | undefined, SmartStickerId?: (number | null) | undefined, EnableRemoveVendBit?: (boolean | null) | undefined, EnableEreceiptBit?: (boolean | null) | undefined, ProductMapAutomaticCreationBit?: (boolean | null) | undefined, Refs?: ({[key: string]: string | null} | null) | undefined}; export type CountryInfo = {Alpha2Code?: string | undefined, Alpha3Code?: string | undefined, Intra?: string | undefined, Name?: string | undefined, NumericCode?: string | undefined}; export type GeoLocation = {Address?: string | undefined, City?: string | undefined, CountryCode?: string | undefined, Latitude?: number | undefined, Longitude?: number | undefined, State?: string | undefined, ZipCode?: string | undefined}; export type ActorInfo = {Country?: CountryInfo | undefined, DynamicURL?: string | undefined, GeoLocation?: GeoLocation | undefined, Id?: number | undefined, MCC?: number | undefined, MerchantId?: string | undefined, Name?: string | undefined, OperatorId?: number | undefined, OperatorName?: string | undefined, SubMerchantId?: string | undefined}; export type CustomData = {Actor?: string | undefined, DirectActor?: string | undefined, Distributor?: string | undefined, Machine?: string | undefined, Operator?: string | undefined, SoftDecline?: string | undefined}; export type CardBrandInfo = {PrimaryDescription?: string | undefined, PrimaryId?: string | undefined, SecondaryDescription?: string | undefined, SecondaryId?: string | undefined}; export type CardData = {BrandInfo?: CardBrandInfo | undefined, CVV2?: string | undefined, CardHolderName?: string | undefined, CardNumber?: string | undefined, EMVData?: string | undefined, EntryMode?: string | undefined, ExpMonth?: string | undefined, ExpYear?: string | undefined, IDNumber?: string | undefined, IsDebitCard?: boolean | undefined, RandomNumber?: string | undefined}; export type PaymentInfo = {SrvTranId?: string | undefined, AuthCode?: string | undefined, AuthAmount?: number | undefined, SettAmount?: number | undefined, RRN?: string | undefined, Token?: string | undefined, AuthDateTime?: string | undefined, SettDateTime?: string | undefined, TraceNumber?: string | undefined, AdditionalData?: string | undefined, IsGatewayTimeout?: boolean | undefined, ProviderExternalData?: string | undefined, InitiateTranReference?: number | undefined, IsRevalueCard?: boolean | undefined}; export type PPVoidRequest = {ReasonCode?: number | undefined, ReasonText?: string | undefined, BasicInfo?: BasicInfo | undefined, DeviceInfo?: DeviceInfo | undefined, MachineInfo?: MachineInfo | undefined, ActorInfo?: ActorInfo | undefined, CustomData?: CustomData | undefined, CardData?: CardData | undefined, PaymentInfo?: PaymentInfo | undefined}; export type CreateApiCortinaPrepaidVoidArgs = {body: PPVoidRequest}; export type CreateApiCortinaPrepaidVoidOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const regularCreditType = z.union([z.literal(0), z.literal(1)]); export const balance = z.object({RegularCredit: z.number().optional(), RegularCreditType: regularCreditType.optional(), RevalueCredit: z.number().int().optional()}); export const paymentInfo = z.object({SrvTranId: z.string().optional(), AuthCode: z.string().optional(), AuthAmount: z.number().optional(), SettAmount: z.number().optional(), RRN: z.string().optional(), Token: z.string().optional(), AuthDateTime: z.string().optional(), SettDateTime: z.string().optional(), TraceNumber: z.string().optional(), AdditionalData: z.string().optional(), IsGatewayTimeout: z.boolean().optional(), ProviderExternalData: z.string().optional(), InitiateTranReference: z.number().int().optional(), IsRevalueCard: z.boolean().optional()}); export const freeInfo = z.array(z.string()); export const posDisplay = z.object({FreeInfo: freeInfo.optional()}); 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 pPVoidResponse = z.object({Balance: balance.optional(), PaymentInfo: paymentInfo.optional(), PosDisplay: posDisplay.optional(), 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 Prepaid Void * * POST /Cortina/Prepaid/Void */ export const createApiCortinaPrepaidVoid = async (args: CreateApiCortinaPrepaidVoidArgs, options?: CreateApiCortinaPrepaidVoidOptions) => { const {baseUrl = "https://example.com:443", 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/Prepaid/Void${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(pPVoidResponse, await res.json()) };