Files
orion/app/modules/payments/exceptions.py
Samir Boulahtit 4e28d91a78 refactor: migrate templates and static files to self-contained modules
Templates Migration:
- Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.)
- Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.)
- Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms)
- Migrate public templates to modules (billing, marketplace, cms)
- Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/)
- Migrate letzshop partials to marketplace module

Static Files Migration:
- Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file)
- Migrate vendor JS to modules: tenancy (4 files), core (2 files)
- Migrate shared JS: vendor-selector.js to core, media-picker.js to cms
- Migrate storefront JS: storefront-layout.js to core
- Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/)
- Update all template references to use module_static paths

Naming Consistency:
- Rename static/platform/ to static/public/
- Rename app/templates/platform/ to app/templates/public/
- Update all extends and static references

Documentation:
- Update module-system.md with shared templates documentation
- Update frontend-structure.md with new module JS organization

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-01 14:34:16 +01:00

145 lines
4.3 KiB
Python

# app/modules/payments/exceptions.py
"""
Payment-related exceptions.
Includes:
- Webhook verification exceptions
- Payment processing exceptions
"""
from app.exceptions.base import (
BusinessLogicException,
ExternalServiceException,
ResourceNotFoundException,
ValidationException,
)
# =============================================================================
# Webhook Exceptions
# =============================================================================
class InvalidWebhookSignatureException(BusinessLogicException):
"""Raised when Stripe webhook signature verification fails."""
def __init__(self, message: str = "Invalid webhook signature"):
super().__init__(
message=message,
error_code="INVALID_WEBHOOK_SIGNATURE",
)
class WebhookMissingSignatureException(BusinessLogicException):
"""Raised when Stripe webhook is missing the signature header."""
def __init__(self):
super().__init__(
message="Missing Stripe-Signature header",
error_code="WEBHOOK_MISSING_SIGNATURE",
)
class WebhookVerificationException(BusinessLogicException):
"""Raised when webhook signature verification fails."""
def __init__(self, message: str = "Invalid webhook signature"):
super().__init__(
message=message,
error_code="WEBHOOK_VERIFICATION_FAILED",
)
# =============================================================================
# Payment Exceptions
# =============================================================================
class PaymentException(BusinessLogicException):
"""Base exception for payment-related errors."""
def __init__(
self,
message: str,
error_code: str = "PAYMENT_ERROR",
details: dict | None = None,
):
super().__init__(message=message, error_code=error_code, details=details)
class PaymentNotFoundException(ResourceNotFoundException):
"""Raised when a payment is not found."""
def __init__(self, payment_id: str):
super().__init__(
resource_type="Payment",
identifier=payment_id,
message=f"Payment with ID '{payment_id}' not found",
)
self.payment_id = payment_id
class PaymentFailedException(PaymentException):
"""Raised when payment processing fails."""
def __init__(self, message: str, stripe_error: str | None = None):
super().__init__(
message=message,
error_code="PAYMENT_FAILED",
details={"stripe_error": stripe_error} if stripe_error else None,
)
self.stripe_error = stripe_error
class PaymentRefundException(PaymentException):
"""Raised when a refund fails."""
def __init__(self, message: str, payment_id: str | None = None):
super().__init__(
message=message,
error_code="REFUND_FAILED",
details={"payment_id": payment_id} if payment_id else None,
)
self.payment_id = payment_id
class InsufficientFundsException(PaymentException):
"""Raised when there are insufficient funds for payment."""
def __init__(self, required_amount: float, available_amount: float | None = None):
message = f"Insufficient funds. Required: {required_amount}"
if available_amount is not None:
message += f", Available: {available_amount}"
super().__init__(
message=message,
error_code="INSUFFICIENT_FUNDS",
details={
"required_amount": required_amount,
"available_amount": available_amount,
},
)
self.required_amount = required_amount
self.available_amount = available_amount
class PaymentGatewayException(ExternalServiceException):
"""Raised when payment gateway fails."""
def __init__(self, gateway: str, message: str):
super().__init__(
service_name=gateway,
message=f"Payment gateway error: {message}",
)
self.gateway = gateway
class InvalidPaymentMethodException(ValidationException):
"""Raised when an invalid payment method is provided."""
def __init__(self, method: str):
super().__init__(
message=f"Invalid payment method: {method}",
details={"method": method},
)
self.method = method