export type UserChangedResponse = {webhookType: string, eventTime: string, action: string, user: {id?: string | undefined, cellPhone?: string | undefined, name?: string | undefined}}; export type CreateApiApiShaketopayComUaCallbackWebhookArgs = {restoId: string, body: UserChangedResponse}; export type CreateApiApiShaketopayComUaCallbackWebhookOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Сервіс отримання відповіді від ресторану про зміни у користувачах * * 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 };