export type Dish = {positionId: string, name: string, count: number, positionCount?: number | undefined, sum: number, categoryId?: number | undefined, category: string, orderNumber?: string | undefined, type?: string | undefined, dishId: string, rawSum?: number | undefined, price: number, positionRawSum?: number | undefined, linkedTo?: string | undefined, additionalInfo?: ({system?: string | undefined, comment?: string | undefined, status?: string | undefined, productGroupExternalId?: string | undefined}) | undefined}; export type OrderEvent = {webhookType: string, eventTime: string, actualOrders: Array<{orderId?: string | undefined, revision: unknown}>, changedOrders: Array<{orderInfo?: ({billId?: string | undefined, orderNumber?: string | undefined, totalSum?: number | undefined, rawSum?: number | undefined, paidSum?: number | undefined, discountSum?: number | undefined, waiter?: string | undefined, waiterId?: string | undefined, tables?: Array | undefined, discounts?: ({list?: (Array<{id?: string | undefined, name?: string | undefined, sum?: number | undefined, code?: number | undefined}>) | undefined}) | undefined, guests?: (Array<{name?: string | undefined, id?: string | undefined, additionalInfo?: ({system?: string | undefined, comment?: string | undefined}) | undefined, dishes?: Array | undefined}>) | undefined, state?: string | undefined, isDelivery?: boolean | undefined, splitAvailable?: boolean | undefined, version?: number | undefined, payments?: (Array<{sum?: number | undefined, paymentTypeName?: string | undefined, paymentTypeKind?: string | undefined, additionalInfo?: ({system?: string | undefined, isPrepay?: boolean | undefined, isExternal?: boolean | undefined, status?: string | undefined, externalId?: string | undefined, typeId?: string | undefined}) | undefined}>) | undefined, orderType?: string | undefined, additionalInfo?: ({system?: string | undefined, tablesDetails?: (Array<{externalId?: string | undefined, name?: string | undefined, fullName?: string | undefined, number?: number | undefined, seatingCapacity?: number | undefined, description?: string | undefined, isActive?: boolean | undefined}>) | undefined, waiterDetails?: ({externalId?: string | undefined, name?: string | undefined, phone?: string | undefined, pinCode?: string | undefined}) | undefined}) | undefined, tableId?: string | undefined, created?: string | undefined, banquetOrder?: boolean | undefined, billAmountForTips?: number | undefined}) | undefined}>}; export type CreateApiApiShaketopayComUaCallbackWebhookArgs = {restoId: string, body: OrderEvent}; export type CreateApiApiShaketopayComUaCallbackWebhookOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * АПІ для виклику кешування рахунків(ordersCache) * * POST //api.shaketopay.com.ua/callback/webhook */ export const createApiApiShaketopayComUaCallbackWebhook = async (args: CreateApiApiShaketopayComUaCallbackWebhookArgs, options: CreateApiApiShaketopayComUaCallbackWebhookOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.restoId != null) headers.set("restoId", String(args.restoId)) const url = `${baseUrl.replace(/\/+$/, '')}//api.shaketopay.com.ua/callback/webhook${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 };