114 lines
3.5 KiB
Python
114 lines
3.5 KiB
Python
## File: app/schemas.py (or your equivalent path)
|
|
|
|
from pydantic import BaseModel, ConfigDict # --- MODIFICATION: Import ConfigDict
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
from decimal import Decimal
|
|
|
|
# --- NEW SCHEMAS FOR CIM WORKFLOW (Now with correct Pydantic V2 config) ---
|
|
|
|
class CardCreate(BaseModel):
|
|
card_number: str
|
|
expiration_date: str # Format: "YYYY-MM"
|
|
cvv: str
|
|
main_card: bool = False
|
|
|
|
class Card(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
last_four_digits: str
|
|
type_of_card: Optional[str] = None
|
|
expiration_month: int
|
|
expiration_year: int
|
|
|
|
# --- MODIFICATION: This is the new syntax for Pydantic V2 ---
|
|
model_config = ConfigDict(from_attributes=True)
|
|
# The line above replaces the old `class Config: orm_mode = True`
|
|
|
|
class TransactionCreateByCardID(BaseModel):
|
|
card_id: int
|
|
charge_amount: Decimal
|
|
tax_amount: Optional[Decimal] = Decimal("0.0")
|
|
service_id: Optional[int] = None
|
|
delivery_id: Optional[int] = None
|
|
|
|
class TransactionAuthorizeByCardID(BaseModel):
|
|
card_id: int
|
|
preauthorize_amount: Decimal
|
|
tax_amount: Optional[Decimal] = Decimal("0.0")
|
|
service_id: Optional[int] = None
|
|
delivery_id: Optional[int] = None
|
|
|
|
# --- YOUR EXISTING SCHEMAS (UPDATED for Pydantic V2) ---
|
|
|
|
class TransactionBase(BaseModel):
|
|
preauthorize_amount: Optional[Decimal] = None
|
|
charge_amount: Optional[Decimal] = None
|
|
transaction_type: int
|
|
service_id: Optional[int] = None
|
|
delivery_id: Optional[int] = None
|
|
card_id: Optional[int] = None
|
|
payment_gateway: int = 1
|
|
rejection_reason: Optional[str] = None
|
|
|
|
class TransactionCreate(TransactionBase):
|
|
charge_amount: Decimal
|
|
card_number: str
|
|
expiration_date: str
|
|
cvv: str
|
|
|
|
class TransactionAuthorize(TransactionBase):
|
|
preauthorize_amount: Decimal
|
|
card_number: str
|
|
expiration_date: str
|
|
cvv: str
|
|
|
|
class TransactionCapture(BaseModel):
|
|
charge_amount: Decimal
|
|
auth_net_transaction_id: str
|
|
|
|
class Transaction(TransactionBase):
|
|
id: int
|
|
transaction_type: int
|
|
status: int
|
|
auth_net_transaction_id: Optional[str] = None
|
|
customer_id: int
|
|
created_at: datetime
|
|
|
|
# --- MODIFICATION: This is the new syntax for Pydantic V2 ---
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
class CustomerBase(BaseModel):
|
|
account_number: Optional[str] = None
|
|
customer_last_name: Optional[str] = None
|
|
customer_first_name: Optional[str] = None
|
|
customer_town: Optional[str] = None
|
|
customer_state: Optional[int] = None
|
|
customer_zip: Optional[str] = None
|
|
customer_first_call: Optional[datetime] = None
|
|
customer_email: Optional[str] = None
|
|
customer_automatic: Optional[int] = None
|
|
customer_phone_number: Optional[str] = None
|
|
customer_home_type: Optional[int] = None
|
|
customer_apt: Optional[str] = None
|
|
customer_address: Optional[str] = None
|
|
company_id: Optional[int] = None
|
|
customer_latitude: Optional[str] = None
|
|
customer_longitude: Optional[str] = None
|
|
correct_address: Optional[bool] = None
|
|
|
|
class Customer(CustomerBase):
|
|
id: int
|
|
auth_net_profile_id: Optional[str] = None
|
|
|
|
# --- MODIFICATION: This is the new syntax for Pydantic V2 ---
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class CustomerCardResponse(Card):
|
|
# We are inheriting all fields from `Card`
|
|
|
|
# Now, add the extra customer fields the frontend needs.
|
|
# We define it as a string because we will be returning the
|
|
# two-letter abbreviation, not the database ID.
|
|
customer_state: str |