import {z} from 'zod' export type GetApiTransactionsTransactionIdArgs = {transaction_id: string, filter?: string | undefined}; export type GetApiTransactionsTransactionIdOptions = {baseUrl?: string | undefined, token?: string | undefined, fetch?: typeof fetch | undefined}; export const cardReasons = z.enum(["6012_data", "above_max_amount", "above_max_refund_amount", "above_max_transactions", "acs_technical_issue", "bad_gateway", "below_min_amount", "below_min_refund_amount", "bin_bank", "bin_country", "bin_level", "bin_product", "bin_scheme", "blocklist_bin", "blocklist_card", "blocklist_email", "blocklist_ip", "blocklist_phone", "card_authentication_failed", "card_not_active", "cardholder_cancellation", "cardholder_cancelled", "challenge_failed", "challenge_limit_exceeded", "challenge_not_completed", "challenge_time_out", "closed_account", "exceeds_authentication_frequency_limit", "exceeds_max_amount", "exceeds_max_refund_amount", "exceeds_max_transactions", "expired_card", "fraud_scoring", "fraud_scoring_error", "generic_decline", "insufficient_funds", "invalid_avs", "invalid_card_number", "invalid_cvv", "invalid_pin", "invalid_transaction", "low_confidence", "lost_or_stolen", "max_amount_day", "max_amount_month", "max_card_attempts", "max_card_success", "max_daily_refunds_amount", "max_daily_refunds_count", "max_email_day", "max_email_month", "max_ip_day", "max_ip_month", "max_monthly_refunds_amount", "max_monthly_refunds_count", "max_phone_day", "max_phone_month", "max_post_day", "max_post_month", "max_refunds_count", "medium_confidence", "no_card_record", "restricted_card", "scheme_status_reason", "security_failure", "suspected_fraud", "transaction_disputed", "transaction_fraud", "transaction_not_permitted_to_cardholder"]); export const retryAdvice = z.object({category: z.enum(["update_credentials", "retry_later", "do_not_retry", "token_requirements_not_met", "cancelled", "not_eligible", "scheme_blocked", "card_product_limitations", "customer_action_required", "update_details", "unknown"]).optional(), detail: z.enum(["lifecycle", "policy", "fraud_security", "non_reloadable_prepaid", "single_use_virtual_card", "multi_use_virtual_card", "card_product_not_supported_by_merchant"]).nullable().optional(), retry_after: z.string().nullable().optional(), acquirer_code: z.string().nullable().optional()}).nullable(); export const issuerResponseCodes = z.enum(["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5C", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6P", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9G", "B1", "N0", "N3", "N4", "N7", "P5", "P6", "R0", "R1", "R3", "XA", "XD"]); export const cardMasked = z.object({holder_name: z.string().min(2).max(45).optional(), scheme: z.enum(["visa", "mastercard", "amex"]).optional(), number: z.string().optional(), expiry_month: z.number().int().gte(1).lte(12).optional(), expiry_year: z.number().int().gte(26).lte(56).optional()}); export const bin = z.object({number: z.string().optional(), scheme: z.enum(["visa", "mastercard", "amex"]).optional(), type: z.enum(["charge", "credit", "debit", "deferred_debit", "prepaid"]).optional(), product: z.enum(["consumer", "commercial"]).optional(), card_level: z.enum(["aarp", "acquiring", "advantage", "airmiles", "atm_only", "black", "blue", "bonus", "business", "cash", "centurion", "charge_card", "check_card", "classic", "commerce", "commercial", "corporate", "delta", "diamond", "distribution", "electric_orange", "electron", "electronic", "executive_business", "fleet_card", "flying_blue", "gift", "global_payment", "gm_card", "gold", "government", "green", "gsa", "hsa_non_substantiated", "hsa_substantiated", "icard", "infinite", "interlink", "mastermoney", "new_world", "optima", "ourocard", "payment_card", "paypass_card", "personal", "pin_only", "platinum", "platinum_edge", "plus", "premier_miles", "premium", "prepaid", "private", "professional", "propriety", "purchasing", "q_cash", "quantum", "rebate", "red", "reserved", "revolving", "rewards", "salute", "sears", "signature", "small_business", "standard", "standard_health", "unembossed", "student", "titanium", "top_up_card", "traditional", "travel", "ultimate", "v_pay", "virtual", "world", "healthcare", "prepaid_maestro_travel", "maestro_delayed_debit"]).optional(), issuer: z.string().optional(), issuer_country: z.string().optional(), issuer_country_code: z.string().optional(), eea: z.boolean().optional(), non_reloadable: z.boolean().optional()}); export const address = z.object({line_1: z.string().max(50).optional(), line_2: z.string().max(50).optional(), city: z.string().min(1).max(40).optional(), state: z.string().max(3).optional(), postcode: z.string().min(1).max(40).optional(), country_code: z.enum(["al", "al", "dz", "as", "ad", "ao", "ai", "aq", "ag", "ar", "am", "aw", "au", "at", "az", "bs", "bh", "bd", "bb", "by", "be", "bz", "bj", "bm", "bt", "bo", "ba", "bw", "br", "io", "bn", "bg", "bf", "bi", "cv", "kh", "cm", "ca", "ky", "cf", "td", "cl", "cn", "co", "km", "cg", "cd", "cr", "hr", "cu", "cy", "cz", "dk", "dj", "dm", "do", "ec", "eg", "sv", "gq", "er", "ee", "sz", "et", "fk", "fo", "fj", "fi", "fr", "gf", "pf", "ga", "gm", "ge", "de", "gh", "gi", "gr", "gl", "gd", "gu", "gt", "gg", "gn", "gw", "gy", "ht", "hn", "hk", "hu", "is", "in", "id", "ir", "iq", "ie", "im", "il", "it", "jm", "jp", "je", "jo", "kz", "ke", "ki", "kp", "kr", "kw", "kg", "la", "lv", "lb", "ls", "lr", "ly", "li", "lt", "lu", "mo", "mk", "mg", "mw", "my", "mv", "ml", "mt", "mh", "mq", "mr", "mu", "yt", "mx", "fm", "md", "mc", "mn", "me", "ms", "ma", "mz", "mm", "na", "nr", "np", "nl", "nc", "nz", "ni", "ne", "ng", "nu", "nf", "mp", "no", "om", "pk", "pw", "ps", "pa", "pg", "py", "pe", "ph", "pl", "pt", "pr", "qa", "ro", "ru", "rw", "re", "bl", "sh", "kn", "lc", "mf", "pm", "vc", "ws", "sm", "st", "sa", "sn", "rs", "sc", "sl", "sg", "sx", "sk", "si", "sb", "so", "za", "gs", "ss", "es", "lk", "sd", "sr", "se", "ch", "sx", "sy", "tw", "tj", "tz", "th", "tg", "tk", "to", "tt", "tn", "tr", "tm", "tc", "tv", "ug", "ua", "ae", "gb", "us", "uy", "uz", "vu", "ve", "vn", "vg", "vi", "wf", "eh", "ye", "zm", "zw"]).max(2).optional()}); export const phone = z.object({country_code: z.string().min(1).max(3).optional(), number: z.string().max(15).optional()}); export const customer = z.object({company_id: z.string().optional(), reference: z.string().max(50).optional(), first_name: z.string().max(50).optional(), last_name: z.string().max(50).optional(), dob: z.string().min(10).max(10).optional(), custom_data: z.string().optional(), billing: z.object({address: address.optional(), email: z.string().max(254).optional(), phone: phone.optional()}).optional(), shipping: z.object({address_match: z.boolean().optional(), first_name: z.string().max(50).optional(), last_name: z.string().max(50).optional(), address: address.optional(), email: z.string().max(254).optional(), phone: phone.optional()}).optional(), created: z.string().optional(), last_updated: z.string().optional()}); export const transaction = z.object({transaction_id: z.string().optional(), status: z.enum(["blocked", "declined", "success", "tds_error", "tds_expired", "tds_failed", "settled", "executed", "cancelled", "expired"]).optional(), reason: cardReasons.optional(), mid: z.literal("card").optional(), payment_method: z.enum(["card", "apple_pay", "google_pay", "mastercard_send", "visa_direct", "faster_payment_send", "pay_by_bank", "direct_debit"]).optional(), transaction_type: z.enum(["sale", "authorisation", "capture", "refund", "void", "credit", "account_to_account", "reversal"]).optional(), transaction: z.object({order_id: z.string().min(2).max(50).optional(), amount: z.number().optional(), currency: z.enum(["AED", "AUD", "CAD", "CHF", "CNY", "DKK", "EUR", "GBP", "HKD", "JPY", "MXN", "SEK", "USD", "ZAR"]).optional(), capture: z.boolean().optional(), billing: z.object({subscription_id: z.string().optional(), bill_id: z.string().optional(), recovery_id: z.string().optional()}).optional()}).optional(), check: z.object({avs_line1: z.enum(["matched", "not_matched", "not_checked", "not_provided"]).optional(), avs_postcode: z.enum(["matched", "not_matched", "not_checked", "not_provided"]).optional(), cvv: z.enum(["matched", "not_matched", "not_checked", "not_provided"]).optional()}).optional(), retry_advice: retryAdvice.optional(), tds: z.object({status: z.literal("success").optional(), eci: z.enum(["00", "01", "02", "05", "06", "07"]).optional(), reason: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13), z.literal(14), z.literal(15), z.literal(16), z.literal(17), z.literal(18), z.literal(19), z.literal(20), z.literal(21), z.literal(22), z.literal(23), z.literal(24), z.literal(25), z.literal(26), z.literal(27), z.literal(28)]).optional()}).optional(), issuer_response_code: issuerResponseCodes.optional(), authorization_code: z.string().max(10).optional(), acquirer_reference_number: z.string().optional(), scheme_reference_data: z.string().optional(), transaction_link_id: z.string().max(36).nullable().optional(), card_id: z.string().optional(), payment: z.object({reference: z.string().min(6).max(18).optional(), payee_id: z.string().max(36).optional(), aspsp_id: z.enum(["santander", "bank_of_scotland", "first_direct", "halifax", "hsbc", "lloyds", "monzo", "nationwide", "natwest", "starling_bank", "revolut", "rbs", "tsb"]).optional()}).optional(), payer: z.object({account_name: z.string().min(1).max(50).optional(), account_number: z.string().max(8).optional(), sort_code: z.string().max(6).optional()}).optional(), card: cardMasked.optional(), bin: bin.optional(), customer: customer.optional(), created: z.string().optional(), last_updated: z.string().optional(), credential_on_file: z.enum(["first", "recurring"]).optional(), custom_data: z.string().optional(), custom1: z.string().max(50).optional(), custom2: z.string().max(50).optional(), charge_date: z.string().optional(), is_retryable: z.boolean().optional(), detail: z.object({scheme: z.literal("bacs").optional(), report: z.literal("ARUDD").optional(), reason_code: z.enum(["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B"]).optional(), reason_description: z.enum(["Refer to payer", "Instruction cancelled", "Payer deceased", "Account transferred", "Advance notice disputed", "No account (OR wrong account type", "No instruction", "Amount differs", "Amount not yet due", "Presentation overdue", "Service user differs", "Account closed"]).optional()}).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 }; /** * Retrieve a transaction * * GET /transactions/{transaction_id} */ export const getApiTransactionsTransactionId = async (args: GetApiTransactionsTransactionIdArgs, options?: GetApiTransactionsTransactionIdOptions) => { const {baseUrl = "https://test-api.acquired.com/v1", fetch: fetchFn = fetch, token} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.filter != null) query.append("filter", String(args.filter)) if (token !== undefined) headers.set('authorization', `Bearer ${token}`) const url = `${baseUrl.replace(/\/+$/, '')}/transactions/${encodeURIComponent(String(args.transaction_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(transaction, await res.json()) };