export type ItemObject = {id?: string | undefined, name?: string | undefined, reference?: string | undefined, price?: number | undefined, quantity?: number | undefined, discount?: number | undefined, taxRate?: number | undefined, totalPrice?: number | undefined}; export type InvoiceStatus = 'opened' | 'paid' | 'paid_in_cash' | 'expired'; export type InvoiceObject = {id?: string | undefined, reference?: string | undefined, customerId?: string | undefined, customerName?: string | undefined, currency: string, dueDate: string, orderDetails?: Array | undefined, subTotalAmount?: number | undefined, deliveryCharges?: number | undefined, deductedAmount?: number | undefined, totalTax?: number | undefined, finalAmount?: number | undefined, status?: InvoiceStatus | undefined, redirectUrlAfterPayment?: string | undefined, deviceId?: string | undefined, enableMultiplePayment?: boolean | undefined, nbrPayments?: number | undefined, paymentUrl?: string | undefined, downloadUrl?: string | undefined, createdAt?: string | undefined, updatedAt?: string | undefined}; export type CreateApiInvoicesArgs = {send_notification?: boolean | undefined, body: InvoiceObject}; export type CreateApiInvoicesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new invoice * * POST /invoices */ export const createApiInvoices = async (args: CreateApiInvoicesArgs, options?: CreateApiInvoicesOptions) => { const {baseUrl = "https://api.test.bictorys.com/pay/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args.send_notification != null) query.append("send_notification", String(args.send_notification)) if (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/invoices${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 undefined };