export type CreateApiIWebhookPayuPaymentGatewayArgs = {paymentGateway: number, body: {merchant_id: string, reference_sale: string, value: string, currency: string, state_pol: string, sign: string, response_message_pol?: string | undefined}}; export type CreateApiIWebhookPayuPaymentGatewayOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Handle PayU payment confirmation callbacks (public) * * POST /i/webhook/payu/{paymentGateway} */ export const createApiIWebhookPayuPaymentGateway = async (args: CreateApiIWebhookPayuPaymentGatewayArgs, options: CreateApiIWebhookPayuPaymentGatewayOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") const url = `${baseUrl.replace(/\/+$/, '')}/i/webhook/payu/${encodeURIComponent(String(args.paymentGateway))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };