export type PostPayments = {payment: {patient_id: number, amount: number, currency?: string | undefined, payment_type_id?: number | undefined, transaction_id: string, paid_at?: string | undefined, charge_splits?: Record | undefined, provider_splits?: Record | undefined, notes?: string | undefined}}; export type CreateApiPaymentsArgs = {'Nex-Api-Version': string, subdomain: string, location_id: number, body: PostPayments}; export type CreateApiPaymentsOptions = {baseUrl?: string | undefined, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create payment * * POST /payments */ export const createApiPayments = async (args: CreateApiPaymentsArgs, options?: CreateApiPaymentsOptions) => { const {baseUrl = "https://nexhealth.info", fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['Nex-Api-Version'] != null) headers.set("Nex-Api-Version", String(args['Nex-Api-Version'])) if (args.subdomain != null) query.append("subdomain", String(args.subdomain)) if (args.location_id != null) query.append("location_id", String(args.location_id)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/payments${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 };