export type SpeiPayinAmount = {currencySymbol: 'MXN', value: string}; export type SpeiPayinRail = {amount: SpeiPayinAmount, type: 'spei'}; export type PixPayinAmount = {currencySymbol: 'BRL', value: string}; export type PixPayinRail = {amount: PixPayinAmount, type: 'pix'}; export type CvuPayinAmount = {currencySymbol: 'ARS', value: string}; export type CvuPayinRail = {amount: CvuPayinAmount, type: 'cvu'}; export type AchPayinAmount = {currencySymbol: 'USD', value: string}; export type AchPayinRail = {amount: AchPayinAmount, type: 'ach'}; export type WirePayinAmount = {currencySymbol: 'USD', value: string}; export type WirePayinRail = {amount: WirePayinAmount, type: 'wire'}; export type SimulateSandboxPayinRequest = {destinationAccountId: string, rail: SpeiPayinRail | PixPayinRail | CvuPayinRail | AchPayinRail | WirePayinRail}; export type CreateApiApiSandboxSimulatePayinArgs = {'on-behalf-of'?: string | undefined, body: SimulateSandboxPayinRequest}; export type CreateApiApiSandboxSimulatePayinOptions = {baseUrl?: string | undefined, bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Simulate a payin * * POST /api/sandbox/simulate/payin */ export const createApiApiSandboxSimulatePayin = async (args: CreateApiApiSandboxSimulatePayinArgs, options?: CreateApiApiSandboxSimulatePayinOptions) => { 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") 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/sandbox/simulate/payin${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 undefined };