export type CreateApiIWebhookStrapiPaymentGatewayArgs = {paymentGateway: number, 'Stripe-Signature': string}; export type CreateApiIWebhookStrapiPaymentGatewayOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Handle Stripe checkout webhook events (public) * * POST /i/webhook/strapi/{paymentGateway} */ export const createApiIWebhookStrapiPaymentGateway = async (args: CreateApiIWebhookStrapiPaymentGatewayArgs, options: CreateApiIWebhookStrapiPaymentGatewayOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args['Stripe-Signature'] != null) headers.set("Stripe-Signature", String(args['Stripe-Signature'])) const url = `${baseUrl.replace(/\/+$/, '')}/i/webhook/strapi/${encodeURIComponent(String(args.paymentGateway))}${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 };