# app/modules/billing/exceptions.py """ Billing module exceptions. Custom exceptions for subscription, billing, and payment operations. """ from app.exceptions import BusinessLogicException, ResourceNotFoundException class BillingException(BusinessLogicException): """Base exception for billing module errors.""" pass class SubscriptionNotFoundException(ResourceNotFoundException): """Raised when a subscription is not found.""" def __init__(self, vendor_id: int): super().__init__("Subscription", str(vendor_id)) class TierNotFoundException(ResourceNotFoundException): """Raised when a subscription tier is not found.""" def __init__(self, tier_code: str): super().__init__("SubscriptionTier", tier_code) class TierLimitExceededException(BillingException): """Raised when a tier limit is exceeded.""" def __init__(self, message: str, limit_type: str, current: int, limit: int): super().__init__(message) self.limit_type = limit_type self.current = current self.limit = limit class FeatureNotAvailableException(BillingException): """Raised when a feature is not available in current tier.""" def __init__(self, feature: str, current_tier: str, required_tier: str): message = f"Feature '{feature}' requires {required_tier} tier (current: {current_tier})" super().__init__(message) self.feature = feature self.current_tier = current_tier self.required_tier = required_tier class StripeNotConfiguredException(BillingException): """Raised when Stripe is not configured.""" def __init__(self): super().__init__("Stripe is not configured") class PaymentFailedException(BillingException): """Raised when a payment fails.""" def __init__(self, message: str, stripe_error: str | None = None): super().__init__(message) self.stripe_error = stripe_error class WebhookVerificationException(BillingException): """Raised when webhook signature verification fails.""" def __init__(self, message: str = "Invalid webhook signature"): super().__init__(message) __all__ = [ "BillingException", "SubscriptionNotFoundException", "TierNotFoundException", "TierLimitExceededException", "FeatureNotAvailableException", "StripeNotConfiguredException", "PaymentFailedException", "WebhookVerificationException", ]