import {z} from 'zod' export type GetApiAccountsAccountIdArgs = {account_id: string}; export type GetApiAccountsAccountIdOptions = {baseUrl: string, adminApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const countryAlpha2 = z.enum(["AF", "AX", "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", "BQ", "BA", "BW", "BV", "BR", "IO", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "VA", "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", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "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", "SJ", "SZ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UG", "UA", "AE", "GB", "UM", "UY", "UZ", "VU", "VE", "VN", "VG", "VI", "WF", "EH", "YE", "ZM", "ZW", "US"]); export const addressDetails = z.object({city: z.string().max(50).nullable().optional(), country: countryAlpha2.nullable().optional(), line1: z.string().max(200).nullable().optional(), line2: z.string().max(50).nullable().optional(), line3: z.string().max(50).nullable().optional(), zip: z.string().max(50).nullable().optional(), state: z.string().nullable().optional(), first_name: z.string().max(255).nullable().optional(), last_name: z.string().max(255).nullable().optional(), origin_zip: z.string().max(50).nullable().optional()}); export const merchantDetails = z.object({primary_contact_person: z.string().max(255).nullable().optional(), primary_phone: z.string().max(255).nullable().optional(), primary_email: z.string().max(255).nullable().optional(), secondary_contact_person: z.string().max(255).nullable().optional(), secondary_phone: z.string().max(255).nullable().optional(), secondary_email: z.string().max(255).nullable().optional(), website: z.string().max(255).nullable().optional(), about_business: z.string().max(255).nullable().optional(), address: addressDetails.nullable().optional(), merchant_tax_registration_id: z.string().nullable().optional()}); export const intentStatus = z.enum(["succeeded", "failed", "cancelled", "cancelled_post_capture", "processing", "requires_customer_action", "requires_merchant_action", "requires_payment_method", "requires_confirmation", "requires_capture", "partially_captured", "partially_captured_and_capturable", "partially_authorized_and_requires_capture", "partially_captured_and_processing", "conflicted", "expired", "review"]); export const payoutStatus = z.enum(["success", "failed", "cancelled", "initiated", "expired", "reversed", "pending", "ineligible", "requires_creation", "requires_confirmation", "requires_payout_method_data", "requires_fulfillment", "requires_vendor_account_creation"]); export const webhookDetails = z.object({webhook_version: z.string().max(255).nullable().optional(), webhook_username: z.string().max(255).nullable().optional(), webhook_password: z.string().max(255).nullable().optional(), webhook_url: z.string().nullable().optional(), payment_created_enabled: z.boolean().nullable().optional(), payment_succeeded_enabled: z.boolean().nullable().optional(), payment_failed_enabled: z.boolean().nullable().optional(), payment_statuses_enabled: z.array(intentStatus), refund_statuses_enabled: z.array(intentStatus), payout_statuses_enabled: z.array(payoutStatus).nullable().optional()}); export const routableConnectors = z.enum(["absa_sanlam", "authipay", "adyenplatform", "stripe_billing_test", "phonypay", "fauxpay", "pretendpay", "stripe_test", "adyen_test", "checkout_test", "paypal_test", "aci", "adyen", "affirm", "airwallex", "amazonpay", "archipel", "authorizedotnet", "bankofamerica", "barclaycard", "billwerk", "bitpay", "bambora", "blackhawknetwork", "bamboraapac", "bluesnap", "calida", "boku", "braintree", "breadpay", "cashtocode", "celero", "chargebee", "custombilling", "checkbook", "checkout", "coinbase", "coingate", "cryptopay", "cybersource", "cybersourcedecisionmanager", "datatrans", "deutschebank", "digitalvirgo", "dlocal", "dwolla", "ebanx", "elavon", "envoy", "facilitapay", "finix", "fiserv", "fiservemea", "fiservcommercehub", "fiuu", "flexiti", "forte", "getnet", "gigadat", "givepayments", "globalpay", "globepay", "gocardless", "hipay", "helcim", "hyperpg", "iatapay", "imerchantsolutions", "inespay", "interpayments", "itaubank", "jpmorgan", "klarna", "loonio", "mifinity", "mollie", "moneris", "multisafepay", "nexinets", "nexixpay", "nmi", "nomupay", "noon", "nordea", "novalnet", "nuvei", "opennode", "paybox", "payme", "payload", "payone", "paypal", "paysafe", "paystack", "paytm", "payconex", "payu", "peachpayments", "payjustnow", "payjustnowinstore", "phonepe", "placetopay", "powertranz", "prophetpay", "rapyd", "razorpay", "recurly", "redsys", "revolv3", "riskified", "santander", "shift4", "signifyd", "silverflow", "square", "stax", "stripe", "stripebilling", "tesouro", "truelayer", "trustly", "trustpay", "trustpayments", "tokenio", "tsys", "tsys_transit", "volt", "wellsfargo", "wise", "worldline", "worldpay", "worldpaymodular", "worldpayvantiv", "worldpayxml", "xendit", "zen", "zift", "plaid", "zsl", "juspaythreedsserver", "ctp_mastercard", "ctp_visa", "netcetera", "cardinal", "threedsecureio"]); export const routableConnectorChoice = z.object({connector: routableConnectors, merchant_connector_id: z.string().nullable().optional()}); export const connectorVolumeSplit = z.object({connector: routableConnectorChoice, split: z.number().int().gte(0)}); export const connectorSelection = z.discriminatedUnion("type", [z.object({type: z.literal("priority"), data: z.array(routableConnectorChoice)}), z.object({type: z.literal("volume_split"), data: z.array(connectorVolumeSplit)})]); export const ruleConnectorSelection = z.object({}); export const programConnectorSelection = z.object({defaultSelection: connectorSelection, rules: ruleConnectorSelection, metadata: z.record(z.string(), z.unknown())}); export const threeDSDecisionRule = z.unknown(); export const ruleThreeDsDecisionRule = z.unknown(); export const programThreeDsDecisionRule = z.object({defaultSelection: threeDSDecisionRule, rules: ruleThreeDsDecisionRule, metadata: z.record(z.string(), z.unknown())}); export const staticRoutingAlgorithm = z.discriminatedUnion("type", [z.object({type: z.literal("single"), data: routableConnectorChoice}), z.object({type: z.literal("priority"), data: z.array(routableConnectorChoice)}), z.object({type: z.literal("volume_split"), data: z.array(connectorVolumeSplit)}), z.object({type: z.literal("advanced"), data: programConnectorSelection}), z.object({type: z.literal("three_ds_decision_rule"), data: programThreeDsDecisionRule})]); export const primaryBusinessDetails = z.object({country: countryAlpha2, business: z.string()}); export const reconStatus = z.enum(["not_requested", "requested", "active", "disabled"]); export const paymentMethod = z.enum(["card", "card_redirect", "pay_later", "wallet", "bank_redirect", "bank_transfer", "crypto", "bank_debit", "reward", "real_time_payment", "upi", "voucher", "gift_card", "open_banking", "mobile_payment", "network_token"]); export const paymentMethodType = z.enum(["ach", "affirm", "afterpay_clearpay", "alfamart", "ali_pay", "ali_pay_hk", "alma", "amazon_pay", "paysera", "apple_pay", "atome", "bacs", "bancontact_card", "becs", "benefit", "bizum", "blik", "bluecode", "boleto", "bca_bank_transfer", "bni_va", "breadpay", "bri_va", "bhn_card_network", "card_redirect", "cimb_va", "classic", "credit", "crypto_currency", "cashapp", "dana", "danamon_va", "debit", "duit_now", "efecty", "eft", "eft_debit_order", "eps", "flexiti", "fps", "evoucher", "giropay", "givex", "google_pay", "go_pay", "gcash", "ideal", "interac", "indomaret", "klarna", "kakao_pay", "local_bank_redirect", "mandiri_va", "knet", "mb_way", "mobile_pay", "momo", "momo_atm", "multibanco", "online_banking_thailand", "online_banking_czech_republic", "online_banking_finland", "online_banking_fpx", "online_banking_poland", "online_banking_slovakia", "oxxo", "pago_efectivo", "permata_bank_transfer", "open_banking_uk", "pay_bright", "payjustnow", "paypal", "paze", "pix", "pix_key", "pix_emv", "pix_qr", "pix_automatico_qr", "pix_automatico_push", "pay_safe_card", "przelewy24", "prompt_pay", "pse", "qris", "red_compra", "red_pagos", "samsung_pay", "sepa", "sepa_bank_transfer", "sepa_guarenteed_debit", "skrill", "sofort", "swish", "touch_n_go", "trustly", "twint", "upi_collect", "upi_intent", "upi_qr", "vipps", "viet_qr", "venmo", "walley", "we_chat_pay", "seven_eleven", "lawson", "mini_stop", "family_mart", "seicomart", "pay_easy", "local_bank_transfer", "mifinity", "open_banking_pis", "direct_carrier_billing", "instant_bank_transfer", "instant_bank_transfer_finland", "instant_bank_transfer_poland", "revolut_pay", "indonesian_bank_transfer", "open_banking", "network_token"]); export const enabledPaymentMethod = z.object({payment_method: paymentMethod, payment_method_types: z.array(paymentMethodType)}); export const businessCollectLinkConfig = z.object({logo: z.string().max(255).nullable().optional(), merchant_name: z.string().max(255).nullable().optional(), theme: z.string().max(255).nullable().optional(), domain_name: z.string().nullable().optional(), allowed_domains: z.array(z.string()), enabled_payment_methods: z.array(enabledPaymentMethod)}); export const merchantProductType = z.enum(["orchestration", "vault", "recon", "recovery", "cost_observability", "dynamic_routing"]); export const merchantAccountType = z.enum(["standard", "platform", "connected"]); export const internalNetworkTokenizationCredentials = z.object({token_service_api_key: z.string().max(255), public_key: z.string().max(255), private_key: z.string().max(255), key_id: z.string().max(255)}); export const networkTokeizationProviderCredentials = z.object({internal_network_token_service: internalNetworkTokenizationCredentials}); export const merchantAccountResponse = z.object({merchant_id: z.string().max(64), merchant_name: z.string().nullable().optional(), return_url: z.string().max(255).nullable().optional(), enable_payment_response_hash: z.boolean(), payment_response_hash_key: z.string().max(255).nullable().optional(), redirect_to_merchant_with_http_post: z.boolean(), merchant_details: merchantDetails.nullable().optional(), webhook_details: webhookDetails.nullable().optional(), payout_routing_algorithm: staticRoutingAlgorithm.nullable().optional(), sub_merchants_enabled: z.boolean().nullable().optional(), parent_merchant_id: z.string().max(255).nullable().optional(), publishable_key: z.string().nullable().optional(), metadata: z.object({}).nullable().optional(), locker_id: z.string().nullable().optional(), primary_business_details: z.array(primaryBusinessDetails), frm_routing_algorithm: staticRoutingAlgorithm.nullable().optional(), organization_id: z.string().min(1).max(64), is_recon_enabled: z.boolean(), default_profile: z.string().max(64).nullable().optional(), recon_status: reconStatus, pm_collect_link_config: businessCollectLinkConfig.nullable().optional(), product_type: merchantProductType.nullable().optional(), merchant_account_type: merchantAccountType, network_tokenization_credentials: networkTokeizationProviderCredentials.nullable().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 }; /** * Merchant Account - Retrieve * * GET /accounts/{account_id} */ export const getApiAccountsAccountId = async (args: GetApiAccountsAccountIdArgs, options: GetApiAccountsAccountIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, adminApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (adminApiKey !== undefined) headers.set("api-key", adminApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/accounts/${encodeURIComponent(String(args.account_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(merchantAccountResponse, await res.json()) };