import {z} from 'zod' export type CreateApiV024PayoutsInitiateChimoneyArgs = {body: {subAccount?: string | undefined, turnOffNotification?: boolean | undefined, redirect_url?: string | undefined, debitCurrency?: string | undefined, chimoneys: Array<{email?: string | undefined, phone?: string | undefined, valueInUSD?: number | undefined, amount?: number | undefined, twitter?: string | undefined, redeemData?: ({walletID?: string | undefined, interledgerWalletAddress?: string | undefined, account_bank?: string | undefined, account_number?: string | undefined, currency?: string | undefined, branch_code?: string | undefined, fullname?: string | undefined}) | undefined}>, enableXUMMPayment?: boolean | undefined, enableInterledgerPayment?: boolean | undefined, cryptoPayment?: (Array<{xrpl?: ({address?: string | undefined, issuer?: string | undefined, currency?: string | undefined}) | undefined}>) | undefined}}; export type CreateApiV024PayoutsInitiateChimoneyOptions = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiV024PayoutsInitiateChimoneyResponse = z.object({status: z.string().optional(), message: z.string().optional(), data: z.object({paymentLink: z.string().optional(), error: z.string().optional(), data: z.array(z.object({})).optional(), cryptoPayment: z.object({xrpl: z.object({}).optional(), eth: z.object({}).optional(), bsc: z.object({}).optional(), xummPayment: z.string().optional()}).optional(), interledgerPayment: z.object({}).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 }; /** * Initiate Chimoney transaction. * * POST /v0.2.4/payouts/initiate-chimoney */ export const createApiV024PayoutsInitiateChimoney = async (args: CreateApiV024PayoutsInitiateChimoneyArgs, options?: CreateApiV024PayoutsInitiateChimoneyOptions) => { const {baseUrl = "https://api.chimoney.io", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyAuth !== undefined) headers.set("X-API-KEY", apiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v0.2.4/payouts/initiate-chimoney${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(createApiV024PayoutsInitiateChimoneyResponse, await res.json()) };