import type { MedusaContainer } from "@medusajs/framework/types"; /** * Core webhook processing shared by the async subscriber and the retry cron. * * Given a verified, persisted PayPal event, this resolves the cart's PayPal * payment session, applies the event's status transition (guarded by * `ALLOWED_TRANSITIONS`), merges capture/refund identifiers onto the session, * and — for settled captures — completes a cart the buyer's browser never * finalized. Everything here is pure or container-driven so it can be * unit-tested without an HTTP layer. */ /** PayPal event type → Medusa payment-session status it should produce. */ export declare const EVENT_STATUS_MAP: Record; /** * Whether a session may move from `from` to `to`. Out-of-order or replayed * webhooks must never regress a session (e.g. captured → authorized). */ export declare function isTransitionAllowed(from: string, to: string): boolean; /** Event families this plugin handles; anything else is recorded as ignored. */ export declare const SUPPORTED_EVENT_PREFIXES: string[]; /** True for event types under one of `SUPPORTED_EVENT_PREFIXES`. */ export declare function isAllowedEventType(eventType: string): boolean; /** * Whether a processing failure is worth retrying. Missing carts/sessions are * permanent and go straight to the dead-letter queue; everything else (DB or * PayPal hiccups) is scheduled for retry. */ export declare function isRetryableError(error: unknown): boolean; /** Initial attempt plus one retry per entry in the schedule. */ export declare const MAX_WEBHOOK_ATTEMPTS: number; /** When to retry after `attemptCount` failures, or null once exhausted. */ export declare function computeNextRetryAt(attemptCount: number): Date | null; /** * The event's `resource` object. PayPal occasionally delivers it as a JSON * string; anything unparseable yields `{}` so downstream lookups stay safe. */ export declare function normalizeResource(payload: Record): Record; /** Event/resource version with any leading "v" stripped, or null. */ export declare function normalizeEventVersion(payload: Record): string | null; /** Pull the capture id out of a refund resource's "up" HATEOAS link. */ export declare function extractCaptureIdFromLinks(resource: Record): string | null; /** PayPal + Medusa identifiers pulled from a webhook resource. */ export interface ExtractedIdentifiers { orderId: string | null; captureId: string | null; refundId: string | null; cartId: string | null; } /** * Pull order / capture / refund ids and the cart id (`custom_id`) out of a * webhook resource. The shape differs per event family, and some * PAYMENT.CAPTURE.* events actually carry a refund resource — see inline. */ export declare function extractIdentifiers(resource: Record, eventType: string): ExtractedIdentifiers; /** * True when a refund resource demonstrably covers less than the captured * amount. Uses the refund's cumulative `total_refunded_amount` (falling back * to the single refund amount) against the capture amount stored on the * session (falling back to the session total). Returns false — i.e. treat as * a full refund, matching the previous behavior — whenever the amounts can't * be determined. */ export declare function isPartialRefund(resource: Record, sessionData: Record): boolean; /** * Whether the webhook processor may complete a paid-but-unfinalized cart. * * The storefront's `/store/paypal-complete` call is the primary completion * path, but it only runs in the buyer's browser. If the tab closes, crashes, * or reloads between the capture and that call, the money is captured and no * Medusa order is ever created. The PAYMENT.CAPTURE.COMPLETED webhook is the * server-side safety net for exactly that gap. * * Enabled by default (completing a cart whose payment settled is the correct * outcome); set PAYPAL_WEBHOOK_COMPLETE_CART=false to disable. */ export declare function isWebhookCartCompletionEnabled(envValue?: string | undefined): boolean; /** Events that prove settled funds and may therefore complete the cart. */ export declare function isCartCompletingEventType(eventType: string): boolean; /** Outcome of `processPayPalWebhookEvent`, mainly for logging/metrics. */ export interface ProcessResult { orderId: string | null; captureId: string | null; refundId: string | null; cartId: string | null; sessionUpdated: boolean; cartCompleted: boolean; } /** * Apply one verified PayPal webhook event to the matching payment session. * * Throws on failures the caller should retry (see `isRetryableError`); * returns normally — with `sessionUpdated: false` — for events that carry no * status mapping or whose cart cannot be resolved. */ export declare function processPayPalWebhookEvent(container: MedusaContainer, input: { eventType: string; payload: Record; }): Promise; //# sourceMappingURL=webhook-processor.d.ts.map