import {z} from 'zod' export type Tags = {[key: string]: unknown} | null; export type UpdateMerchantDisableProcessing = {processing_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantDisableSettlements = {settlement_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantEnableBuyerCharges = {convenience_charges_enabled?: boolean | undefined, rent_surcharges_enabled?: boolean | undefined, surcharge_fees_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantEnableL2L3Processing = {level_two_level_three_data_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantEnableLoanRepayment = {loan_repayment?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantEnablePartialAuthorizations = {default_partial_authorization_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantEnableSameDayACH = {disbursements_same_day_ach_pull_enabled?: boolean | undefined, disbursements_same_day_ach_push_enabled?: boolean | undefined, tags?: Tags | undefined}; export type UpdateMerchantSettlementQueue = {settlement_queue_mode?: ('MANUAL' | 'UNSET') | undefined}; export type UpdateMerchantTerminate = {is_terminated?: boolean | undefined, tags?: Tags | undefined, termination_details?: ({description?: string | undefined, reason?: ('CHURNED' | 'COMPLIANCE_VIOLATION' | 'EXCESSIVE_ACH_RETURNS' | 'EXCESSIVE_CHARGEBACKS' | 'FRAUD' | 'IDENTITY_THEFT' | 'ILLEGAL_TRANSACTIONS' | 'INSOLVENCY' | 'OTHER' | 'PCI_VIOLATION' | 'PROCESSOR_MIGRATION' | 'SUSPECTED_FRAUD' | 'UNSUPPORTED_BUSINESS_TYPE' | 'UNUSUAL_ACTIVITY' | 'VIOLATED_MERCHANT_TERMS_OF_SERVICE') | undefined}) | undefined}; export type UpdateApiMerchantsMerchantIdArgs = {body: UpdateMerchantDisableProcessing | UpdateMerchantDisableSettlements | UpdateMerchantEnableBuyerCharges | UpdateMerchantEnableL2L3Processing | UpdateMerchantEnableLoanRepayment | UpdateMerchantEnablePartialAuthorizations | UpdateMerchantEnableSameDayACH | UpdateMerchantSettlementQueue | UpdateMerchantTerminate}; export type UpdateApiMerchantsMerchantIdOptions = {baseUrl?: string | undefined, BasicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const id = z.string().min(1); export const createdAt = z.string(); export const updatedAt = z.string(); export const country = z.enum(["ABW", "AFG", "AGO", "AIA", "ALA", "ALB", "AND", "ARE", "ARG", "ARM", "ASM", "ATA", "ATF", "ATG", "AUS", "AUT", "AZE", "BDI", "BEL", "BEN", "BES", "BFA", "BGD", "BGR", "BHR", "BHS", "BIH", "BLM", "BLR", "BLZ", "BMU", "BOL", "BRA", "BRB", "BRN", "BTN", "BVT", "BWA", "CAF", "CAN", "CCK", "CHE", "CHL", "CHN", "CIV", "CMR", "COD", "COG", "COK", "COL", "COM", "CPV", "CRI", "CUB", "CUW", "CXR", "CYM", "CYP", "CZE", "DEU", "DJI", "DMA", "DNK", "DOM", "DZA", "ECU", "EGY", "ERI", "ESH", "ESP", "EST", "ETH", "FIN", "FJI", "FLK", "FRA", "FRO", "FSM", "GAB", "GBR", "GEO", "GGY", "GHA", "GIB", "GIN", "GLP", "GMB", "GNB", "GNQ", "GRC", "GRD", "GRL", "GTM", "GUF", "GUM", "GUY", "HKG", "HMD", "HND", "HRV", "HTI", "HUN", "IDN", "IMN", "IND", "IOT", "IRL", "IRN", "IRQ", "ISL", "ISR", "ITA", "JAM", "JEY", "JOR", "JPN", "KAZ", "KEN", "KGZ", "KHM", "KIR", "KNA", "KOR", "KWT", "LAO", "LBN", "LBR", "LBY", "LCA", "LIE", "LKA", "LSO", "LTU", "LUX", "LVA", "MAC", "MAF", "MAR", "MCO", "MDA", "MDG", "MDV", "MEX", "MHL", "MKD", "MLI", "MLT", "MMR", "MNE", "MNG", "MNP", "MRT", "MSR", "MTQ", "MUS", "MWI", "MYS", "MYT", "NAM", "NCL", "NER", "NFK", "NGA", "NIC", "NIU", "NLD", "NOR", "NPL", "NRU", "NZL", "OMN", "PAK", "PAN", "PCN", "PER", "PHL", "PLW", "PNG", "POL", "PRI", "PRK", "PRT", "PRY", "PSE", "PYF", "QAT", "REU", "ROU", "RUS", "RWA", "SAU", "SDN", "SEN", "SGP", "SGS", "SHN", "SJM", "SLB", "SLE", "SLV", "SMR", "SOM", "SPM", "SRB", "SSD", "STP", "SUR", "SVK", "SVN", "SWE", "SWZ", "SXM", "SYC", "SYR", "TCA", "TCD", "TGO", "THA", "TJK", "TKL", "TKM", "TLS", "TON", "TTO", "TUN", "TUR", "TUV", "TWN", "TZA", "UGA", "UKR", "UMI", "URY", "USA", "UZB", "VAT", "VCT", "VEN", "VGB", "VIR", "VNM", "VUT", "WLF", "WSM", "XKX", "YEM", "ZAF", "ZMB", "ZWE"]).nullable(); export const currency = z.enum(["CAD", "USD"]); export const refundsDisabledMerchant = z.boolean(); export const tags = z.record(z.string(), z.unknown()).nullable(); export const self = z.object({href: z.string().min(1).optional()}); export const identityLink = z.object({href: z.string().optional()}); export const verifications = z.object({href: z.string().min(1).optional()}); export const merchantProfiles = z.object({href: z.string().optional()}); export const applicationLink = z.object({href: z.string().min(1).optional()}); export const merchant = z.object({id: id.optional(), created_at: createdAt.optional(), updated_at: updatedAt.optional(), application: z.string().min(1).optional(), card_cvv_required: z.boolean().optional(), card_expiration_date_required: z.boolean().optional(), card_network_details: z.object({}).nullable().optional(), convenience_charges_enabled: z.boolean().optional(), country: country.optional(), creating_transfer_from_report_enabled: z.boolean().optional(), currencies: z.array(currency).nullable().optional(), default_partial_authorization_enabled: z.boolean().optional(), disbursements_ach_pull_enabled: z.boolean().optional(), disbursements_ach_push_enabled: z.boolean().optional(), disbursements_card_pull_enabled: z.boolean().optional(), disbursements_card_push_enabled: z.boolean().optional(), disbursements_same_day_ach_pull_enabled: z.boolean().optional(), disbursements_same_day_ach_push_enabled: z.boolean().optional(), fee_ready_to_settle_upon: z.enum(["RECONCILIATION", "SUCCESSFUL_CAPTURE", "PROCESSOR_WINDOW", "CONFIGURABLE_WINDOW"]).optional(), first_approved_at: z.string().nullable().optional(), gateway: z.string().nullable().optional(), gross_settlement_enabled: z.boolean().optional(), identity: z.string().optional(), instant_payouts_card_push_enabled: z.boolean().optional(), is_terminated: z.boolean().optional(), level_two_level_three_data_enabled: z.boolean().optional(), loan_repayment: z.boolean().nullable().optional(), mcc: z.string().nullable().optional(), merchant_name: z.string().optional(), merchant_profile: z.string().optional(), microdeposit_verification_required_buyer: z.boolean().optional(), microdeposit_verification_required_sender: z.boolean().optional(), microdeposit_verification_send_email_enabled: z.boolean().optional(), mid: z.string().nullable().optional(), onboarding_state: z.enum(["APPROVED", "PROVISIONING", "REJECTED", "UPDATE_REQUESTED"]).optional(), processing_enabled: z.boolean().optional(), processor: z.enum(["FINIX_V1", "DUMMY_V1"]).optional(), processor_details: z.object({mid: z.string().optional(), api_key: z.string().optional()}).optional(), pending_refunds_strategy: z.enum(["NONE", "SEVEN_DAY_DELAYED_ADJUSTMENT", "SAME_DAY_ADJUSTMENT"]).nullable().optional(), ready_to_settle_upon: z.enum(["RECONCILIATION", "SUCCESSFUL_CAPTURE", "PROCESSOR_WINDOW", "CONFIGURABLE_WINDOW"]).optional(), ready_to_settle_upon_delay_alignment: z.enum(["ACH", "NONE"]).optional(), refunds_disabled: refundsDisabledMerchant.optional(), rent_surcharges_enabled: z.boolean().optional(), settlement_enabled: z.boolean().optional(), settlement_funding_identifier: z.enum(["UNSET", "MID_AND_DATE", "MID_AND_MERCHANT_NAME"]).optional(), settlement_queue_mode: z.enum(["UNSET", "MANUAL"]).optional(), surcharges_enabled: z.boolean().optional(), tags: tags.optional(), termination_details: z.object({terminated_at: z.string().optional(), reason: z.enum(["CHURNED", "COMPLIANCE_VIOLATION", "EXCESSIVE_ACH_RETURNS", "EXCESSIVE_CHARGEBACKS", "FRAUD", "IDENTITY_THEFT", "ILLEGAL_TRANSACTIONS", "INSOLVENCY", "OTHER", "PCI_VIOLATION", "PROCESSOR_MIGRATION", "SUSPECTED_FRAUD", "UNSUPPORTED_BUSINESS_TYPE", "UNUSUAL_ACTIVITY", "VIOLATED_MERCHANT_TERMS_OF_SERVICE"]).optional(), description: z.string().max(1000).optional(), terminated_by: z.enum(["PLATFORM_USER", "PARTNER_USER"]).optional(), terminated_by_user_id: z.string().optional()}).nullable().optional(), unreferenced_refund_card_present_enabled: z.boolean().optional(), unreferenced_refund_manual_entry_enabled: z.boolean().optional(), verification: z.string().optional(), _links: z.object({self: self.optional(), identity: identityLink.optional(), verifications: verifications.optional(), merchant_profile: merchantProfiles.optional(), merchant_profiles: merchantProfiles.optional(), verification: verifications.optional(), application: applicationLink.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 }; /** * Update a Merchant * * PUT /merchants/{merchant_id} */ export const updateApiMerchantsMerchantId = async (args: UpdateApiMerchantsMerchantIdArgs, options?: UpdateApiMerchantsMerchantIdOptions) => { const {baseUrl = "https://finix.sandbox-payments-api.com", fetch: fetchFn = fetch, BasicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (BasicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${BasicAuth.username}:${BasicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/merchants/${encodeURIComponent(String(args.merchant_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(merchant, await res.json()) };