export type CreateApiOrdersArgs = {body: {code?: string | undefined, customer_id: string, customer: Record, items: Array, shipping?: Record | undefined, payments: Array, closed?: boolean | undefined, metadata?: string | undefined, device?: Record | undefined, location?: Record | undefined, ip?: string | undefined, session_id?: string | undefined, antifraud_enabled?: boolean | undefined, antifraud?: Record | undefined, SubMerchant?: Record | undefined}}; export type CreateApiOrdersOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Criar pedido * * POST /orders/ */ export const createApiOrders = async (args: CreateApiOrdersArgs, options?: CreateApiOrdersOptions) => { const {baseUrl = "https://api.mundipagg.com/core/v1", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/orders/${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 (await res.json()) as unknown };