import {z} from 'zod' export type GetApiV23dArgs = {_limit?: number | undefined, _skip?: number | undefined, _sort?: (Array<'_id' | 'amount' | 'card' | 'created_at' | 'currency_code' | 'entity_id' | 'entity_name' | 'threeds_contract_id' | 'transaction_id' | 'authentication.acs_rendering_type' | 'authentication.acs_transaction_id' | 'authentication.acs_url' | 'authentication.authentication_type' | 'authentication.authorization_payload' | 'authentication.card_brand' | 'authentication.cardholder_info' | 'authentication.cavv_algorithm' | 'authentication.cavv' | 'authentication.challenge_cancel' | 'authentication.challenge_required' | 'authentication.ds_transaction_id' | 'authentication.eci_flag' | 'authentication.enrolled' | 'authentication.error_desc' | 'authentication.error_no' | 'authentication.network_score' | 'authentication.order_id' | 'authentication.pares_status' | 'authentication.payload' | 'authentication.reason_code' | 'authentication.reason_desc' | 'authentication.signature_verification' | 'authentication.status_reason' | 'authentication.threeds_version' | 'authentication.xid' | 'authentication.white_list_status' | 'authentication.white_list_status_source' | '-_id' | '-amount' | '-card' | '-created_at' | '-currency_code' | '-entity_id' | '-threeds_contract_id' | '-transaction_id' | '-authentication.acs_rendering_type' | '-authentication.acs_transaction_id' | '-authentication.acs_url' | '-authentication.authentication_type' | '-authentication.authorization_payload' | '-authentication.card_brand' | '-authentication.cardholder_info' | '-authentication.cavv_algorithm' | '-authentication.cavv' | '-authentication.challenge_cancel' | '-authentication.challenge_required' | '-authentication.ds_transaction_id' | '-authentication.eci_flag' | '-authentication.enrolled' | '-authentication.error_desc' | '-authentication.error_no' | '-authentication.network_score' | '-authentication.order_id' | '-authentication.pares_status' | '-authentication.payload' | '-authentication.reason_code' | '-authentication.reason_desc' | '-authentication.signature_verification' | '-authentication.status_reason' | '-authentication.threeds_version' | '-authentication.xid' | '-authentication.white_list_status' | '-authentication.white_list_status_source'>) | undefined, _id?: string | undefined, amount?: number | undefined, card?: string | undefined, created_at?: string | undefined, currency_code?: string | undefined, entity_id?: string | undefined, threeds_contract_id?: string | undefined, transaction_id?: string | undefined, 'authentication.acs_rendering_type'?: string | undefined, 'authentication.acs_transaction_id'?: string | undefined, 'authentication.acs_url'?: string | undefined, 'authentication.authentication_type'?: string | undefined, 'authentication.authorization_payload'?: string | undefined, 'authentication.card_brand'?: string | undefined, 'authentication.cardholder_info'?: string | undefined, 'authentication.cavv_algorithm'?: string | undefined, 'authentication.cavv'?: string | undefined, 'authentication.challenge_cancel'?: ('01' | '02' | '03' | '04' | '05' | '06' | '07' | '8.0') | undefined, 'authentication.challenge_required'?: string | undefined, 'authentication.ds_transaction_id'?: string | undefined, 'authentication.eci_flag'?: string | undefined, 'authentication.enrolled'?: string | undefined, 'authentication.error_desc'?: string | undefined, 'authentication.error_no'?: string | undefined, 'authentication.network_score'?: string | undefined, 'authentication.order_id'?: string | undefined, 'authentication.pares_status'?: string | undefined, 'authentication.payload'?: string | undefined, 'authentication.reason_code'?: string | undefined, 'authentication.reason_desc'?: string | undefined, 'authentication.signature_verification'?: string | undefined, 'authentication.status_reason'?: string | undefined, 'authentication.threeds_version'?: string | undefined, 'authentication.xid'?: string | undefined, encrypted_card?: string | undefined, public_key_alias?: string | undefined, '_id!'?: string | undefined, 'amount!'?: number | undefined, 'card!'?: string | undefined, 'created_at!'?: string | undefined, 'currency_code!'?: string | undefined, 'entity_id!'?: string | undefined, 'threeds_contract_id!'?: string | undefined, 'transaction_id!'?: string | undefined, 'authentication.acs_rendering_type!'?: string | undefined, 'authentication.acs_transaction_id!'?: string | undefined, 'authentication.acs_url!'?: string | undefined, 'authentication.authentication_type!'?: string | undefined, 'authentication.authorization_payload!'?: string | undefined, 'authentication.card_brand!'?: string | undefined, 'authentication.cardholder_info!'?: string | undefined, 'authentication.cavv_algorithm!'?: string | undefined, 'authentication.cavv!'?: string | undefined, 'authentication.challenge_cancel!'?: ('01' | '02' | '03' | '04' | '05' | '06' | '07' | '8.0') | undefined, 'authentication.challenge_required!'?: string | undefined, 'authentication.ds_transaction_id!'?: string | undefined, 'authentication.eci_flag!'?: string | undefined, 'authentication.enrolled!'?: string | undefined, 'authentication.error_desc!'?: string | undefined, 'authentication.error_no!'?: string | undefined, 'authentication.network_score!'?: string | undefined, 'authentication.order_id!'?: string | undefined, 'authentication.pares_status!'?: string | undefined, 'authentication.payload!'?: string | undefined, 'authentication.reason_code!'?: string | undefined, 'authentication.reason_desc!'?: string | undefined, 'authentication.signature_verification!'?: string | undefined, 'authentication.status_reason!'?: string | undefined, 'authentication.threeds_version!'?: string | undefined, 'authentication.xid!'?: string | undefined, 'encrypted_card!'?: string | undefined, 'public_key_alias!'?: string | undefined, '_id~'?: string | undefined, 'card~'?: string | undefined, 'currency_code~'?: string | undefined, 'entity_id~'?: string | undefined, 'threeds_contract_id~'?: string | undefined, 'transaction_id~'?: string | undefined, 'authentication.acs_rendering_type~'?: string | undefined, 'authentication.acs_transaction_id~'?: string | undefined, 'authentication.acs_url~'?: string | undefined, 'authentication.authentication_type~'?: string | undefined, 'authentication.authorization_payload~'?: string | undefined, 'authentication.card_brand~'?: string | undefined, 'authentication.cardholder_info~'?: string | undefined, 'authentication.cavv_algorithm~'?: string | undefined, 'authentication.cavv~'?: string | undefined, 'authentication.challenge_cancel~'?: ('01' | '02' | '03' | '04' | '05' | '06' | '07' | '8.0') | undefined, 'authentication.challenge_required~'?: string | undefined, 'authentication.ds_transaction_id~'?: string | undefined, 'authentication.eci_flag~'?: string | undefined, 'authentication.enrolled~'?: string | undefined, 'authentication.error_desc~'?: string | undefined, 'authentication.error_no~'?: string | undefined, 'authentication.network_score~'?: string | undefined, 'authentication.order_id~'?: string | undefined, 'authentication.pares_status~'?: string | undefined, 'authentication.payload~'?: string | undefined, 'authentication.reason_code~'?: string | undefined, 'authentication.reason_desc~'?: string | undefined, 'authentication.signature_verification~'?: string | undefined, 'authentication.status_reason~'?: string | undefined, 'authentication.threeds_version~'?: string | undefined, 'authentication.xid~'?: string | undefined, 'encrypted_card~'?: string | undefined, 'public_key_alias~'?: string | undefined, 'amount>'?: number | undefined, 'created_at>'?: string | undefined, 'amount<'?: number | undefined, 'created_at<'?: string | undefined}; export type GetApiV23dOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const authenticationResult = z.object({threeds_version: z.string().optional(), enrolled: z.string().optional(), error_desc: z.string().optional(), error_no: z.string().optional(), order_id: z.string().optional(), eci_flag: z.string().optional(), signature_verification: z.string().optional(), ds_transaction_id: z.string().optional(), acs_url: z.string().optional(), card_brand: z.string().optional(), network_score: z.string().max(2).optional(), challenge_cancel: z.enum(["01", "02", "03", "04", "05", "06", "07", "8.0"]).optional(), authorization_payload: z.string().optional(), cavv: z.string().optional(), cavv_algorithm: z.string().optional(), pares_status: z.string().optional(), payload: z.string().optional(), xid: z.string().optional(), reason_code: z.string().optional(), reason_desc: z.string().optional(), cardholder_info: z.string().optional(), acs_rendering_type: z.string().optional(), acs_transaction_id: z.string().optional(), authentication_type: z.string().optional(), challenge_required: z.string().optional(), status_reason: z.string().optional()}); export const threeDSAuthentication = z.object({_id: z.string().optional(), amount: z.number().lte(9007199254740991).optional(), threeds_contract_id: z.string().optional(), authentication: authenticationResult.optional(), card: z.string().optional(), currency_code: z.string().min(3).max(3).optional(), created_at: z.string().optional(), entity_id: z.string().optional(), transaction_id: z.string().optional()}); export const threeDSAuthenticationList = z.array(threeDSAuthentication); 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 ThreeDSAuthentications * * GET /v2/3d * * Also accepts auth: BearerAuth */ export const getApiV23d = async (args: GetApiV23dArgs, options?: GetApiV23dOptions) => { const {baseUrl = "https://emea.gsc.verifone.cloud/oidc/checkout-service", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args._limit != null) query.append("_limit", String(args._limit)) if (args._skip != null) query.append("_skip", String(args._skip)) for (const item of args._sort ?? []) query.append("_sort", String(item)) if (args._id != null) query.append("_id", String(args._id)) if (args.amount != null) query.append("amount", String(args.amount)) if (args.card != null) query.append("card", String(args.card)) if (args.created_at != null) query.append("created_at", String(args.created_at)) if (args.currency_code != null) query.append("currency_code", String(args.currency_code)) if (args.entity_id != null) query.append("entity_id", String(args.entity_id)) if (args.threeds_contract_id != null) query.append("threeds_contract_id", String(args.threeds_contract_id)) if (args.transaction_id != null) query.append("transaction_id", String(args.transaction_id)) if (args['authentication.acs_rendering_type'] != null) query.append("authentication.acs_rendering_type", String(args['authentication.acs_rendering_type'])) if (args['authentication.acs_transaction_id'] != null) query.append("authentication.acs_transaction_id", String(args['authentication.acs_transaction_id'])) if (args['authentication.acs_url'] != null) query.append("authentication.acs_url", String(args['authentication.acs_url'])) if (args['authentication.authentication_type'] != null) query.append("authentication.authentication_type", String(args['authentication.authentication_type'])) if (args['authentication.authorization_payload'] != null) query.append("authentication.authorization_payload", String(args['authentication.authorization_payload'])) if (args['authentication.card_brand'] != null) query.append("authentication.card_brand", String(args['authentication.card_brand'])) if (args['authentication.cardholder_info'] != null) query.append("authentication.cardholder_info", String(args['authentication.cardholder_info'])) if (args['authentication.cavv_algorithm'] != null) query.append("authentication.cavv_algorithm", String(args['authentication.cavv_algorithm'])) if (args['authentication.cavv'] != null) query.append("authentication.cavv", String(args['authentication.cavv'])) if (args['authentication.challenge_cancel'] != null) query.append("authentication.challenge_cancel", String(args['authentication.challenge_cancel'])) if (args['authentication.challenge_required'] != null) query.append("authentication.challenge_required", String(args['authentication.challenge_required'])) if (args['authentication.ds_transaction_id'] != null) query.append("authentication.ds_transaction_id", String(args['authentication.ds_transaction_id'])) if (args['authentication.eci_flag'] != null) query.append("authentication.eci_flag", String(args['authentication.eci_flag'])) if (args['authentication.enrolled'] != null) query.append("authentication.enrolled", String(args['authentication.enrolled'])) if (args['authentication.error_desc'] != null) query.append("authentication.error_desc", String(args['authentication.error_desc'])) if (args['authentication.error_no'] != null) query.append("authentication.error_no", String(args['authentication.error_no'])) if (args['authentication.network_score'] != null) query.append("authentication.network_score", String(args['authentication.network_score'])) if (args['authentication.order_id'] != null) query.append("authentication.order_id", String(args['authentication.order_id'])) if (args['authentication.pares_status'] != null) query.append("authentication.pares_status", String(args['authentication.pares_status'])) if (args['authentication.payload'] != null) query.append("authentication.payload", String(args['authentication.payload'])) if (args['authentication.reason_code'] != null) query.append("authentication.reason_code", String(args['authentication.reason_code'])) if (args['authentication.reason_desc'] != null) query.append("authentication.reason_desc", String(args['authentication.reason_desc'])) if (args['authentication.signature_verification'] != null) query.append("authentication.signature_verification", String(args['authentication.signature_verification'])) if (args['authentication.status_reason'] != null) query.append("authentication.status_reason", String(args['authentication.status_reason'])) if (args['authentication.threeds_version'] != null) query.append("authentication.threeds_version", String(args['authentication.threeds_version'])) if (args['authentication.xid'] != null) query.append("authentication.xid", String(args['authentication.xid'])) if (args.encrypted_card != null) query.append("encrypted_card", String(args.encrypted_card)) if (args.public_key_alias != null) query.append("public_key_alias", String(args.public_key_alias)) if (args['_id!'] != null) query.append("_id!", String(args['_id!'])) if (args['amount!'] != null) query.append("amount!", String(args['amount!'])) if (args['card!'] != null) query.append("card!", String(args['card!'])) if (args['created_at!'] != null) query.append("created_at!", String(args['created_at!'])) if (args['currency_code!'] != null) query.append("currency_code!", String(args['currency_code!'])) if (args['entity_id!'] != null) query.append("entity_id!", String(args['entity_id!'])) if (args['threeds_contract_id!'] != null) query.append("threeds_contract_id!", String(args['threeds_contract_id!'])) if (args['transaction_id!'] != null) query.append("transaction_id!", String(args['transaction_id!'])) if (args['authentication.acs_rendering_type!'] != null) query.append("authentication.acs_rendering_type!", String(args['authentication.acs_rendering_type!'])) if (args['authentication.acs_transaction_id!'] != null) query.append("authentication.acs_transaction_id!", String(args['authentication.acs_transaction_id!'])) if (args['authentication.acs_url!'] != null) query.append("authentication.acs_url!", String(args['authentication.acs_url!'])) if (args['authentication.authentication_type!'] != null) query.append("authentication.authentication_type!", String(args['authentication.authentication_type!'])) if (args['authentication.authorization_payload!'] != null) query.append("authentication.authorization_payload!", String(args['authentication.authorization_payload!'])) if (args['authentication.card_brand!'] != null) query.append("authentication.card_brand!", String(args['authentication.card_brand!'])) if (args['authentication.cardholder_info!'] != null) query.append("authentication.cardholder_info!", String(args['authentication.cardholder_info!'])) if (args['authentication.cavv_algorithm!'] != null) query.append("authentication.cavv_algorithm!", String(args['authentication.cavv_algorithm!'])) if (args['authentication.cavv!'] != null) query.append("authentication.cavv!", String(args['authentication.cavv!'])) if (args['authentication.challenge_cancel!'] != null) query.append("authentication.challenge_cancel!", String(args['authentication.challenge_cancel!'])) if (args['authentication.challenge_required!'] != null) query.append("authentication.challenge_required!", String(args['authentication.challenge_required!'])) if (args['authentication.ds_transaction_id!'] != null) query.append("authentication.ds_transaction_id!", String(args['authentication.ds_transaction_id!'])) if (args['authentication.eci_flag!'] != null) query.append("authentication.eci_flag!", String(args['authentication.eci_flag!'])) if (args['authentication.enrolled!'] != null) query.append("authentication.enrolled!", String(args['authentication.enrolled!'])) if (args['authentication.error_desc!'] != null) query.append("authentication.error_desc!", String(args['authentication.error_desc!'])) if (args['authentication.error_no!'] != null) query.append("authentication.error_no!", String(args['authentication.error_no!'])) if (args['authentication.network_score!'] != null) query.append("authentication.network_score!", String(args['authentication.network_score!'])) if (args['authentication.order_id!'] != null) query.append("authentication.order_id!", String(args['authentication.order_id!'])) if (args['authentication.pares_status!'] != null) query.append("authentication.pares_status!", String(args['authentication.pares_status!'])) if (args['authentication.payload!'] != null) query.append("authentication.payload!", String(args['authentication.payload!'])) if (args['authentication.reason_code!'] != null) query.append("authentication.reason_code!", String(args['authentication.reason_code!'])) if (args['authentication.reason_desc!'] != null) query.append("authentication.reason_desc!", String(args['authentication.reason_desc!'])) if (args['authentication.signature_verification!'] != null) query.append("authentication.signature_verification!", String(args['authentication.signature_verification!'])) if (args['authentication.status_reason!'] != null) query.append("authentication.status_reason!", String(args['authentication.status_reason!'])) if (args['authentication.threeds_version!'] != null) query.append("authentication.threeds_version!", String(args['authentication.threeds_version!'])) if (args['authentication.xid!'] != null) query.append("authentication.xid!", String(args['authentication.xid!'])) if (args['encrypted_card!'] != null) query.append("encrypted_card!", String(args['encrypted_card!'])) if (args['public_key_alias!'] != null) query.append("public_key_alias!", String(args['public_key_alias!'])) if (args['_id~'] != null) query.append("_id~", String(args['_id~'])) if (args['card~'] != null) query.append("card~", String(args['card~'])) if (args['currency_code~'] != null) query.append("currency_code~", String(args['currency_code~'])) if (args['entity_id~'] != null) query.append("entity_id~", String(args['entity_id~'])) if (args['threeds_contract_id~'] != null) query.append("threeds_contract_id~", String(args['threeds_contract_id~'])) if (args['transaction_id~'] != null) query.append("transaction_id~", String(args['transaction_id~'])) if (args['authentication.acs_rendering_type~'] != null) query.append("authentication.acs_rendering_type~", String(args['authentication.acs_rendering_type~'])) if (args['authentication.acs_transaction_id~'] != null) query.append("authentication.acs_transaction_id~", String(args['authentication.acs_transaction_id~'])) if (args['authentication.acs_url~'] != null) query.append("authentication.acs_url~", String(args['authentication.acs_url~'])) if (args['authentication.authentication_type~'] != null) query.append("authentication.authentication_type~", String(args['authentication.authentication_type~'])) if (args['authentication.authorization_payload~'] != null) query.append("authentication.authorization_payload~", String(args['authentication.authorization_payload~'])) if (args['authentication.card_brand~'] != null) query.append("authentication.card_brand~", String(args['authentication.card_brand~'])) if (args['authentication.cardholder_info~'] != null) query.append("authentication.cardholder_info~", String(args['authentication.cardholder_info~'])) if (args['authentication.cavv_algorithm~'] != null) query.append("authentication.cavv_algorithm~", String(args['authentication.cavv_algorithm~'])) if (args['authentication.cavv~'] != null) query.append("authentication.cavv~", String(args['authentication.cavv~'])) if (args['authentication.challenge_cancel~'] != null) query.append("authentication.challenge_cancel~", String(args['authentication.challenge_cancel~'])) if (args['authentication.challenge_required~'] != null) query.append("authentication.challenge_required~", String(args['authentication.challenge_required~'])) if (args['authentication.ds_transaction_id~'] != null) query.append("authentication.ds_transaction_id~", String(args['authentication.ds_transaction_id~'])) if (args['authentication.eci_flag~'] != null) query.append("authentication.eci_flag~", String(args['authentication.eci_flag~'])) if (args['authentication.enrolled~'] != null) query.append("authentication.enrolled~", String(args['authentication.enrolled~'])) if (args['authentication.error_desc~'] != null) query.append("authentication.error_desc~", String(args['authentication.error_desc~'])) if (args['authentication.error_no~'] != null) query.append("authentication.error_no~", String(args['authentication.error_no~'])) if (args['authentication.network_score~'] != null) query.append("authentication.network_score~", String(args['authentication.network_score~'])) if (args['authentication.order_id~'] != null) query.append("authentication.order_id~", String(args['authentication.order_id~'])) if (args['authentication.pares_status~'] != null) query.append("authentication.pares_status~", String(args['authentication.pares_status~'])) if (args['authentication.payload~'] != null) query.append("authentication.payload~", String(args['authentication.payload~'])) if (args['authentication.reason_code~'] != null) query.append("authentication.reason_code~", String(args['authentication.reason_code~'])) if (args['authentication.reason_desc~'] != null) query.append("authentication.reason_desc~", String(args['authentication.reason_desc~'])) if (args['authentication.signature_verification~'] != null) query.append("authentication.signature_verification~", String(args['authentication.signature_verification~'])) if (args['authentication.status_reason~'] != null) query.append("authentication.status_reason~", String(args['authentication.status_reason~'])) if (args['authentication.threeds_version~'] != null) query.append("authentication.threeds_version~", String(args['authentication.threeds_version~'])) if (args['authentication.xid~'] != null) query.append("authentication.xid~", String(args['authentication.xid~'])) if (args['encrypted_card~'] != null) query.append("encrypted_card~", String(args['encrypted_card~'])) if (args['public_key_alias~'] != null) query.append("public_key_alias~", String(args['public_key_alias~'])) if (args['amount>'] != null) query.append("amount>", String(args['amount>'])) if (args['created_at>'] != null) query.append("created_at>", String(args['created_at>'])) if (args['amount<'] != null) query.append("amount<", String(args['amount<'])) if (args['created_at<'] != null) query.append("created_at<", String(args['created_at<'])) if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/3d${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(threeDSAuthenticationList, await res.json()) };