export type CreateApiWebhooksPaystackArgs = {'x-paystack-signature': string}; export type CreateApiWebhooksPaystackOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Paystack webhook endpoint * * POST /webhooks/paystack */ export const createApiWebhooksPaystack = async (args: CreateApiWebhooksPaystackArgs, options?: CreateApiWebhooksPaystackOptions) => { const {baseUrl = "https://api.novabilling.one", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['x-paystack-signature'] != null) headers.set("x-paystack-signature", String(args['x-paystack-signature'])) const url = `${baseUrl.replace(/\/+$/, '')}/webhooks/paystack${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 };