import {z} from 'zod' export type GetApiApiV2TransactionIdArgs = {id: string}; export type GetApiApiV2TransactionIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const amountString = z.string(); export const acquirerAuthorizingNetworkID = z.string(); export const acquirerAuthorizingNetworkIdDescriptor = z.string(); export const acquirerResponseCode = z.string().max(4); export const acquirerResponseMessage = z.string(); export const paymentProductType = z.enum(["Affirm", "Amex", "Crypto", "Diners Club International", "Discover", "JCB", "Klarna", "Maestro", "Mastercard", "OP Online Payment", "Swish", "Unknown", "Visa"]); export const transactionType = z.enum(["AUTHORISATION", "BALANCE", "CANCEL", "CAPTURE", "CARD_ACTIVATION", "CARD_DEACTIVATION", "CARD_VERIFICATION", "CASH_ADVANCE", "CASH_DEPOSIT", "DECLINED", "DELAYED_CHARGE", "EXTEND", "ISSUER_INSTALMENT_SELECTION", "LOAD", "NO_SHOW", "NON_FINANCIAL", "PREAUTH", "PREAUTH_COMPLETION", "PREAUTH_INCREMENT", "RATE", "REAUTHORISATION", "REFUND", "SALE", "UNLOAD", "VOID"]); export const transactionState = z.enum(["APPROVED", "AUTHENTICATING", "AUTHORISED", "AWAITING_INVOICE", "CANCELLED", "CONFIRMED", "COMPLETED", "CUSTOMER_ACCEPTED", "DECLINED", "DEFERRED", "DISPUTED", "EXCEPTION", "EXPIRED", "FAILED", "INITIATED", "ON_HOLD", "PARTIALLY_REFUNDED", "RECEIVED", "RECONCILED", "RECONCILIATION_FAILED", "REFUNDED", "REJECTED", "REPEATING", "REVERSED", "REVERSE_ERROR", "REVERSING", "ROUTING", "SENT", "SETTLED", "SETTLEMENT_FAILED", "SETTLEMENT_REQUESTED", "SUBMITTED", "TIMED_OUT", "UNMATCHED"]); export const cardBrand = z.string(); export const customerDetailsShippingInformationDto = z.object({address: z.string().max(300), city: z.string().max(28), country: z.string().min(2).max(2), postal_code: z.string().min(1).max(16), email: z.string().min(3).max(254).optional(), first_name: z.string().max(100).optional(), last_name: z.string().max(100).optional(), phone: z.string().max(18).optional(), state: z.string().max(35).optional()}); export const customerDetailsDto = z.object({title: z.string().max(120).optional(), first_name: z.string().max(100).optional(), middle_name: z.string().max(100).optional(), last_name: z.string().max(100).optional(), company_name: z.string().max(100).optional(), phone_number: z.string().max(25).optional(), email_address: z.string().optional(), shipping: customerDetailsShippingInformationDto.optional(), billing: z.object({address_1: z.string().max(40).optional(), address_2: z.string().max(40).optional(), address_3: z.string().max(40).optional(), city: z.string().max(28).optional(), country: z.enum(["ZZ", "AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA", "BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV", "BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU", "CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES", "ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM", "GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE", "IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM", "KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY", "MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT", "MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU", "NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA", "RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL", "TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE", "VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW"]).optional(), phone: z.string().max(25).optional(), postal_code: z.string().max(10).optional(), state: z.string().max(35).optional()}).optional(), language: z.string().optional()}); export const tokenDetailsPartial = z.object({reuse_token_type: z.enum(["CHASE", "INTERNAL", "TAVE"]).optional(), reuse_token: z.string().min(14).max(255).optional(), analytics_token: z.string().optional()}); export const listDetailedAmount = z.object({gratuity_amount: amountString.optional(), cashback_amount: amountString.optional(), donation_amount: amountString.optional(), tax_amount: amountString.optional(), surcharge_amount: amountString.optional()}); export const gatewayTransaction = z.object({id: z.string().optional(), amount: amountString.optional(), acquirer_authorizing_network_id: acquirerAuthorizingNetworkID.optional(), acquirer_authorizing_network_id_descriptor: acquirerAuthorizingNetworkIdDescriptor.optional(), acquirer_response_code: acquirerResponseCode.optional(), acquirer_response_message: acquirerResponseMessage.optional(), currency_code: z.enum(["AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BOV", "BRL", "BSD", "BTN", "BWP", "BYR", "BZD", "CAD", "CDF", "CHE", "CHF", "CHW", "CLF", "CLP", "CNY", "COP", "COU", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LTL", "LVL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MUR", "MVR", "MWK", "MXN", "MXV", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "USN", "USS", "UYI", "UYU", "UZS", "VEF", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XBA", "XBB", "XBC", "XBD", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "XTS", "XXX", "YER", "ZAR", "ZMK", "ZMW", "BTC"]).optional(), city: z.string().optional(), country_code: z.string().optional(), created_at: z.string().optional(), customer: z.string().optional(), customer_ip: z.string().max(45).optional(), dynamic_descriptor: z.string().optional(), geo_location: z.array(z.string()).optional(), payment_product: z.string().optional(), payment_product_type: paymentProductType.optional(), processor_reference: z.string().optional(), status: z.string().optional(), transaction_type: transactionType.optional(), transaction_status: transactionState.optional(), parent_id: z.string().optional(), reason_code: z.string().max(4).optional(), card_brand: cardBrand.optional(), shipping_information: z.object({address: z.string().max(300), city: z.string().max(28), country: z.string().min(2).max(2), postal_code: z.string().min(1).max(16), email: z.string().min(3).max(254).optional(), first_name: z.string().max(100).optional(), last_name: z.string().max(100).optional(), phone: z.number().optional(), state: z.string().max(35).optional()}).optional(), customer_details: customerDetailsDto.optional(), merchant_reference: z.string().max(50).optional(), user_agent: z.string().optional(), arn: z.string().optional(), authorization_code: z.string().optional(), avs_result: z.enum(["A", "B", "C", "D", "E", "F", "G", "I", "K", "L", "M", "N", "O", "P", "R", "S", "T", "U", "W", "X", "Y", "Z"]).optional(), created_by: z.string().optional(), cvv_present: z.boolean().optional(), cvv_result: z.enum(["0", "1", "2", "3"]).optional(), processor_payer_id: z.string().optional(), pos_device_id: z.string().optional(), rrn: z.string().optional(), shopper_interaction: z.enum(["ecommerce", "pos", "moto", "mail_order", "telephone_order", "unknown"]).optional(), stan: z.string().max(40).optional(), threed_authentication: z.object({eci_flag: z.enum(["00", "01", "02", "03", "04", "05", "06", "07"]).optional(), enrolled: z.string().optional(), cavv: z.string().max(48).optional(), cavv_algorithm: z.string().optional(), pares_status: z.string().optional(), xid: z.string().optional(), ds_transaction_id: z.string().optional(), threeds_version: z.enum(["1.0.2", "2.1.0", "2.2.0"]).optional()}).optional(), masked_card_number: z.string().max(16).optional(), promo_code: z.string().optional(), payment_summary: z.object({captured_amount: z.string().optional()}).optional(), token_details: tokenDetailsPartial.optional(), entity_id: z.string().optional(), acquirer_merchant_id: z.string().max(36).optional(), description: z.string().optional(), detailed_amount: listDetailedAmount.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 }; /** * Read transaction * * GET /api/v2/transaction/{id} * * Also accepts auth: BearerAuth */ export const getApiApiV2TransactionId = async (args: GetApiApiV2TransactionIdArgs, options?: GetApiApiV2TransactionIdOptions) => { 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 (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/transaction/${encodeURIComponent(String(args.id))}${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(gatewayTransaction, await res.json()) };