refactor: remove backward compatibility code for pre-launch baseline
Clean up accumulated backward-compat shims, deprecated wrappers, unused aliases, and legacy code across the codebase. Since the platform is not live yet, this establishes a clean baseline. Changes: - Delete deprecated middleware/context.py (RequestContext, get_request_context) - Remove unused factory get_store_email_settings_service() - Remove deprecated pagination_full macro, /admin/platform-homepage route - Remove ConversationResponse, InvoiceSettings* unprefixed aliases - Simplify celery_config.py (remove empty LEGACY_TASK_MODULES) - Standardize billing exceptions: *Error aliases → *Exception names - Consolidate duplicate TierNotFoundError/FeatureNotFoundError classes - Remove deprecated is_admin_request() from Store/PlatformContextManager - Remove is_platform_default field, MediaUploadResponse legacy flat fields - Remove MediaItemResponse.url alias, update JS to use file_url - Update all affected tests and documentation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,14 +5,6 @@ Billing module services.
|
||||
Provides subscription management, Stripe integration, and admin operations.
|
||||
"""
|
||||
|
||||
from app.modules.billing.exceptions import (
|
||||
BillingServiceError,
|
||||
NoActiveSubscriptionError,
|
||||
PaymentSystemNotConfiguredError,
|
||||
StripePriceNotConfiguredError,
|
||||
SubscriptionNotCancelledError,
|
||||
TierNotFoundError,
|
||||
)
|
||||
from app.modules.billing.services.admin_subscription_service import (
|
||||
AdminSubscriptionService,
|
||||
admin_subscription_service,
|
||||
@@ -56,12 +48,6 @@ __all__ = [
|
||||
"admin_subscription_service",
|
||||
"BillingService",
|
||||
"billing_service",
|
||||
"BillingServiceError",
|
||||
"PaymentSystemNotConfiguredError",
|
||||
"TierNotFoundError",
|
||||
"StripePriceNotConfiguredError",
|
||||
"NoActiveSubscriptionError",
|
||||
"SubscriptionNotCancelledError",
|
||||
"FeatureService",
|
||||
"feature_service",
|
||||
"PlatformPricingService",
|
||||
|
||||
@@ -16,12 +16,12 @@ from datetime import datetime
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.billing.exceptions import (
|
||||
BillingServiceError,
|
||||
NoActiveSubscriptionError,
|
||||
PaymentSystemNotConfiguredError,
|
||||
StripePriceNotConfiguredError,
|
||||
SubscriptionNotCancelledError,
|
||||
TierNotFoundError,
|
||||
BillingException,
|
||||
NoActiveSubscriptionException,
|
||||
PaymentSystemNotConfiguredException,
|
||||
StripePriceNotConfiguredException,
|
||||
SubscriptionNotCancelledException,
|
||||
TierNotFoundException,
|
||||
)
|
||||
from app.modules.billing.models import (
|
||||
AddOnProduct,
|
||||
@@ -93,7 +93,7 @@ class BillingService:
|
||||
Get a tier by its code.
|
||||
|
||||
Raises:
|
||||
TierNotFoundError: If tier doesn't exist
|
||||
TierNotFoundException: If tier doesn't exist
|
||||
"""
|
||||
tier = (
|
||||
db.query(SubscriptionTier)
|
||||
@@ -105,7 +105,7 @@ class BillingService:
|
||||
)
|
||||
|
||||
if not tier:
|
||||
raise TierNotFoundError(tier_code)
|
||||
raise TierNotFoundException(tier_code)
|
||||
|
||||
return tier
|
||||
|
||||
@@ -126,12 +126,12 @@ class BillingService:
|
||||
Dict with checkout_url and session_id
|
||||
|
||||
Raises:
|
||||
PaymentSystemNotConfiguredError: If Stripe not configured
|
||||
TierNotFoundError: If tier doesn't exist
|
||||
StripePriceNotConfiguredError: If price not configured
|
||||
PaymentSystemNotConfiguredException: If Stripe not configured
|
||||
TierNotFoundException: If tier doesn't exist
|
||||
StripePriceNotConfiguredException: If price not configured
|
||||
"""
|
||||
if not stripe_service.is_configured:
|
||||
raise PaymentSystemNotConfiguredError()
|
||||
raise PaymentSystemNotConfiguredException()
|
||||
|
||||
tier = self.get_tier_by_code(db, tier_code)
|
||||
|
||||
@@ -142,7 +142,7 @@ class BillingService:
|
||||
)
|
||||
|
||||
if not price_id:
|
||||
raise StripePriceNotConfiguredError(tier_code)
|
||||
raise StripePriceNotConfiguredException(tier_code)
|
||||
|
||||
# Check if this is a new subscription (for trial)
|
||||
existing_sub = subscription_service.get_merchant_subscription(
|
||||
@@ -188,18 +188,18 @@ class BillingService:
|
||||
Dict with portal_url
|
||||
|
||||
Raises:
|
||||
PaymentSystemNotConfiguredError: If Stripe not configured
|
||||
NoActiveSubscriptionError: If no subscription with customer ID
|
||||
PaymentSystemNotConfiguredException: If Stripe not configured
|
||||
NoActiveSubscriptionException: If no subscription with customer ID
|
||||
"""
|
||||
if not stripe_service.is_configured:
|
||||
raise PaymentSystemNotConfiguredError()
|
||||
raise PaymentSystemNotConfiguredException()
|
||||
|
||||
subscription = subscription_service.get_merchant_subscription(
|
||||
db, merchant_id, platform_id
|
||||
)
|
||||
|
||||
if not subscription or not subscription.stripe_customer_id:
|
||||
raise NoActiveSubscriptionError()
|
||||
raise NoActiveSubscriptionException()
|
||||
|
||||
session = stripe_service.create_portal_session(
|
||||
customer_id=subscription.stripe_customer_id,
|
||||
@@ -266,14 +266,14 @@ class BillingService:
|
||||
Dict with message and effective_date
|
||||
|
||||
Raises:
|
||||
NoActiveSubscriptionError: If no subscription to cancel
|
||||
NoActiveSubscriptionException: If no subscription to cancel
|
||||
"""
|
||||
subscription = subscription_service.get_merchant_subscription(
|
||||
db, merchant_id, platform_id
|
||||
)
|
||||
|
||||
if not subscription or not subscription.stripe_subscription_id:
|
||||
raise NoActiveSubscriptionError()
|
||||
raise NoActiveSubscriptionException()
|
||||
|
||||
if stripe_service.is_configured:
|
||||
stripe_service.cancel_subscription(
|
||||
@@ -308,18 +308,18 @@ class BillingService:
|
||||
Dict with success message
|
||||
|
||||
Raises:
|
||||
NoActiveSubscriptionError: If no subscription
|
||||
SubscriptionNotCancelledError: If not cancelled
|
||||
NoActiveSubscriptionException: If no subscription
|
||||
SubscriptionNotCancelledException: If not cancelled
|
||||
"""
|
||||
subscription = subscription_service.get_merchant_subscription(
|
||||
db, merchant_id, platform_id
|
||||
)
|
||||
|
||||
if not subscription or not subscription.stripe_subscription_id:
|
||||
raise NoActiveSubscriptionError()
|
||||
raise NoActiveSubscriptionException()
|
||||
|
||||
if not subscription.cancelled_at:
|
||||
raise SubscriptionNotCancelledError()
|
||||
raise SubscriptionNotCancelledException()
|
||||
|
||||
if stripe_service.is_configured:
|
||||
stripe_service.reactivate_subscription(subscription.stripe_subscription_id)
|
||||
@@ -339,14 +339,14 @@ class BillingService:
|
||||
Dict with amount_due_cents, currency, next_payment_date, line_items
|
||||
|
||||
Raises:
|
||||
NoActiveSubscriptionError: If no subscription with customer ID
|
||||
NoActiveSubscriptionException: If no subscription with customer ID
|
||||
"""
|
||||
subscription = subscription_service.get_merchant_subscription(
|
||||
db, merchant_id, platform_id
|
||||
)
|
||||
|
||||
if not subscription or not subscription.stripe_customer_id:
|
||||
raise NoActiveSubscriptionError()
|
||||
raise NoActiveSubscriptionException()
|
||||
|
||||
if not stripe_service.is_configured:
|
||||
return {
|
||||
@@ -399,16 +399,16 @@ class BillingService:
|
||||
Dict with message, new_tier, effective_immediately
|
||||
|
||||
Raises:
|
||||
TierNotFoundError: If tier doesn't exist
|
||||
NoActiveSubscriptionError: If no subscription
|
||||
StripePriceNotConfiguredError: If price not configured
|
||||
TierNotFoundException: If tier doesn't exist
|
||||
NoActiveSubscriptionException: If no subscription
|
||||
StripePriceNotConfiguredException: If price not configured
|
||||
"""
|
||||
subscription = subscription_service.get_merchant_subscription(
|
||||
db, merchant_id, platform_id
|
||||
)
|
||||
|
||||
if not subscription or not subscription.stripe_subscription_id:
|
||||
raise NoActiveSubscriptionError()
|
||||
raise NoActiveSubscriptionException()
|
||||
|
||||
tier = self.get_tier_by_code(db, new_tier_code)
|
||||
|
||||
@@ -419,7 +419,7 @@ class BillingService:
|
||||
)
|
||||
|
||||
if not price_id:
|
||||
raise StripePriceNotConfiguredError(new_tier_code)
|
||||
raise StripePriceNotConfiguredException(new_tier_code)
|
||||
|
||||
# Update in Stripe
|
||||
if stripe_service.is_configured:
|
||||
@@ -472,11 +472,11 @@ class BillingService:
|
||||
Dict with checkout_url and session_id
|
||||
|
||||
Raises:
|
||||
PaymentSystemNotConfiguredError: If Stripe not configured
|
||||
BillingServiceError: If addon doesn't exist
|
||||
PaymentSystemNotConfiguredException: If Stripe not configured
|
||||
BillingException: If addon doesn't exist
|
||||
"""
|
||||
if not stripe_service.is_configured:
|
||||
raise PaymentSystemNotConfiguredError()
|
||||
raise PaymentSystemNotConfiguredException()
|
||||
|
||||
addon = (
|
||||
db.query(AddOnProduct)
|
||||
@@ -488,10 +488,10 @@ class BillingService:
|
||||
)
|
||||
|
||||
if not addon:
|
||||
raise BillingServiceError(f"Add-on '{addon_code}' not found")
|
||||
raise BillingException(f"Add-on '{addon_code}' not found")
|
||||
|
||||
if not addon.stripe_price_id:
|
||||
raise BillingServiceError(f"Stripe price not configured for add-on '{addon_code}'")
|
||||
raise BillingException(f"Stripe price not configured for add-on '{addon_code}'")
|
||||
|
||||
from app.modules.tenancy.models import Store
|
||||
store = db.query(Store).filter(Store.id == store_id).first()
|
||||
@@ -522,7 +522,7 @@ class BillingService:
|
||||
Dict with message and addon_code
|
||||
|
||||
Raises:
|
||||
BillingServiceError: If addon not found or not owned by store
|
||||
BillingException: If addon not found or not owned by store
|
||||
"""
|
||||
store_addon = (
|
||||
db.query(StoreAddOn)
|
||||
@@ -534,7 +534,7 @@ class BillingService:
|
||||
)
|
||||
|
||||
if not store_addon:
|
||||
raise BillingServiceError("Add-on not found")
|
||||
raise BillingException("Add-on not found")
|
||||
|
||||
addon_code = store_addon.addon_product.code
|
||||
|
||||
|
||||
Reference in New Issue
Block a user