refactor: enforce strict architecture rules and add Pydantic response models
- Update architecture rules to be stricter (API-003 now blocks ALL exception raising in endpoints, not just HTTPException) - Update get_current_vendor_api dependency to guarantee token_vendor_id presence - Remove redundant _get_vendor_from_token helpers from all vendor API files - Move vendor access validation to service layer methods - Add Pydantic response models for media, notification, and payment endpoints - Add get_active_vendor_by_code service method for public vendor lookup - Add get_import_job_for_vendor service method with vendor validation - Update validation script to detect exception raising patterns in endpoints 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1,166 @@
|
||||
# Payment models
|
||||
# models/schema/payment.py
|
||||
"""
|
||||
Payment Pydantic schemas for API validation and responses.
|
||||
|
||||
This module provides schemas for:
|
||||
- Payment configuration
|
||||
- Stripe integration
|
||||
- Payment methods
|
||||
- Transactions and balance
|
||||
- Refunds
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PAYMENT CONFIGURATION SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class PaymentConfigResponse(BaseModel):
|
||||
"""Response for payment configuration."""
|
||||
|
||||
payment_gateway: str | None = None
|
||||
accepted_methods: list[str] = []
|
||||
currency: str = "EUR"
|
||||
stripe_connected: bool = False
|
||||
stripe_account_id: str | None = None
|
||||
paypal_connected: bool = False
|
||||
message: str | None = None
|
||||
|
||||
|
||||
class PaymentConfigUpdate(BaseModel):
|
||||
"""Request model for updating payment configuration."""
|
||||
|
||||
payment_gateway: str | None = Field(None, max_length=50)
|
||||
accepted_methods: list[str] | None = None
|
||||
currency: str | None = Field(None, max_length=3)
|
||||
|
||||
|
||||
class PaymentConfigUpdateResponse(BaseModel):
|
||||
"""Response for payment configuration update."""
|
||||
|
||||
success: bool = False
|
||||
message: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# STRIPE INTEGRATION SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class StripeConnectRequest(BaseModel):
|
||||
"""Request model for connecting Stripe account."""
|
||||
|
||||
authorization_code: str | None = None
|
||||
state: str | None = None
|
||||
|
||||
|
||||
class StripeConnectResponse(BaseModel):
|
||||
"""Response for Stripe connection."""
|
||||
|
||||
connected: bool = False
|
||||
stripe_account_id: str | None = None
|
||||
message: str | None = None
|
||||
|
||||
|
||||
class StripeDisconnectResponse(BaseModel):
|
||||
"""Response for Stripe disconnection."""
|
||||
|
||||
disconnected: bool = False
|
||||
message: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# PAYMENT METHODS SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class PaymentMethodInfo(BaseModel):
|
||||
"""Information about a payment method."""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
type: str # credit_card, paypal, bank_transfer, etc.
|
||||
enabled: bool = True
|
||||
icon: str | None = None
|
||||
|
||||
|
||||
class PaymentMethodsResponse(BaseModel):
|
||||
"""Response for payment methods listing."""
|
||||
|
||||
methods: list[PaymentMethodInfo] = []
|
||||
message: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# TRANSACTION SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TransactionInfo(BaseModel):
|
||||
"""Information about a payment transaction."""
|
||||
|
||||
id: int
|
||||
order_id: int | None = None
|
||||
amount: float
|
||||
currency: str = "EUR"
|
||||
status: str # pending, completed, failed, refunded
|
||||
payment_method: str | None = None
|
||||
customer_email: str | None = None
|
||||
created_at: datetime
|
||||
completed_at: datetime | None = None
|
||||
metadata: dict[str, Any] | None = None
|
||||
|
||||
|
||||
class TransactionsResponse(BaseModel):
|
||||
"""Response for payment transactions listing."""
|
||||
|
||||
transactions: list[TransactionInfo] = []
|
||||
total: int = 0
|
||||
skip: int = 0
|
||||
limit: int = 50
|
||||
message: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# BALANCE SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class PaymentBalanceResponse(BaseModel):
|
||||
"""Response for payment balance information."""
|
||||
|
||||
available_balance: float = 0.0
|
||||
pending_balance: float = 0.0
|
||||
currency: str = "EUR"
|
||||
next_payout_date: datetime | None = None
|
||||
last_payout_date: datetime | None = None
|
||||
last_payout_amount: float | None = None
|
||||
message: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# REFUND SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class RefundRequest(BaseModel):
|
||||
"""Request model for processing a refund."""
|
||||
|
||||
amount: float | None = Field(None, gt=0, description="Partial refund amount, or None for full refund")
|
||||
reason: str | None = Field(None, max_length=500)
|
||||
|
||||
|
||||
class RefundResponse(BaseModel):
|
||||
"""Response for refund operation."""
|
||||
|
||||
refund_id: int | None = None
|
||||
payment_id: int | None = None
|
||||
amount: float | None = None
|
||||
status: str | None = None # pending, completed, failed
|
||||
message: str | None = None
|
||||
|
||||
Reference in New Issue
Block a user