# Copyright (c) 2025 Patrick Motsch # All rights reserved. """ Central Stripe SDK initialization. All Stripe interactions MUST use getStripeClient() to ensure consistent API key, API version, and fallback handling across billing and subscription flows. """ import logging from typing import Optional logger = logging.getLogger(__name__) _stripeInitialized = False def getStripeClient(): """ Initialize and return the configured Stripe SDK module. Raises ValueError if no Stripe secret key is configured. """ import stripe from modules.shared.configuration import APP_CONFIG apiVersion = APP_CONFIG.get("STRIPE_API_VERSION") if apiVersion: stripe.api_version = apiVersion secretKey = APP_CONFIG.get("STRIPE_SECRET_KEY_SECRET") or APP_CONFIG.get("STRIPE_SECRET_KEY") if not secretKey: raise ValueError("STRIPE_SECRET_KEY_SECRET not configured") stripe.api_key = secretKey return stripe