import {z} from 'zod' export type USDDomesticPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankName: string, bankRoutingNumber: string, symbol: 'USD', transferType: 'ACH' | 'WIRE', type: 'usdDomestic'}; export type USDInternationalWirePayoutMethodDetails = {bankAccountNumber: string, bankName: string, intermediaryRoutingNumber?: string | undefined, swiftBic: string, symbol: 'USD', type: 'usdInternationalWire'}; export type USDPeruPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'PASSPORT' | 'RESIDENT_ID' | 'RUC' | 'TAX_ID', symbol: 'USD', type: 'usdPeru'}; export type USDChinaPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'PASSPORT' | 'TAX_ID' | 'RESIDENT_ID', phoneNumber: unknown, swiftBic: string, symbol: 'USD', type: 'usdChina'}; export type USDPanamaPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'RUC_NIT' | 'PASSPORT' | 'RESIDENT_ID', symbol: 'USD', type: 'usdPanama'}; export type USDHongKongPayoutMethodDetails = {bankAccountNumber: string, bankId: string, swiftBic: string, symbol: 'USD', type: 'usdHongKong'}; export type USDElSalvadorPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'DUI' | 'NIT' | 'PASSPORT', phoneNumber: unknown, symbol: 'USD', type: 'usdElSalvador'}; export type USDPayoutMethod = {details: USDDomesticPayoutMethodDetails | USDInternationalWirePayoutMethodDetails | USDPeruPayoutMethodDetails | USDChinaPayoutMethodDetails | USDPanamaPayoutMethodDetails | USDHongKongPayoutMethodDetails | USDElSalvadorPayoutMethodDetails, type: 'usd'}; export type ARSAliasPayoutMethodDetails = {alias: string, documentNumber: string, symbol: 'ARS', type: 'arsAlias'}; export type ARSAccountNumberPayoutMethodDetails = {bankAccountNumber: string, documentNumber: string, symbol: 'ARS', type: 'arsAccountNumber'}; export type ARSPayoutMethod = {details: ARSAliasPayoutMethodDetails | ARSAccountNumberPayoutMethodDetails, type: 'ars'}; export type BRLPixPhonePayoutMethodDetails = {bankId: string, documentNumber: string, phoneNumber: unknown, symbol: 'BRL', type: 'pixPhone'}; export type BRLPixEmailPayoutMethodDetails = {bankId: string, documentNumber: string, email: string, symbol: 'BRL', type: 'pixEmail'}; export type BRLPixDocumentPayoutMethodDetails = {bankId: string, documentNumber: string, symbol: 'BRL', type: 'pixDocument'}; export type BRLPixBankAccountPayoutMethodDetails = {bankAccountNumber: string, bankId: string, documentNumber: string, symbol: 'BRL', type: 'pixBankAccount'}; export type BRLWirePayoutMethodDetails = {accountNumber: string, accountType: 'CHECKING' | 'SAVINGS', bankBranch: string, bankId: string, documentNumber: string, symbol: 'BRL', type: 'wire'}; export type BRLPayoutMethod = {details: BRLPixPhonePayoutMethodDetails | BRLPixEmailPayoutMethodDetails | BRLPixDocumentPayoutMethodDetails | BRLPixBankAccountPayoutMethodDetails | BRLWirePayoutMethodDetails, type: 'brl'}; export type COPDomesticPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'RUC_NIT' | 'PASSPORT' | 'RESIDENT_ID', phoneNumber: unknown, symbol: 'COP', type: 'copDomestic'}; export type COPBreBPayoutMethodDetails = {keyValue: string, symbol: 'COP', type: 'copBreB'}; export type COPPayoutMethod = {details: COPDomesticPayoutMethodDetails | COPBreBPayoutMethodDetails, type: 'cop'}; export type EURSepaPayoutMethodDetails = {bankName: string, country: unknown, iban: string, swiftBic: string, symbol: 'EUR', type: 'eurSepa'}; export type EURPayoutMethod = {details: EURSepaPayoutMethodDetails, type: 'eur'}; export type MXNDomesticPayoutMethodDetails = {bankAccountNumber: string, symbol: 'MXN', type: 'mxnDomestic'}; export type MXNDebitCardPayoutMethodDetails = {bankId: string, cardNumber: string, symbol: 'MXN', type: 'mxnDebitCard'}; export type MXNPayoutMethod = {details: MXNDomesticPayoutMethodDetails | MXNDebitCardPayoutMethodDetails, type: 'mxn'}; export type CLPDomesticPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'PASSPORT' | 'RESIDENT_ID' | 'RUC' | 'TAX_ID', symbol: 'CLP', type: 'clpDomestic'}; export type CLPPayoutMethod = {details: CLPDomesticPayoutMethodDetails, type: 'clp'}; export type PENDomesticPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'PASSPORT' | 'RESIDENT_ID' | 'RUC' | 'TAX_ID', symbol: 'PEN', type: 'penDomestic'}; export type PENPayoutMethod = {details: PENDomesticPayoutMethodDetails, type: 'pen'}; export type BOBDomesticPayoutMethodDetails = {bankAccountNumber: string, bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'RUC_NIT' | 'RESIDENT_ID', symbol: 'BOB', type: 'bobDomestic'}; export type BOBPayoutMethod = {details: BOBDomesticPayoutMethodDetails, type: 'bob'}; export type CRCDomesticPayoutMethodDetails = {bankId: string, documentNumber: string, documentType: 'NATIONAL_ID' | 'PASSPORT' | 'RESIDENT_ID' | 'RUC' | 'TAX_ID', iban: string, symbol: 'CRC', type: 'crcDomestic'}; export type CRCPayoutMethod = {details: CRCDomesticPayoutMethodDetails, type: 'crc'}; export type ZARDomesticPayoutMethodDetails = {accountType: 'CHECKING' | 'SAVINGS', bankAccountNumber: string, bankId: string, symbol: 'ZAR', type: 'zarDomestic'}; export type ZARPayoutMethod = {details: ZARDomesticPayoutMethodDetails, type: 'zar'}; export type BlockchainPayoutMethodDetails = {blockchain: 'ETHEREUM' | 'POLYGON' | 'BASE' | 'CELO' | 'PLASMA' | 'TRON', type: 'blockchainWallet', walletAddress: string}; export type CreatePayoutMethodRequestBody = {alias: string, payoutMethod: USDPayoutMethod | ARSPayoutMethod | BRLPayoutMethod | COPPayoutMethod | EURPayoutMethod | MXNPayoutMethod | CLPPayoutMethod | PENPayoutMethod | BOBPayoutMethod | CRCPayoutMethod | ZARPayoutMethod | BlockchainPayoutMethodDetails}; export type CreateApiApiCounterpartiesIdPayoutMethodsArgs = {id: string, 'on-behalf-of'?: string | undefined, body: CreatePayoutMethodRequestBody}; export type CreateApiApiCounterpartiesIdPayoutMethodsOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const uSDDomesticPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankName: z.string(), bankRoutingNumberTruncated: z.string(), symbol: z.literal("USD"), transferType: z.enum(["ACH", "WIRE"]), type: z.literal("usdDomestic")}); export const uSDInternationalWirePayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankName: z.string(), intermediaryRoutingNumberTruncated: z.string().optional(), swiftBicTruncated: z.string(), symbol: z.literal("USD"), type: z.literal("usdInternationalWire")}); export const uSDPeruPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "PASSPORT", "RESIDENT_ID", "RUC", "TAX_ID"]), symbol: z.literal("USD"), type: z.literal("usdPeru")}); export const uSDChinaPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["PASSPORT", "TAX_ID", "RESIDENT_ID"]), phoneNumberTruncated: z.string(), swiftBicTruncated: z.string(), symbol: z.literal("USD"), type: z.literal("usdChina")}); export const uSDPanamaPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "RUC_NIT", "PASSPORT", "RESIDENT_ID"]), symbol: z.literal("USD"), type: z.literal("usdPanama")}); export const uSDHongKongPayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankId: z.string(), swiftBicTruncated: z.string(), symbol: z.literal("USD"), type: z.literal("usdHongKong")}); export const uSDElSalvadorPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["DUI", "NIT", "PASSPORT"]), phoneNumberTruncated: z.string(), symbol: z.literal("USD"), type: z.literal("usdElSalvador")}); export const uSDPayoutMethodInfo = z.object({details: z.union([uSDDomesticPayoutMethodResponseDetails, uSDInternationalWirePayoutMethodResponseDetails, uSDPeruPayoutMethodResponseDetails, uSDChinaPayoutMethodResponseDetails, uSDPanamaPayoutMethodResponseDetails, uSDHongKongPayoutMethodResponseDetails, uSDElSalvadorPayoutMethodResponseDetails]), type: z.literal("usd")}); export const aRSAliasPayoutMethodResponseDetails = z.object({aliasTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), symbol: z.literal("ARS"), type: z.literal("arsAlias")}); export const aRSAccountNumberPayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankAccountNumberType: z.enum(["CVU", "CBU"]), bankId: z.string(), documentNumberTruncated: z.string(), symbol: z.literal("ARS"), type: z.literal("arsAccountNumber")}); export const aRSPayoutMethodInfo = z.object({details: z.union([aRSAliasPayoutMethodResponseDetails, aRSAccountNumberPayoutMethodResponseDetails]), type: z.literal("ars")}); export const bRLPixPhonePayoutMethodResponseDetails = z.object({bankId: z.string(), documentNumberTruncated: z.string(), phoneNumberTruncated: z.string(), symbol: z.literal("BRL"), type: z.literal("pixPhone")}); export const bRLPixEmailPayoutMethodResponseDetails = z.object({bankId: z.string(), documentNumberTruncated: z.string(), emailTruncated: z.string(), symbol: z.literal("BRL"), type: z.literal("pixEmail")}); export const bRLPixDocumentPayoutMethodResponseDetails = z.object({bankId: z.string(), documentNumberTruncated: z.string(), symbol: z.literal("BRL"), type: z.literal("pixDocument")}); export const bRLPixBankAccountPayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), symbol: z.literal("BRL"), type: z.literal("pixBankAccount")}); export const bRLWirePayoutMethodResponseDetails = z.object({accountNumberTruncated: z.string(), accountType: z.enum(["CHECKING", "SAVINGS"]), bankBranchTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), symbol: z.literal("BRL"), type: z.literal("wire")}); export const bRLPayoutMethodInfo = z.object({details: z.union([bRLPixPhonePayoutMethodResponseDetails, bRLPixEmailPayoutMethodResponseDetails, bRLPixDocumentPayoutMethodResponseDetails, bRLPixBankAccountPayoutMethodResponseDetails, bRLWirePayoutMethodResponseDetails]), type: z.literal("brl")}); export const cOPDomesticPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "RUC_NIT", "PASSPORT", "RESIDENT_ID"]), phoneNumberTruncated: z.string(), symbol: z.literal("COP"), type: z.literal("copDomestic")}); export const cOPBreBPayoutMethodResponseDetails = z.object({keyValueTruncated: z.string(), symbol: z.literal("COP"), type: z.literal("copBreB")}); export const cOPPayoutMethodInfo = z.object({details: z.union([cOPDomesticPayoutMethodResponseDetails, cOPBreBPayoutMethodResponseDetails]), type: z.literal("cop")}); export const eURSepaPayoutMethodResponseDetails = z.object({bankName: z.string(), country: z.string(), ibanTruncated: z.string(), swiftBicTruncated: z.string(), symbol: z.literal("EUR"), type: z.literal("eurSepa")}); export const eURPayoutMethodInfo = z.object({details: eURSepaPayoutMethodResponseDetails, type: z.literal("eur")}); export const mXNDomesticPayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankId: z.string(), symbol: z.literal("MXN"), type: z.literal("mxnDomestic")}); export const mXNDebitCardPayoutMethodResponseDetails = z.object({bankId: z.string(), cardNumberTruncated: z.string(), symbol: z.literal("MXN"), type: z.literal("mxnDebitCard")}); export const mXNPayoutMethodInfo = z.object({details: z.union([mXNDomesticPayoutMethodResponseDetails, mXNDebitCardPayoutMethodResponseDetails]), type: z.literal("mxn")}); export const cLPDomesticPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "PASSPORT", "RESIDENT_ID", "RUC", "TAX_ID"]), symbol: z.literal("CLP"), type: z.literal("clpDomestic")}); export const cLPPayoutMethodInfo = z.object({details: cLPDomesticPayoutMethodResponseDetails, type: z.literal("clp")}); export const pENDomesticPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "PASSPORT", "RESIDENT_ID", "RUC", "TAX_ID"]), symbol: z.literal("PEN"), type: z.literal("penDomestic")}); export const pENPayoutMethodInfo = z.object({details: pENDomesticPayoutMethodResponseDetails, type: z.literal("pen")}); export const bOBDomesticPayoutMethodResponseDetails = z.object({bankAccountNumberTruncated: z.string(), bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "RUC_NIT", "RESIDENT_ID"]), symbol: z.literal("BOB"), type: z.literal("bobDomestic")}); export const bOBPayoutMethodInfo = z.object({details: bOBDomesticPayoutMethodResponseDetails, type: z.literal("bob")}); export const cRCDomesticPayoutMethodResponseDetails = z.object({bankId: z.string(), documentNumberTruncated: z.string(), documentType: z.enum(["NATIONAL_ID", "PASSPORT", "RESIDENT_ID", "RUC", "TAX_ID"]), ibanTruncated: z.string(), symbol: z.literal("CRC"), type: z.literal("crcDomestic")}); export const cRCPayoutMethodInfo = z.object({details: cRCDomesticPayoutMethodResponseDetails, type: z.literal("crc")}); export const zARDomesticPayoutMethodResponseDetails = z.object({accountType: z.enum(["CHECKING", "SAVINGS"]), bankAccountNumberTruncated: z.string(), bankId: z.string(), symbol: z.literal("ZAR"), type: z.literal("zarDomestic")}); export const zARPayoutMethodInfo = z.object({details: zARDomesticPayoutMethodResponseDetails, type: z.literal("zar")}); export const blockchainPayoutMethodResponseDetails = z.object({blockchain: z.enum(["ETHEREUM", "POLYGON", "BASE", "CELO", "PLASMA", "TRON"]), walletAddress: z.string()}); export const blockchainPayoutMethodInfo = z.object({details: blockchainPayoutMethodResponseDetails, type: z.literal("blockchainWallet")}); export const payoutMethodResponse = z.object({alias: z.string(), counterpartyId: z.string(), createdAt: z.string(), id: z.string(), payoutMethod: z.union([uSDPayoutMethodInfo, aRSPayoutMethodInfo, bRLPayoutMethodInfo, cOPPayoutMethodInfo, eURPayoutMethodInfo, mXNPayoutMethodInfo, cLPPayoutMethodInfo, pENPayoutMethodInfo, bOBPayoutMethodInfo, cRCPayoutMethodInfo, zARPayoutMethodInfo, blockchainPayoutMethodInfo])}); 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 a Payout Method * * POST /api/counterparties/{id}/payout-methods */ export const createApiApiCounterpartiesIdPayoutMethods = async (args: CreateApiApiCounterpartiesIdPayoutMethodsArgs, options?: CreateApiApiCounterpartiesIdPayoutMethodsOptions) => { const {baseUrl = "https://api.muralpay.com", fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['on-behalf-of'] != null) headers.set("on-behalf-of", String(args['on-behalf-of'])) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/counterparties/${encodeURIComponent(String(args.id))}/payout-methods${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(payoutMethodResponse, await res.json()) };