import Stripe from 'stripe'; /** * Stripe's side of abandoned orders, as PayPal's `reconcileAbandonedOrders`: * every Stripe order still unpaid an hour after it was created is checked * with Stripe, which alone knows whether the shopper gave up (a 3-D Secure * check left open sends no event, so such an order stayed `pending` forever) * or the money is on its way (a bank debit can be `processing` for days). * * For each order, the live state of every PaymentIntent made for it: * - one `succeeded` / `requires_capture`: the shopper paid and the webhook * was lost; the payment is recorded and the order placed, as the webhook * would have done; * - one `processing`, or a state this code does not know: wait; * - else (never finished, or canceled): each open intent is canceled at * Stripe first, so it can never be paid later, then the order is canceled * and its cart given back (`cancelAbandonedOrder`), so the shopper's cart * recovery link works again. * Any error leaves the order as it is, for the next run. */ export declare const DEFAULT_ABANDONED_TTL_HOURS = 1; /** * An order with no stored intent (made before the `stripe_payment_intent` * table, or its insert failed) can only be looked up with Stripe's search, * which "can be up to an hour behind during outages": such an order waits * until well past that. */ export declare const SEARCH_FALLBACK_MIN_AGE_HOURS = 6; /** Orders looked at per run; the rest wait for the next one */ export declare const ORDERS_PER_RUN = 100; export interface IntentState { id: string; status: string; } export type StripeOrderDecision = { action: 'record'; intent: T; kind: 'capture' | 'authorization'; } | { action: 'wait'; reason: string; } | { action: 'cancel'; open: T[]; }; /** What to do with an unpaid order, from its intents' live states */ export declare function decideAbandonedStripeOrder(intents: T[]): StripeOrderDecision; export interface UnpaidStripeOrder { order_id: number; uuid: string; created_at: Date | string; } export interface ReconcileDeps { storedIntentIds: (orderId: number) => Promise; /** Stripe's search by the order's uuid (metadata); throws where search is not available (India) */ searchIntentIds: (orderUuid: string) => Promise; /** The intent's live state; null when this Stripe account does not know it (keys changed) */ retrieve: (id: string) => Promise; cancelIntent: (id: string) => Promise; record: (order: UnpaidStripeOrder, intent: Stripe.PaymentIntent, kind: 'capture' | 'authorization') => Promise<'recorded' | 'mismatch' | 'gone'>; cancelAbandonedOrder: (uuid: string, reason: string) => Promise<{ cartReopened: boolean; }>; now: () => number; } /** One unpaid Stripe order; answers what happened, for the log */ export declare function reconcileStripeOrder(order: UnpaidStripeOrder, deps: ReconcileDeps): Promise; /** The intents stored for an order (`stripe_payment_intent`), oldest first */ export declare function storedIntentIds(orderId: number): Promise; /** Records a lost webhook's payment under the order's row lock, as the webhook does */ export declare function recordLostPayment(order: UnpaidStripeOrder, intent: Stripe.PaymentIntent, kind: 'capture' | 'authorization'): Promise<'recorded' | 'mismatch' | 'gone'>; /** * Stripe orders created before `cutoff` that were never paid nor canceled, * newest first: an order that keeps waiting (a bank debit, an intent of * another Stripe account) never holds back the newer ones */ export declare function findUnpaidStripeOrders(cutoff: Date): Promise; /** * The `stripeReconcileAbandonedOrders` cron job (every 15 minutes; config * `system.stripe.reconcileSchedule`, `reconcileEnabled`, and * `abandonedOrderTtlHours`, default 1). Per-order failures are logged and * retried on the next run. */ export default function reconcileAbandonedStripeOrders(): Promise;