import Stripe from 'stripe'; import { ShopProduct } from '../types.js'; /** * F136 Phase 1 — Stripe SDK wrapper. * * Lazy-init: the Stripe client is constructed the first time it's needed, * not at import time. Two reasons: * 1. Tests can run without STRIPE_SECRET_KEY (calls are mocked elsewhere). * 2. Sites that don't actually use Stripe (free-tier marketing sites * that only consume product collections) won't crash on missing env. * * Mode: per-site. Each site loads its own STRIPE_SECRET_KEY from env; * `getStripe(secretKey?)` accepts an explicit key for multi-tenant cms-admin * where the key lives in the site config rather than process.env. */ /** * Get a memoized Stripe client. * * @param secretKey — explicit key (e.g. site.stripeSecretKey from cms-admin * site config). Falls back to process.env.STRIPE_SECRET_KEY. */ declare function getStripe(secretKey?: string): Stripe; /** Test/cleanup hook — clears the memoized client cache. */ declare function resetStripeClientCache(): void; interface SyncResult { /** Stripe Product id (created or reused). */ stripeProductId: string; /** Map of currency → Stripe Price id (active price for each currency). */ stripePriceIds: Record; /** Stripe Price ids that were archived in this sync (changed amounts). */ archivedPriceIds: string[]; /** Whether the Stripe Product was created (true) or updated (false). */ created: boolean; } interface SyncOptions { /** Pass an explicit secret key (multi-tenant cms-admin). Falls back to env. */ secretKey?: string; /** Override the active flag (e.g. archive on product deletion). */ active?: boolean; } /** * Push a CMS product document to Stripe. * * Behaviour: * - status='active' → Stripe Product is active, Prices are active * - status='draft' → Stripe Product is INactive (no checkout possible) * - status='archived'→ Stripe Product is INactive, Prices archived too */ declare function syncProductToStripe(product: ShopProduct, opts?: SyncOptions): Promise; /** * Archive a product in Stripe (called when the CMS document is deleted * or its status changes to 'archived'). Stripe doesn't allow deleting * Products that have ever been associated with a Charge or Subscription, * so we always archive instead of delete. */ declare function archiveProductInStripe(stripeProductId: string, opts?: SyncOptions): Promise; export { type SyncOptions, type SyncResult, archiveProductInStripe, getStripe, resetStripeClientCache, syncProductToStripe };