import {z} from 'zod' export type AcceptorKey = string; export type ExtendedFreeTextField = string; export type Mid = string; export type Mcc = string; export type DoingBusinessAsName = string; export type NullableWebshopUrl = string | null; export type CountryCodeAlpha3 = string; export type CountryCodeOnlyAlpha3 = {alpha3: CountryCodeAlpha3}; export type CountryCodeAlpha2 = string; export type CountryCodeOnlyAlpha2 = {alpha2: CountryCodeAlpha2}; export type CountryCodeNumeric = string; export type CountryCodeOnlyNumeric = {numeric: CountryCodeNumeric}; export type CountryCodeCreate = CountryCodeOnlyAlpha3 | CountryCodeOnlyAlpha2 | CountryCodeOnlyNumeric; export type StateOrProvince = string; export type City = string; export type Line1 = string; export type Line2 = string; export type PostalCode = string; export type AddressCreate = {countryCode: CountryCodeCreate, stateOrProvince?: StateOrProvince | undefined, city: City, line1: Line1, line2?: Line2 | undefined, postalCode: PostalCode}; export type Null = Record | null; export type NullableAddress = AddressCreate | Null; export type NullableNetworkAssignedId = string | null; export type BinKeyRef = string; export type NullableAcquirerOrPayFacBusinessId = string | null; export type NullableSubMerchantId = string | null; export type NullableSubMerchantAddress = AddressCreate | Null; export type NullableIsoId = string | null; export type NullableGatewayId = string | null; export type NullableForeignRetailer = boolean | null; export type NullableMarketplaceId = string | null; export type NullableRampProviderId = string | null; export type AcceptorRestriction = {suspendPayouts?: boolean | undefined, blockCharges?: boolean | undefined}; export type AcceptorRestrictions = Array; export type NullableChargesBlocked = boolean | null; export type Tags = {[key: string]: string}; export type NullableTags = Tags | Null; export type DisputeHandling = {autoDefense: boolean}; export type NullableDisputeHandling = DisputeHandling | Null; export type NullableReference = string | null; export type NullableRoute = string | null; export type NullableMerchantVolumeIndicator = string | null; export type AuthorizationCurrencyForAmexDirectMerchant = 'EUR' | 'USD' | 'AFN' | 'ALL' | 'DZD' | 'AOA' | 'XCD' | 'ARS' | 'AMD' | 'AWG' | 'AUD' | 'AZN' | 'BSD' | 'BHD' | 'BDT' | 'BBD' | 'BYN' | 'BZD' | 'XOF' | 'BMD' | 'INR' | 'BTN' | 'BOB' | 'BAM' | 'BWP' | 'NOK' | 'BRL' | 'BND' | 'BGN' | 'BIF' | 'CVE' | 'KHR' | 'XAF' | 'CAD' | 'KYD' | 'CLP' | 'CNY' | 'CNH' | 'COP' | 'KMF' | 'CDF' | 'NZD' | 'CRC' | 'HRK' | 'CUP' | 'CUC' | 'ANG' | 'CZK' | 'DKK' | 'DJF' | 'DOP' | 'EGP' | 'SVC' | 'ERN' | 'ETB' | 'FKP' | 'FJD' | 'XPF' | 'GMD' | 'GEL' | 'GHS' | 'GIP' | 'GTQ' | 'GBP' | 'GNF' | 'GYD' | 'HTG' | 'HNL' | 'HKD' | 'HUF' | 'ISK' | 'IDR' | 'IRR' | 'IQD' | 'ILS' | 'JMD' | 'JPY' | 'JOD' | 'KZT' | 'KES' | 'KPW' | 'KRW' | 'KWD' | 'KGS' | 'LAK' | 'LBP' | 'LSL' | 'ZAR' | 'LRD' | 'LYD' | 'CHF' | 'MOP' | 'MKD' | 'MGA' | 'MWK' | 'MYR' | 'MVR' | 'MRU' | 'MUR' | 'MXN' | 'MDL' | 'MNT' | 'MAD' | 'MZN' | 'MMK' | 'NAD' | 'NPR' | 'NIO' | 'NGN' | 'OMR' | 'PKR' | 'PAB' | 'PGK' | 'PYG' | 'PEN' | 'PHP' | 'PLN' | 'QAR' | 'RON' | 'RUB' | 'RWF' | 'SHP' | 'WST' | 'STN' | 'SAR' | 'RSD' | 'SCR' | 'SLL' | 'SLE' | 'SGD' | 'SBD' | 'SOS' | 'SSP' | 'LKR' | 'SDG' | 'SRD' | 'SZL' | 'SEK' | 'SYP' | 'TWD' | 'TJS' | 'TZS' | 'THB' | 'TOP' | 'TTD' | 'TND' | 'TRY' | 'TMT' | 'UGX' | 'UAH' | 'AED' | 'UYU' | 'UYW' | 'UZS' | 'VUV' | 'VES' | 'VND' | 'YER' | 'ZMW' | 'ZWL' | 'ZWG'; export type AcceptorMergeUpdate = {description?: ExtendedFreeTextField | undefined, mid?: Mid | undefined, mcc?: Mcc | undefined, doingBusinessAsName?: DoingBusinessAsName | undefined, webshopUrl?: NullableWebshopUrl | undefined, pointOfSaleAddress?: NullableAddress | undefined, networkAssignedId?: NullableNetworkAssignedId | undefined, binKey?: BinKeyRef | undefined, acquirerOrPayFacBusinessId?: NullableAcquirerOrPayFacBusinessId | undefined, subMerchantId?: NullableSubMerchantId | undefined, subMerchantAddress?: NullableSubMerchantAddress | undefined, isoId?: NullableIsoId | undefined, gatewayId?: NullableGatewayId | undefined, foreignRetailer?: NullableForeignRetailer | undefined, marketplaceId?: NullableMarketplaceId | undefined, rampProviderId?: NullableRampProviderId | undefined, restrictions?: AcceptorRestrictions | undefined, chargesBlocked?: NullableChargesBlocked | undefined, tags?: NullableTags | undefined, disputeHandling?: NullableDisputeHandling | undefined, reference?: NullableReference | undefined, route?: NullableRoute | undefined, merchantVolumeIndicator?: NullableMerchantVolumeIndicator | undefined, authorizationCurrency?: AuthorizationCurrencyForAmexDirectMerchant | undefined}; export type PatchApiAcceptorsAcceptorKeyArgs = {acceptorKey: AcceptorKey, body: AcceptorMergeUpdate}; export type PatchApiAcceptorsAcceptorKeyOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const acceptorKey = z.string().min(5).max(120); export const acceptorStatus = z.enum(["draft", "active", "archived"]); export const extendedFreeTextField = z.string().min(1).max(160); export const mid = z.string().min(1).max(20); export const mcc = z.string().min(4).max(4); export const doingBusinessAsName = z.string().min(1).max(120); export const webshopUrl = z.string().min(8).max(2048); export const countryCodeAlpha3 = z.string().min(3).max(3); export const countryCodeAlpha2 = z.string().min(2).max(2); export const countryCodeNumeric = z.string().min(3).max(3); export const countryCode = z.object({alpha3: countryCodeAlpha3, alpha2: countryCodeAlpha2, numeric: countryCodeNumeric}); export const stateOrProvince = z.string().min(1).max(120); export const city = z.string().min(1).max(120); export const line1 = z.string().min(1).max(120); export const line2 = z.string().min(1).max(120); export const postalCode = z.string().min(1).max(10); export const address = z.object({countryCode: countryCode, stateOrProvince: stateOrProvince.optional(), city: city, line1: line1, line2: line2.optional(), postalCode: postalCode}); export const messageSystem = z.enum(["DMS", "SMS"]); export const binKey = z.string().min(5).max(120); export const status = z.enum(["active", "archived"]); export const acquirerAgentKey = z.string(); export const created = z.string(); export const lastModified = z.string(); export const version = z.number().int(); export const visaBin = z.object({network: z.literal("visa"), messageSystem: messageSystem, acquirerIdCode: z.string().min(6).max(6), acquirerBin: z.string().min(6).max(6), bid: z.string().min(8).max(8), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const mastercardBin = z.object({network: z.literal("mastercard"), messageSystem: messageSystem, acquirerIdCode: z.string().min(6).max(6), acquirerBin: z.string().min(6).max(6), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const bancontactBin = z.object({network: z.literal("bancontact"), messageSystem: messageSystem, acquirerIdCode: z.string().min(6).max(6), acquirerBin: z.string().min(6).max(6), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const authorizationCurrency = z.enum(["EUR", "USD", "AFN", "ALL", "DZD", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "INR", "BTN", "BOB", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLP", "CNY", "CNH", "COP", "KMF", "CDF", "NZD", "CRC", "HRK", "CUP", "CUC", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MKD", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "MXN", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLL", "SLE", "SGD", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "UYU", "UYW", "UZS", "VUV", "VES", "VND", "YER", "ZMW", "ZWL", "ZWG"]); export const amexModel = z.enum(["payfac", "direct_merchant", "payment_designation"]); export const amexBin = z.object({network: z.literal("american-express"), messageSystem: z.literal("DMS"), acquirerIdCode: z.string().min(6).max(11), acquirerBin: z.union([z.string(), z.string().min(6).max(11), z.string().min(6).max(11)]), authorizationCurrency: authorizationCurrency.optional(), amexModel: amexModel.optional(), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const discoverAcquirerBin = z.string().min(1).max(11); export const discoverIsoId = z.string().min(1).max(11); export const discoverBin = z.object({network: z.literal("discover"), messageSystem: z.literal("DMS"), acquirerIdCode: z.string().min(1).max(11), acquirerBin: discoverAcquirerBin, isoId: discoverIsoId.optional(), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const dxsCode = z.string().min(3).max(3); export const dinersBin = z.object({network: z.literal("diners"), messageSystem: z.literal("DMS"), acquirerBin: z.string().min(6).max(11), acquirerIdCode: z.string().min(6).max(11), dxsCode: dxsCode, key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const unionpayBin = z.object({network: z.literal("unionpay"), messageSystem: z.literal("DMS"), acquirerIdCode: z.string().min(8).max(11), key: binKey, status: status, description: extendedFreeTextField, acquirerAgentKey: acquirerAgentKey.optional(), acquirerCountryCode: countryCode, shared: z.boolean(), created: created, lastModified: lastModified.optional(), version: version}); export const bin = z.discriminatedUnion("network", [visaBin, mastercardBin, bancontactBin, amexBin, discoverBin, dinersBin, unionpayBin]); export const merchantKey = z.string().min(5).max(120); export const merchantStatus = z.enum(["active", "archived"]); export const merchantReference = z.string().min(1).max(120); export const agentKey = z.string(); export const merchantLegalName = z.string().min(1).max(120); export const phoneNumber = z.string().min(5).max(33); export const url = z.string().min(8).max(2048); export const tags = z.record(z.string(), z.string().min(1).max(100)); export const taxRegistrationId = z.string().max(20); export const email = z.string(); export const businessType = z.enum(["corporation", "sole_proprietorship", "partnership", "non_profit_organization", "government_agency", "limited_liability_company"]); export const merchant = z.object({key: merchantKey, status: merchantStatus, merchantReference: merchantReference.optional(), agentKey: agentKey, name: z.string().min(1).max(120), description: z.string().min(1).max(160).optional(), legalName: merchantLegalName, registeredAddress: address, customerInquiry: phoneNumber, websiteUrl: url, tags: tags.optional(), created: created, lastModified: lastModified.optional(), version: version, taxRegistrationId: taxRegistrationId.optional(), sellerEmail: email.optional(), businessType: businessType.optional()}); export const networkAssignedId = z.string(); export const acquirerOrPayFacBusinessId = z.string().min(1).max(11); export const subMerchantId = z.string().min(1).max(15); export const isoId = z.string(); export const gatewayId = z.string(); export const acceptorRestriction = z.object({suspendPayouts: z.boolean().optional(), blockCharges: z.boolean().optional()}); export const acceptorRestrictions = z.array(acceptorRestriction); export const chargesBlocked = z.boolean(); export const foreignRetailer = z.boolean(); export const marketplaceId = z.string(); export const rampProviderId = z.string(); export const disputeHandling = z.object({autoDefense: z.boolean()}); export const reference = z.string().min(1).max(120); export const acceptorRoute = z.string().max(255); export const merchantVolumeIndicator = z.string().min(2).max(2); export const authorizationCurrencyForAmexDirectMerchant = z.enum(["EUR", "USD", "AFN", "ALL", "DZD", "AOA", "XCD", "ARS", "AMD", "AWG", "AUD", "AZN", "BSD", "BHD", "BDT", "BBD", "BYN", "BZD", "XOF", "BMD", "INR", "BTN", "BOB", "BAM", "BWP", "NOK", "BRL", "BND", "BGN", "BIF", "CVE", "KHR", "XAF", "CAD", "KYD", "CLP", "CNY", "CNH", "COP", "KMF", "CDF", "NZD", "CRC", "HRK", "CUP", "CUC", "ANG", "CZK", "DKK", "DJF", "DOP", "EGP", "SVC", "ERN", "ETB", "FKP", "FJD", "XPF", "GMD", "GEL", "GHS", "GIP", "GTQ", "GBP", "GNF", "GYD", "HTG", "HNL", "HKD", "HUF", "ISK", "IDR", "IRR", "IQD", "ILS", "JMD", "JPY", "JOD", "KZT", "KES", "KPW", "KRW", "KWD", "KGS", "LAK", "LBP", "LSL", "ZAR", "LRD", "LYD", "CHF", "MOP", "MKD", "MGA", "MWK", "MYR", "MVR", "MRU", "MUR", "MXN", "MDL", "MNT", "MAD", "MZN", "MMK", "NAD", "NPR", "NIO", "NGN", "OMR", "PKR", "PAB", "PGK", "PYG", "PEN", "PHP", "PLN", "QAR", "RON", "RUB", "RWF", "SHP", "WST", "STN", "SAR", "RSD", "SCR", "SLL", "SLE", "SGD", "SBD", "SOS", "SSP", "LKR", "SDG", "SRD", "SZL", "SEK", "SYP", "TWD", "TJS", "TZS", "THB", "TOP", "TTD", "TND", "TRY", "TMT", "UGX", "UAH", "AED", "UYU", "UYW", "UZS", "VUV", "VES", "VND", "YER", "ZMW", "ZWL", "ZWG"]); export const acceptor = z.object({key: acceptorKey, status: acceptorStatus, description: extendedFreeTextField, mid: mid, mcc: mcc, doingBusinessAsName: doingBusinessAsName, webshopUrl: webshopUrl.optional(), pointOfSaleAddress: address.optional(), bin: bin, merchant: merchant, networkAssignedId: networkAssignedId.optional(), acquirerOrPayFacBusinessId: acquirerOrPayFacBusinessId.optional(), subMerchantId: subMerchantId.optional(), subMerchantAddress: address.optional(), isoId: isoId.optional(), gatewayId: gatewayId.optional(), restrictions: acceptorRestrictions.optional(), chargesBlocked: chargesBlocked.optional(), foreignRetailer: foreignRetailer.optional(), marketplaceId: marketplaceId.optional(), rampProviderId: rampProviderId.optional(), tags: tags.optional(), disputeHandling: disputeHandling.optional(), created: created, lastModified: lastModified.optional(), version: version, reference: reference.optional(), route: acceptorRoute.optional(), merchantVolumeIndicator: merchantVolumeIndicator.optional(), authorizationCurrency: authorizationCurrencyForAmexDirectMerchant.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 Merchant Acceptor * * PATCH /acceptors/{acceptorKey} * * Also accepts auth: BearerToken */ export const patchApiAcceptorsAcceptorKey = async (args: PatchApiAcceptorsAcceptorKeyArgs, options?: PatchApiAcceptorsAcceptorKeyOptions) => { const {baseUrl = "https://eu-west-1.api.silverflow.com/v1", fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/merge-patch+json") headers.set('accept', "application/json") if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/acceptors/${encodeURIComponent(String(args.acceptorKey))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(acceptor, await res.json()) };