export type PaymentLinkStatus = 'opened' | 'paid' | 'paid_in_cash' | 'expired'; export type PaymentLinkObject = {id?: string | undefined, reference?: string | undefined, description?: string | undefined, amount: number, currency: string, dueDate?: string | undefined, status?: PaymentLinkStatus | undefined, paymentUrl?: string | undefined, redirectUrlAfterPayment?: string | undefined, enableMultiplePayment?: boolean | undefined, nbrPayments?: number | undefined, deviceId?: string | undefined, cashier?: string | undefined, enableCardPaymentOnly?: boolean | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, customerName?: string | undefined, customerPhone?: string | undefined, customerEmail?: string | undefined, customerLocale?: string | undefined} | {id?: string | undefined, reference?: string | undefined, description?: string | undefined, amount: number, currency: string, dueDate?: string | undefined, status?: PaymentLinkStatus | undefined, paymentUrl?: string | undefined, redirectUrlAfterPayment?: string | undefined, enableMultiplePayment?: boolean | undefined, nbrPayments?: number | undefined, deviceId?: string | undefined, cashier?: string | undefined, enableCardPaymentOnly?: boolean | undefined, createdAt?: string | undefined, updatedAt?: string | undefined, customerId?: string | undefined}; export type CreateApiPaymentlinksArgs = {body: PaymentLinkObject}; export type CreateApiPaymentlinksOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new payment link * * POST /paymentlinks */ export const createApiPaymentlinks = async (args: CreateApiPaymentlinksArgs, options?: CreateApiPaymentlinksOptions) => { 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 (ApiKeyAuth !== undefined) headers.set("X-API-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/paymentlinks${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 };