export type PostRefundCreateRequest = {amount?: number | undefined, orderline_pk?: number | undefined, refund_type?: (4 | 5 | 6) | undefined}; export type CreateApiWsSavRefundArgs = {body: PostRefundCreateRequest}; export type CreateApiWsSavRefundOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a refund on an Orderline * * POST /ws/sav/refund * * Also accepts auth: BasicAuth */ export const createApiWsSavRefund = async (args: CreateApiWsSavRefundArgs, options?: CreateApiWsSavRefundOptions) => { const {baseUrl = "https://preprod.backmarket.co.jp", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/ws/sav/refund${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 res.text() };