import {z} from 'zod' export type ComponentsSchemasAcceptorKeyRef = string; export type SchemasMerchantKey = string; export type SchemasAcceptorRoute = string; export type SchemasAcceptorResolver = {merchantAcceptorKey: ComponentsSchemasAcceptorKeyRef} | {merchantKey: SchemasMerchantKey, route?: SchemasAcceptorRoute | undefined}; export type ComponentsSchemasPan = string; export type ExpiryMonthOptional = number; export type ExpiryYearOptional = number; export type SchemasCvc = string; export type SchemasHolderName = string; export type CardInputWithOptionalExpiryDate = {number: ComponentsSchemasPan, expiryMonth?: ExpiryMonthOptional | undefined, expiryYear?: ExpiryYearOptional | undefined, cvc?: SchemasCvc | undefined, holderName?: SchemasHolderName | undefined}; export type SchemasProcessorTokenKey = string; export type SchemasCardByProcessorTokenKey = {processorTokenKey: SchemasProcessorTokenKey, cvc?: string | undefined}; export type CardWithOptionalExpiryDate = CardInputWithOptionalExpiryDate | SchemasCardByProcessorTokenKey; export type ComponentsSchemasAmountValue = number; export type CommonCurrencyCode = 'AED' | 'AFN' | 'ALL' | 'AMD' | 'AOA' | 'ARS' | 'AUD' | 'AWG' | 'AZN' | 'BAM' | 'BBD' | 'BDT' | 'BHD' | 'BIF' | 'BMD' | 'BND' | 'BOB' | 'BRL' | 'BSD' | 'BTN' | 'BWP' | 'BYN' | 'BZD' | 'CAD' | 'CDF' | 'CHF' | 'CLP' | 'CNY' | 'COP' | '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' | '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' | 'LYD' | 'MAD' | 'MDL' | 'MGA' | 'MKD' | 'MMK' | 'MNT' | 'MOP' | 'MRU' | 'MUR' | 'MVR' | 'MWK' | 'MXN' | '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' | 'SOS' | 'SRD' | 'SSP' | 'STN' | 'SYP' | 'SZL' | 'THB' | 'TJS' | 'TMT' | 'TND' | 'TOP' | 'TRY' | 'TTD' | 'TWD' | 'TZS' | 'UAH' | 'UGX' | 'USD' | 'UYU' | 'UZS' | 'VES' | 'VND' | 'VUV' | 'WST' | 'XAF' | 'XCD' | 'XCG' | 'XOF' | 'XPF' | 'YER' | 'ZAR' | 'ZMW' | 'ZWL'; export type CommonAmount = {value: ComponentsSchemasAmountValue, currency: CommonCurrencyCode}; export type PayoutCardEntry = 'e-commerce'; export type PayoutOrder = 'checkout'; export type PayoutChargeType = {intent: 'payout', cardEntry: PayoutCardEntry, order: PayoutOrder, payoutType: 'account-to-account' | 'fast-refund' | 'general-funds-disbursement' | 'liquid-assets' | 'merchant-disbursement' | 'online-gambling' | 'person-to-person' | 'wallet-transfer'}; export type VisaPayoutInitialTransactionReference = {initialTransactionIdentifier: string}; export type Result3DS = 'full-auth' | 'attempt'; export type AuthenticationValue3ds = string; export type FundingPayoutThreeDsAuthenticationResult = {type: Result3DS, version?: '2.2.0' | undefined, authenticationValue: AuthenticationValue3ds, directoryServerTransId: string, eci?: string | undefined}; export type LocalTransactionDateTime = unknown; export type TransactionReference = string; export type PayoutFundingSource = 'credit' | 'debit' | 'prepaid' | 'deposit-account' | 'mobile-money-account' | 'cash' | 'other'; export type SchemasCountryCodeAlpha3 = string; export type ComponentsSchemasCountryCodeAlpha3 = {alpha3: SchemasCountryCodeAlpha3}; export type SchemasCountryCodeAlpha2 = string; export type ComponentsSchemasCountryCodeAlpha2 = {alpha2: SchemasCountryCodeAlpha2}; export type SchemasCountryCodeNumeric = string; export type ComponentsSchemasCountryCodeNumeric = {numeric: SchemasCountryCodeNumeric}; export type OpenapiComponentsSchemasStateOrProvince = string; export type OpenapiComponentsSchemasCity = string; export type OpenapiComponentsSchemasLine1 = string; export type OpenapiComponentsSchemasLine2 = string; export type OpenapiComponentsSchemasPostalCode = string; export type PayoutSenderInput = {type?: ('consumer' | 'organization' | 'not-applicable') | undefined, organizationName?: string | undefined, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, accountNumber?: string | undefined, accountNumberType?: ('card-account' | 'iban-bank-account' | 'bic-bank-account' | 'rtn-bank-account' | 'email' | 'phone-number' | 'wallet-id' | 'social-network-id' | 'other') | undefined, address?: ({countryCode: ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric, stateOrProvince?: OpenapiComponentsSchemasStateOrProvince | undefined, city: OpenapiComponentsSchemasCity, line1: OpenapiComponentsSchemasLine1, line2?: OpenapiComponentsSchemasLine2 | undefined, postalCode: OpenapiComponentsSchemasPostalCode}) | undefined, identification?: ({type: 'date-of-birth' | 'national-identification' | 'passport-number' | 'driver-license' | 'tax-identification' | 'company-registration-number' | 'social-security-number' | 'other', value: string, issuingCountry?: string | undefined}) | undefined}; export type ChargesPayoutAccountNumberType = 'card-account' | 'iban-bank-account' | 'bic-bank-account' | 'rtn-bank-account' | 'email' | 'phone-number' | 'wallet-id' | 'social-network-id' | 'other'; export type PayoutReceiverInput = {type?: ('consumer' | 'organization' | 'not-applicable') | undefined, organizationName?: string | undefined, firstName?: string | undefined, middleName?: string | undefined, lastName?: string | undefined, accountNumber?: string | undefined, accountNumberType?: ChargesPayoutAccountNumberType | undefined, address?: ({countryCode: ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric, stateOrProvince?: OpenapiComponentsSchemasStateOrProvince | undefined, city: OpenapiComponentsSchemasCity, line1: OpenapiComponentsSchemasLine1, line2?: OpenapiComponentsSchemasLine2 | undefined, postalCode: OpenapiComponentsSchemasPostalCode}) | undefined, identification?: ({type: 'date-of-birth' | 'national-identification' | 'passport-number' | 'driver-license' | 'tax-identification' | 'company-registration-number' | 'social-security-number' | 'other', value: string, issuingCountry?: string | undefined}) | undefined}; export type PayoutTransactionType = 'tax-refund' | 'cryptocurrency' | 'central-bank-digital-currency' | 'stablecoin' | 'blockchain-native-coin' | 'non-fungible-token'; export type PurposeOfPayment = string; export type SchemasDynamicDescriptor = {merchantName?: string | undefined, merchantCity?: string | undefined}; export type RiskAssessmentKey = string; export type ForeignRetailerDisabled = {indicator: false}; export type ForeignRetailerEnabled = {indicator: true, amount?: number | undefined}; export type SchemasForeignRetailer = ForeignRetailerDisabled | ForeignRetailerEnabled; export type SchemasAddressInput = {countryCode: ComponentsSchemasCountryCodeAlpha3 | ComponentsSchemasCountryCodeAlpha2 | ComponentsSchemasCountryCodeNumeric, stateOrProvince?: OpenapiComponentsSchemasStateOrProvince | undefined, city: OpenapiComponentsSchemasCity, line1: OpenapiComponentsSchemasLine1, line2?: OpenapiComponentsSchemasLine2 | undefined, postalCode: OpenapiComponentsSchemasPostalCode}; export type SubMerchant = {id?: string | undefined, address?: SchemasAddressInput | undefined}; export type PayoutChargeRequest = {merchantAcceptorResolver: SchemasAcceptorResolver, card: CardWithOptionalExpiryDate, amount: CommonAmount, type: PayoutChargeType, initialTransactionReferences?: VisaPayoutInitialTransactionReference | undefined, threeDsAuthenticationResult?: FundingPayoutThreeDsAuthenticationResult | undefined, localTransactionDateTime?: LocalTransactionDateTime | undefined, transactionReference?: TransactionReference | undefined, fundingSource?: PayoutFundingSource | undefined, sender?: PayoutSenderInput | undefined, receiver?: PayoutReceiverInput | undefined, transactionType?: PayoutTransactionType | undefined, purposeOfPayment?: PurposeOfPayment | undefined, dynamicDescriptor?: SchemasDynamicDescriptor | undefined, clearingMode?: ('auto' | 'manual') | undefined, clearAfter?: unknown | undefined, riskAssessmentKey?: RiskAssessmentKey | undefined, foreignRetailer?: SchemasForeignRetailer | undefined, subMerchant?: SubMerchant | undefined}; export type CreateApiChargesPayoutArgs = {'Idempotency-Key'?: string | undefined, body: PayoutChargeRequest}; export type CreateApiChargesPayoutOptions = {baseUrl?: string | undefined, ApiKey?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const chargeKey = z.string().min(5).max(120); export const componentsSchemasAcceptorKey = z.string().min(5).max(120); export const schemasVersion = z.number().int(); export const componentsSchemasAcceptorRef = z.object({key: componentsSchemasAcceptorKey, version: schemasVersion}); export const schemasProcessorTokenKey = z.string().min(5).max(120); export const outputCard = z.object({maskedNumber: z.string(), processorTokenKey: schemasProcessorTokenKey.optional()}); export const componentsSchemasAmountValue = z.number().int().gte(0).lte(999999999999); export const commonCurrencyCode = z.enum(["AED", "AFN", "ALL", "AMD", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "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", "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", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "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", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XCG", "XOF", "XPF", "YER", "ZAR", "ZMW", "ZWL"]); export const commonAmount = z.object({value: componentsSchemasAmountValue, currency: commonCurrencyCode}); export const payoutCardEntry = z.literal("e-commerce"); export const payoutOrder = z.literal("checkout"); export const payoutChargeType = z.object({intent: z.literal("payout"), cardEntry: payoutCardEntry, order: payoutOrder, payoutType: z.enum(["account-to-account", "fast-refund", "general-funds-disbursement", "liquid-assets", "merchant-disbursement", "online-gambling", "person-to-person", "wallet-transfer"])}); export const authenticationStatus = z.enum(["none", "authenticated", "non-authenticated"]); export const authorizationStatusWithoutPartialApproval = z.enum(["none", "approved", "declined", "reversed"]); export const clearingStatus = z.enum(["none", "manual", "pending", "completed", "cancelled", "abandoned"]); export const statusWithoutPartialApproval = z.object({authentication: authenticationStatus, authorization: authorizationStatusWithoutPartialApproval, clearing: clearingStatus}); export const method = z.enum(["3ds1", "3ds2", "device"]); export const threeDsComplianceReason = z.enum(["mandated", "none", "ucof", "recurring", "installment", "incremental", "delayed-charges", "no-show", "reauthorization", "resubmission", "whitelist", "auto", "mit", "tra", "low-value", "delegation", "scp"]); export const result3DS = z.enum(["full-auth", "attempt"]); export const fundingPayoutThreeDsAuthenticationResultResponse = z.object({type: result3DS, version: z.literal("2.2.0").optional(), directoryServerTransId: z.string().optional()}); export const fundingPayoutThreeDsAuthentication = z.object({method: method, compliance: z.enum(["mandated", "mit", "exemption"]), complianceReason: threeDsComplianceReason, result: fundingPayoutThreeDsAuthenticationResultResponse}); export const methodBEP = z.literal("bep"); export const complianceBEP = z.literal("mandated"); export const complianceReasonBEP = z.literal("mandated"); export const bEPAuthenticationResult = z.object({trm: z.enum(["50", "51"])}); export const scaBEP = z.object({method: methodBEP, compliance: complianceBEP, complianceReason: complianceReasonBEP, result: bEPAuthenticationResult}); export const authenticationOutOfScope = z.object({method: z.literal("none"), compliance: z.literal("out-of-scope"), complianceReason: z.enum(["none", "moto", "one-leg", "anonymous-prepaid", "recurring"])}); export const authenticationExempt = z.object({method: z.literal("none"), compliance: z.literal("exemption"), complianceReason: z.enum(["whitelist", "auto", "mit", "tra", "recurring", "low-value", "delegation", "scp", "wip"])}); export const scaMit = z.object({method: z.literal("none"), compliance: z.literal("mit"), complianceReason: z.enum(["installment", "ucof"])}); export const fundingPayoutSca = z.union([fundingPayoutThreeDsAuthentication, scaBEP, authenticationOutOfScope, authenticationExempt, scaMit]); export const cvcResult = z.enum(["none", "match", "no-match", "not-processed"]); export const avsResult = z.enum(["none", "match", "partial-match", "no-match", "not-processed"]); export const fundingPayoutChargeAuthentication = z.object({sca: fundingPayoutSca, cvc: cvcResult, avs: avsResult}); export const localTransactionDateTime = z.string(); export const payoutTransactionType = z.enum(["tax-refund", "cryptocurrency", "central-bank-digital-currency", "stablecoin", "blockchain-native-coin", "non-fungible-token"]); export const transactionReference = z.string().min(1).max(120); export const payoutFundingSource = z.enum(["credit", "debit", "prepaid", "deposit-account", "mobile-money-account", "cash", "other"]); export const isoFieldResponseCode = z.string(); export const isoFieldResponseCodeDescription = z.string(); export const isoFieldAuthorizationCode = z.string(); export const isoFieldSystemTraceAuditNumber = z.string(); export const isoFieldRetrievalReferenceNumber = z.string(); export const isoFieldEciAmex = z.string(); export const amexSpecificFields = z.object({acquirerReferenceData: z.string(), cvcResult: z.string().optional(), avsResult: z.string().optional()}); export const authorizationIsoFieldsAmericanExpress = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("not-applicable"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciAmex, networkSpecificFields: amexSpecificFields}); export const bancontactSpecificFields = z.object({iban: z.string().optional()}); export const authorizationIsoFieldsBancontact = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("none"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: z.literal("none"), networkSpecificFields: bancontactSpecificFields}); export const isoFieldEciDiners = z.string(); export const dinersSpecificFields = z.object({network: z.literal("diners"), cvvIndicator: z.string().optional(), networkReferenceId: z.string().optional()}); export const authorizationIsoFieldsDiners = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.string(), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciDiners, networkSpecificFields: dinersSpecificFields}); export const isoFieldNetworkCode = z.string(); export const isoFieldEciDiscover = z.string(); export const discoverSpecificFields = z.object({network: z.literal("discover"), avsResponseCode: z.string().optional(), cidResultCode: z.string().optional(), networkReferenceId: z.string().optional()}); export const authorizationIsoFieldsDiscover = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciDiscover, networkSpecificFields: discoverSpecificFields}); export const isoFieldEciMastercard = z.string(); export const mastercardSpecificFields = z.object({banknetReference: z.string(), traceId: z.string(), merchantAdviceCode: z.string().optional(), cvcResult: z.string().optional(), nameValidationResult: z.string().optional(), avsResponse: z.string().optional(), paymentAccountReference: z.string().optional(), transactionLinkId: z.string().optional(), digitalCommerceProgramType: z.string().optional(), onBehalfServices: z.array(z.object({onBehalfService: z.string(), onBehalfResult1: z.string(), onBehalfResult2: z.string()})).optional()}); export const authorizationIsoFieldsMastercard = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciMastercard, networkSpecificFields: mastercardSpecificFields}); export const isoFieldEciUnionPay = z.string(); export const unionPaySpecificFields = z.object({network: z.literal("unionpay"), pvnCheckResult: z.string().optional()}); export const authorizationIsoFieldsUnionPay = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: z.literal("not-applicable"), systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciUnionPay, networkSpecificFields: unionPaySpecificFields}); export const isoFieldEciVisa = z.string(); export const visaSpecificFields = z.object({transactionIdentifier: z.string(), cvv2ResultCode: z.string().optional(), avsResultCode: z.string().optional(), paymentAccountReference: z.string().optional(), aniResults: z.object({status: z.string(), fullNameMatch: z.string().optional(), firstNameMatch: z.string().optional(), middleNameMatch: z.string().optional(), lastNameMatch: z.string().optional()}).optional(), vaaiScore: z.string().optional(), tokenRequestorId: z.string().optional()}); export const authorizationIsoFieldsVisa = z.object({responseCode: isoFieldResponseCode, responseCodeDescription: isoFieldResponseCodeDescription, authorizationCode: isoFieldAuthorizationCode.optional(), networkCode: isoFieldNetworkCode, systemTraceAuditNumber: isoFieldSystemTraceAuditNumber, retrievalReferenceNumber: isoFieldRetrievalReferenceNumber, eci: isoFieldEciVisa, networkSpecificFields: visaSpecificFields}); export const authorizationIsoFields = z.union([authorizationIsoFieldsAmericanExpress, authorizationIsoFieldsBancontact, authorizationIsoFieldsDiners, authorizationIsoFieldsDiscover, authorizationIsoFieldsMastercard, authorizationIsoFieldsUnionPay, authorizationIsoFieldsVisa]); export const chargesPayoutAccountNumberType = z.enum(["card-account", "iban-bank-account", "bic-bank-account", "rtn-bank-account", "email", "phone-number", "wallet-id", "social-network-id", "other"]); export const schemasCountryCodeAlpha3 = z.string().min(3).max(3); export const schemasCountryCodeAlpha2 = z.string().min(2).max(2); export const schemasCountryCodeNumeric = z.string().min(3).max(3); export const schemasCountryCode = z.object({alpha3: schemasCountryCodeAlpha3, alpha2: schemasCountryCodeAlpha2, numeric: schemasCountryCodeNumeric}); export const chargesPayoutPayoutSender = z.object({type: z.enum(["consumer", "organization", "not-applicable"]).optional(), organizationName: z.string().min(1).max(120).optional(), firstName: z.string().min(1).max(120).optional(), middleName: z.string().min(1).max(120).optional(), lastName: z.string().min(1).max(120).optional(), accountNumber: z.string().min(1).max(50).optional(), accountNumberType: chargesPayoutAccountNumberType.optional(), address: z.object({countryCode: schemasCountryCode, stateOrProvince: z.string().min(1).max(120).optional(), city: z.string().min(1).max(120), line1: z.string().min(1).max(120), line2: z.string().min(1).max(120).optional(), postalCode: z.string().min(1).max(10)}).optional(), identification: z.object({type: z.enum(["date-of-birth", "national-identification", "passport-number", "driver-license", "tax-identification", "company-registration-number", "social-security-number", "other"]), value: z.string().min(1).max(35), issuingCountry: z.string().min(3).max(3).optional()}).optional()}); export const openapiComponentsSchemasStateOrProvince = z.string().min(1).max(120); export const openapiComponentsSchemasCity = z.string().min(1).max(120); export const openapiComponentsSchemasLine1 = z.string().min(1).max(120); export const openapiComponentsSchemasLine2 = z.string().min(1).max(120); export const openapiComponentsSchemasPostalCode = z.string().min(1).max(10); export const chargesPayoutPayoutReceiver = z.object({type: z.enum(["consumer", "organization", "not-applicable"]).optional(), organizationName: z.string().min(1).max(120).optional(), firstName: z.string().min(1).max(120).optional(), middleName: z.string().min(1).max(120).optional(), lastName: z.string().min(1).max(120).optional(), accountNumber: z.string().min(1).max(50).optional(), accountNumberType: chargesPayoutAccountNumberType.optional(), address: z.object({countryCode: schemasCountryCode, stateOrProvince: openapiComponentsSchemasStateOrProvince.optional(), city: openapiComponentsSchemasCity, line1: openapiComponentsSchemasLine1, line2: openapiComponentsSchemasLine2.optional(), postalCode: openapiComponentsSchemasPostalCode}).optional(), identification: z.object({type: z.enum(["date-of-birth", "national-identification", "passport-number", "driver-license", "tax-identification", "company-registration-number", "social-security-number", "other"]), value: z.string().min(1).max(35), issuingCountry: z.string().min(3).max(3).optional()}).optional()}); export const purposeOfPayment = z.string().min(1).max(12); export const schemasDynamicDescriptor = z.object({merchantName: z.string().min(1).max(22).optional(), merchantCity: z.string().min(1).max(13).optional()}); export const foreignRetailerDisabled = z.object({indicator: z.literal(false)}); export const foreignRetailerEnabled = z.object({indicator: z.literal(true), amount: z.number().int().gte(1).lte(999999999999).optional()}); export const schemasForeignRetailer = z.union([foreignRetailerDisabled, foreignRetailerEnabled]); export const componentsSchemasAddress = z.object({countryCode: schemasCountryCode, stateOrProvince: openapiComponentsSchemasStateOrProvince.optional(), city: openapiComponentsSchemasCity, line1: openapiComponentsSchemasLine1, line2: openapiComponentsSchemasLine2.optional(), postalCode: openapiComponentsSchemasPostalCode}); export const subMerchantResponse = z.object({id: z.string().min(1).max(15).optional(), address: componentsSchemasAddress.optional()}); export const clearAfter = z.string(); export const openapiComponentsSchemasCreated = z.string(); export const componentsSchemasLastModified = z.string(); export const payoutChargeResponse = z.object({key: chargeKey, merchantAcceptorRef: componentsSchemasAcceptorRef, card: outputCard, amount: commonAmount, type: payoutChargeType, clearingMode: z.enum(["none", "auto", "manual"]), status: statusWithoutPartialApproval, authentication: fundingPayoutChargeAuthentication, localTransactionDateTime: localTransactionDateTime, transactionType: payoutTransactionType.optional(), transactionReference: transactionReference.optional(), fundingSource: payoutFundingSource.optional(), authorizationIsoFields: authorizationIsoFields, sender: chargesPayoutPayoutSender.optional(), receiver: chargesPayoutPayoutReceiver.optional(), purposeOfPayment: purposeOfPayment.optional(), dynamicDescriptor: schemasDynamicDescriptor.optional(), foreignRetailer: schemasForeignRetailer.optional(), subMerchant: subMerchantResponse.optional(), clearAfter: clearAfter.optional(), created: openapiComponentsSchemasCreated, lastModified: componentsSchemasLastModified.optional(), version: schemasVersion}); 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 }; /** * Create Payout Charge * * POST /charges/payout * * Also accepts auth: BearerToken */ export const createApiChargesPayout = async (args: CreateApiChargesPayoutArgs, options?: CreateApiChargesPayoutOptions) => { 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/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) if (ApiKey !== undefined) headers.set('authorization', `Basic ${btoa(`${ApiKey.username}:${ApiKey.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/charges/payout${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(payoutChargeResponse, await res.json()) };