export type Amount = {amount: string, currency: string}; export type MerchantReference = 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 Extensions = {industry?: ({travel?: ({startDate?: string | undefined, endDate?: string | undefined}) | undefined}) | undefined, type?: ({link?: ({notification: {phoneCountryCode?: string | undefined, phoneNumber?: string | undefined, preferredLanguage?: ('' | 'english' | 'italiano' | 'francais' | 'deutsch' | 'espanol' | 'dutch' | 'suomi' | 'portuguese') | undefined, emailAddress?: string | undefined, channels: Array<'email' | 'sms'>}}) | undefined}) | undefined}; export type CreateApiV2InstorePaybylinkOrdersArgs = {body: {totalAmount: Amount, merchantReference?: MerchantReference | undefined, type?: string | undefined, items?: Items | undefined, extensions?: Extensions | undefined}}; export type CreateApiV2InstorePaybylinkOrdersOptions = {baseUrl?: string | undefined, InstoreApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create an offline pay-by-link order * * POST /v2/instore/paybylink/orders */ export const createApiV2InstorePaybylinkOrders = async (args: CreateApiV2InstorePaybylinkOrdersArgs, options?: CreateApiV2InstorePaybylinkOrdersOptions) => { 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(/\/+$/, '')}/v2/instore/paybylink/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 };