Updated auth api for customer profile
This commit is contained in:
@@ -1,39 +1,77 @@
|
||||
## File: your_app/schemas.py
|
||||
|
||||
from pydantic import BaseModel
|
||||
from typing import List, Optional
|
||||
from datetime import datetime
|
||||
from decimal import Decimal # Use Decimal for currency
|
||||
|
||||
# --- NEW SCHEMAS FOR CIM WORKFLOW ---
|
||||
|
||||
class CardCreate(BaseModel):
|
||||
# This schema receives sensitive card info just once.
|
||||
card_number: str
|
||||
expiration_date: str # Format: "YYYY-MM"
|
||||
cvv: str
|
||||
|
||||
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
|
||||
expiration_month: int
|
||||
expiration_year: int
|
||||
|
||||
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
|
||||
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 TransactionBase(BaseModel):
|
||||
preauthorize_amount: Optional[float] = None # Amount preauthorized (for auth transactions)
|
||||
charge_amount: Optional[float] = None # Final charge amount (for charge/capture transactions)
|
||||
transaction_type: int # 0 = charge, 1 = auth, 3 = capture - Required for database
|
||||
service_id: Optional[int] = None # Reference to Service_Service.id
|
||||
delivery_id: Optional[int] = None # Reference to Delivery_Delivery.id
|
||||
card_id: Optional[int] = None # Reference to credit card used for payment
|
||||
payment_gateway: int = 1 # 1 = Authorize.Net, 0 = Other
|
||||
rejection_reason: Optional[str] = None # Detailed error message when payment is declined
|
||||
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: float # Final charge amount
|
||||
charge_amount: Decimal
|
||||
card_number: str
|
||||
expiration_date: str # MM/YY
|
||||
cvv: str
|
||||
|
||||
class TransactionAuthorize(TransactionBase):
|
||||
preauthorize_amount: float # Amount to preauthorize
|
||||
preauthorize_amount: Decimal
|
||||
card_number: str
|
||||
expiration_date: str
|
||||
cvv: str
|
||||
|
||||
class TransactionCapture(BaseModel):
|
||||
charge_amount: float # Amount to capture
|
||||
charge_amount: Decimal
|
||||
auth_net_transaction_id: str
|
||||
|
||||
class Transaction(TransactionBase):
|
||||
id: int
|
||||
transaction_type: int # 0 = charge, 1 = auth, 3 = capture
|
||||
status: int # 0 = approved, 1 = declined
|
||||
transaction_type: int
|
||||
status: int
|
||||
auth_net_transaction_id: Optional[str] = None
|
||||
customer_id: int
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
@@ -59,6 +97,27 @@ class CustomerBase(BaseModel):
|
||||
|
||||
class Customer(CustomerBase):
|
||||
id: int
|
||||
# --- ADD THIS FIELD ---
|
||||
auth_net_profile_id: Optional[str] = None
|
||||
|
||||
class Config:
|
||||
orm_mode = 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
|
||||
|
||||
# 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
|
||||
Reference in New Issue
Block a user