export type CreateApiServicesCollectorArgs = {app_identifiant: string, collector_key: string, invoice: string}; export type CreateApiServicesCollectorOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Push to purchase collector * * POST /services/collector */ export const createApiServicesCollector = async (args: CreateApiServicesCollectorArgs, options?: CreateApiServicesCollectorOptions) => { const {baseUrl = "https://api.sinao.app/v1", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.app_identifiant != null) query.append("app_identifiant", String(args.app_identifiant)) if (args.collector_key != null) query.append("collector_key", String(args.collector_key)) if (args.invoice != null) query.append("invoice", String(args.invoice)) const url = `${baseUrl.replace(/\/+$/, '')}/services/collector${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };