export type Amount = {amount: string, currency: string}; export type Items = Array<{gtin?: string | undefined, quantity: number, price: Amount, name: string, category: string, subcategory?: Array | undefined, sku: string, brand?: string | undefined, pageUrl?: string | undefined, imageUrl?: string | undefined}>; export type MerchantReference = string; export type CreateApiV1InstoreOrdersArgs = {body: {totalAmount: Amount, preApprovalCode: string, requestId: string, merchantOperatorId: string, items: Items, merchantReference: MerchantReference}}; export type CreateApiV1InstoreOrdersOptions = {baseUrl?: string | undefined, InstoreApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create instore order * * POST /v1/instore/orders */ export const createApiV1InstoreOrders = async (args: CreateApiV1InstoreOrdersArgs, options?: CreateApiV1InstoreOrdersOptions) => { const {baseUrl = "https://integration.api.scalapay.com", fetch: fetchFn = fetch, InstoreApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (InstoreApiKeyAuth !== undefined) headers.set("Authorization", InstoreApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/v1/instore/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 };