Adding authnet not tested

This commit is contained in:
2025-09-15 15:30:30 -04:00
parent 5a6bcc0700
commit 47e3fb443b
6 changed files with 285 additions and 157 deletions

View File

@@ -1,43 +1,45 @@
## File: your_app/schemas.py
## File: app/schemas.py (or your equivalent path)
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict # --- MODIFICATION: Import ConfigDict
from typing import List, Optional
from datetime import datetime
from decimal import Decimal # Use Decimal for currency
from decimal import Decimal
# --- NEW SCHEMAS FOR CIM WORKFLOW ---
# --- NEW SCHEMAS FOR CIM WORKFLOW (Now with correct Pydantic V2 config) ---
class CardCreate(BaseModel):
# This schema receives sensitive card info just once.
card_number: str
expiration_date: str # Format: "YYYY-MM"
cvv: str
main_card: bool = False
class Card(BaseModel):
# This schema is for displaying saved card info. It is NOT sensitive.
id: int
customer_id: int
last_four: str
card_brand: Optional[str] = None
user_id: int
last_four_digits: str
type_of_card: Optional[str] = None
expiration_month: int
expiration_year: int
class Config:
orm_mode = True
# --- 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):
# This is the NEW way to create a charge, using an internal card_id.
card_id: int
charge_amount: Decimal # Use Decimal
# Fields for Level 2 data
charge_amount: Decimal
tax_amount: Optional[Decimal] = Decimal("0.0")
# Your other business-related IDs
service_id: Optional[int] = None
delivery_id: Optional[int] = None
# --- YOUR EXISTING SCHEMAS (UPDATED) ---
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
@@ -52,7 +54,7 @@ class TransactionBase(BaseModel):
class TransactionCreate(TransactionBase):
charge_amount: Decimal
card_number: str
expiration_date: str # MM/YY
expiration_date: str
cvv: str
class TransactionAuthorize(TransactionBase):
@@ -73,8 +75,8 @@ class Transaction(TransactionBase):
customer_id: int
created_at: datetime
class Config:
orm_mode = True
# --- MODIFICATION: This is the new syntax for Pydantic V2 ---
model_config = ConfigDict(from_attributes=True)
class CustomerBase(BaseModel):
account_number: Optional[str] = None
@@ -97,27 +99,16 @@ class CustomerBase(BaseModel):
class Customer(CustomerBase):
id: int
# --- ADD THIS FIELD ---
auth_net_profile_id: Optional[str] = None
class Config:
orm_mode = True
# --- MODIFICATION: This is the new syntax for Pydantic V2 ---
model_config = ConfigDict(from_attributes=True)
# --- ADD THIS NEW SCHEMA ---
class TransactionAuthorizeByCardID(BaseModel):
# This is for creating an AUTHORIZATION using an internal card_id.
card_id: int
preauthorize_amount: Decimal # Use Decimal
class CustomerCardResponse(Card):
# We are inheriting all fields from `Card`
# Fields for Level 2 data (important for rates!)
tax_amount: Optional[Decimal] = Decimal("0.0")
# Your other business-related IDs
service_id: Optional[int] = None
delivery_id: Optional[int] = None
# --- Your TransactionCapture schema is perfect and needs NO changes ---
class TransactionCapture(BaseModel):
charge_amount: Decimal
auth_net_transaction_id: str
# 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