export type GetApiDownloadInvoiceIdArgs = {invoiceId: string, op_token: string}; export type GetApiDownloadInvoiceIdOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download invoice * * GET /download/{invoiceId} */ export const getApiDownloadInvoiceId = async (args: GetApiDownloadInvoiceIdArgs, options?: GetApiDownloadInvoiceIdOptions) => { const {baseUrl = "https://api.test.bictorys.com/pay/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/pdf") if (args.op_token != null) query.append("op_token", String(args.op_token)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/download/${encodeURIComponent(String(args.invoiceId))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };