import {z} from 'zod' export type UpdateApiApiV1RecipientsRecipientIdPaymentDetailsPaymentDetailsIdArgs = {paymentDetailsId: string, recipientId: string, body: BodyInit}; export type UpdateApiApiV1RecipientsRecipientIdPaymentDetailsPaymentDetailsIdOptions = {baseUrl?: string | undefined, WirexUserToken?: string | undefined, fetch?: typeof fetch | undefined}; export const responseRecipientPaymentDetailsLegalAddress = z.object({city: z.string(), country: z.string(), line1: z.string(), line2: z.string().optional(), state: z.string().optional(), zip_code: z.string()}); export const responseRecipientPaymentDetailsAch = z.object({account_number: z.string(), bank_name: z.string().optional(), legal_address: responseRecipientPaymentDetailsLegalAddress.optional(), routing_number: z.string()}); export const responseRecipientPaymentDetailsBiFast = z.object({account_number: z.string().optional(), bank_code: z.string().optional(), bank_name: z.string().optional(), destination_country: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsCard = z.object({card_id: z.string(), card_pan_last: z.string()}); export const responseRecipientPaymentDetailsCrossChainCrypto = z.object({address: z.string(), network: z.string(), tag: z.string().optional()}); export const responseRecipientPaymentDetailsCrypto = z.object({address: z.string(), network: z.string(), recipient_address: z.string()}); export const responseRecipientPaymentDetailsFasterPayment = z.object({account_number: z.string(), sort_code: z.string()}); export const responseRecipientPaymentDetailsFpsHk = z.object({bank_code: z.string().optional(), fps_id: z.string().optional(), fps_id_type: z.string().optional(), legal_address: responseRecipientPaymentDetailsLegalAddress.optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsImps = z.object({account_number: z.string().optional(), bank_name: z.string().optional(), destination_country: z.string().optional(), ifsc_code: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsInstapay = z.object({account_number: z.string().optional(), bank_code: z.string().optional(), bank_name: z.string().optional(), destination_country: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsIpp = z.object({bank_name: z.string().optional(), destination_country: z.string().optional(), iban: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsNip = z.object({account_number: z.string().optional(), bank_code: z.string().optional(), bank_name: z.string().optional(), destination_country: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsPix = z.object({legal_address: responseRecipientPaymentDetailsLegalAddress.optional(), national_id_number: z.string().optional(), pix_key: z.string().optional(), pix_key_type: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsPse = z.object({account_number: z.string().optional(), account_type: z.string().optional(), bank_code: z.string().optional(), destination_country: z.string().optional(), document_number: z.string().optional(), document_type: z.string().optional(), recipient_name: z.string().optional()}); export const responseRecipientPaymentDetailsSepa = z.object({bic: z.string(), iban: z.string()}); export const responseRecipientPaymentDetailsSpei = z.object({clabe: z.string(), legal_address: responseRecipientPaymentDetailsLegalAddress.optional(), national_id_number: z.string().optional()}); export const responseRecipientPaymentDetailsSwift = z.object({bank_country: z.string().optional(), bank_name: z.string().optional(), bic: z.string(), iban: z.string(), legal_address: responseRecipientPaymentDetailsLegalAddress.optional()}); export const responseRecipientDetailsType = z.enum(["Crypto", "Sepa", "FasterPayment", "Ach", "Swift", "Spei", "Card", "Pix", "FpsHk", "Imps", "Instapay", "BiFast", "Nip", "Ipp", "Pse", "CrossChainCrypto"]); export const responseRecipientPaymentDetailsResponse = z.object({ach: responseRecipientPaymentDetailsAch.optional(), bi_fast: responseRecipientPaymentDetailsBiFast.optional(), card: responseRecipientPaymentDetailsCard.optional(), cross_chain_crypto: responseRecipientPaymentDetailsCrossChainCrypto.optional(), crypto: responseRecipientPaymentDetailsCrypto.optional(), currencies: z.array(z.string()), faster_payment: responseRecipientPaymentDetailsFasterPayment.optional(), fps_hk: responseRecipientPaymentDetailsFpsHk.optional(), id: z.string(), imps: responseRecipientPaymentDetailsImps.optional(), instapay: responseRecipientPaymentDetailsInstapay.optional(), ipp: responseRecipientPaymentDetailsIpp.optional(), nip: responseRecipientPaymentDetailsNip.optional(), pix: responseRecipientPaymentDetailsPix.optional(), pse: responseRecipientPaymentDetailsPse.optional(), sepa: responseRecipientPaymentDetailsSepa.optional(), spei: responseRecipientPaymentDetailsSpei.optional(), swift: responseRecipientPaymentDetailsSwift.optional(), type: responseRecipientDetailsType}); 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 payment details * * PUT /api/v1/recipients/{recipientId}/payment_details/{paymentDetailsId} * * Also accepts auth: ChainId + UserAddress + WirexPartnerToken */ export const updateApiApiV1RecipientsRecipientIdPaymentDetailsPaymentDetailsId = async (args: UpdateApiApiV1RecipientsRecipientIdPaymentDetailsPaymentDetailsIdArgs, options?: UpdateApiApiV1RecipientsRecipientIdPaymentDetailsPaymentDetailsIdOptions) => { const {baseUrl = "https://api-baas.wirexapp.com", fetch: fetchFn = fetch, WirexUserToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "*/*") headers.set('accept', "application/json") if (WirexUserToken !== undefined) headers.set("Authorization", WirexUserToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/recipients/${encodeURIComponent(String(args.recipientId))}/payment_details/${encodeURIComponent(String(args.paymentDetailsId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(responseRecipientPaymentDetailsResponse, await res.json()) };