import type Stripe from 'stripe'; /** * Register a webhook event handler */ export declare function onWebhookEvent(eventType: WebhookEventType, handler: WebhookHandler): void; /** * Register multiple webhook handlers at once */ export declare function registerWebhookHandlers(handlerMap: Record): void; /** * Construct and verify a webhook event from the raw request. * * Async on every runtime, deliberately. Bun resolves the Stripe SDK's crypto * provider to WebCrypto's `SubtleCrypto`, which is async-only, so the SDK's * synchronous `constructEvent` throws "SubtleCryptoProvider cannot be used in a * synchronous context" there. This package used to wrap that sync call under * this name and offer the working one as `constructEventAsync`, which made the * shorter and more obvious export the one that could never work on the * framework's own default runtime. * * It failed where it hurt most. Verification lives inside the caller's * try/catch, so the throw surfaced as a 401 on every genuine Stripe delivery: * Stripe retried, every retry 401'd, and local subscription state silently * stopped tracking reality. Tests that call the handler directly rather than * POSTing a signed body never touch verification at all, so nothing caught it * (stacksjs/stacks#2355). * * There is one name now, and it works on Node and Bun alike. A caller that * genuinely needs the synchronous path on Node can still reach * `stripe.webhooks.constructEvent` through the exported client. * * `tolerance` (in seconds) controls how much clock skew between Stripe and * this server is acceptable before signatures are rejected. Stripe's SDK * default is 300s; tightening this is recommended in production but the * previous code dropped the value entirely, so a configured tolerance was * silently ignored. */ export declare function constructEvent(payload: string | Buffer, signature: string, secret: string, tolerance?: number): Promise; /** * Alias of {@link constructEvent}, kept so callers that adopted this name while * `constructEvent` could not work on Bun keep compiling unchanged. * * @deprecated Use {@link constructEvent}. It is async on every runtime as of * stacksjs/stacks#2355, so the two are the same function and one name is enough. */ export declare function constructEventAsync(payload: string | Buffer, signature: string, secret: string, tolerance?: number): Promise; /** * Handle an incoming webhook event */ export declare function handleWebhookEvent(event: Stripe.Event): Promise<{ handled: boolean, eventType: string, errors?: string[] }>; /** * Process a webhook request */ export declare function processWebhook(payload: string | Buffer, signature: string, config: WebhookConfig): Promise<{ success: boolean, eventType?: string, error?: string }>; /** * Register payment intent handlers */ export declare function onPaymentIntent(handlers: { succeeded?: WebhookHandler failed?: WebhookHandler created?: WebhookHandler canceled?: WebhookHandler }): void; /** * Register subscription handlers */ export declare function onSubscription(handlers: { created?: WebhookHandler updated?: WebhookHandler deleted?: WebhookHandler trialWillEnd?: WebhookHandler }): void; /** * Register invoice handlers */ export declare function onInvoice(handlers: { paid?: WebhookHandler paymentFailed?: WebhookHandler created?: WebhookHandler finalized?: WebhookHandler }): void; /** * Register checkout session handlers */ export declare function onCheckout(handlers: { completed?: WebhookHandler expired?: WebhookHandler }): void; /** * Register charge handlers */ export declare function onCharge(handlers: { succeeded?: WebhookHandler failed?: WebhookHandler refunded?: WebhookHandler disputed?: WebhookHandler }): void; /** * Extract payment intent from event */ export declare function getPaymentIntent(event: Stripe.Event): Stripe.PaymentIntent | null; /** * Extract subscription from event */ export declare function getSubscription(event: Stripe.Event): Stripe.Subscription | null; /** * Extract invoice from event */ export declare function getInvoice(event: Stripe.Event): Stripe.Invoice | null; /** * Extract checkout session from event */ export declare function getCheckoutSession(event: Stripe.Event): Stripe.Checkout.Session | null; /** * Extract charge from event */ export declare function getCharge(event: Stripe.Event): Stripe.Charge | null; /** * Extract customer from event */ export declare function getCustomer(event: Stripe.Event): Stripe.Customer | null; declare const handlers: Map; export declare const manageWebhook: { onWebhookEvent: typeof onWebhookEvent; registerWebhookHandlers: typeof registerWebhookHandlers; constructEvent: typeof constructEvent; constructEventAsync: typeof constructEventAsync; handleWebhookEvent: typeof handleWebhookEvent; processWebhook: typeof processWebhook; onPaymentIntent: typeof onPaymentIntent; onSubscription: typeof onSubscription; onInvoice: typeof onInvoice; onCheckout: typeof onCheckout; onCharge: typeof onCharge; getPaymentIntent: typeof getPaymentIntent; getSubscription: typeof getSubscription; getInvoice: typeof getInvoice; getCheckoutSession: typeof getCheckoutSession; getCharge: typeof getCharge; getCustomer: typeof getCustomer }; export declare interface WebhookConfig { secret: string tolerance?: number } export type WebhookEventType = | 'payment_intent.succeeded' | 'payment_intent.payment_failed' | 'payment_intent.created' | 'payment_intent.canceled' | 'customer.subscription.created' | 'customer.subscription.updated' | 'customer.subscription.deleted' | 'customer.subscription.trial_will_end' | 'customer.created' | 'customer.updated' | 'customer.deleted' | 'invoice.paid' | 'invoice.payment_failed' | 'invoice.finalized' | 'invoice.created' | 'checkout.session.completed' | 'checkout.session.expired' | 'charge.succeeded' | 'charge.failed' | 'charge.refunded' | 'charge.dispute.created' | 'charge.dispute.closed' | 'payment_method.attached' | 'payment_method.detached' | 'setup_intent.succeeded' | 'setup_intent.setup_failed' | string; export type WebhookHandler = (_event: Stripe.Event) => Promise | void;