68 lines
2.7 KiB
Python
68 lines
2.7 KiB
Python
## File: your_app/models.py
|
|
|
|
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean, ForeignKey, Numeric
|
|
from .database import Base
|
|
import datetime
|
|
|
|
class Customer(Base):
|
|
__tablename__ = "customers"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
|
|
# --- ADD THIS COLUMN ---
|
|
# This stores the master profile ID from Authorize.Net's CIM.
|
|
auth_net_profile_id = Column(String, unique=True, index=True, nullable=True)
|
|
|
|
# --- YOUR EXISTING COLUMNS ---
|
|
account_number = Column(String(25))
|
|
customer_last_name = Column(String(250))
|
|
customer_first_name = Column(String(250))
|
|
customer_town = Column(String(140))
|
|
customer_state = Column(Integer)
|
|
customer_zip = Column(String(25))
|
|
customer_first_call = Column(DateTime)
|
|
customer_email = Column(String(500))
|
|
customer_automatic = Column(Integer)
|
|
customer_phone_number = Column(String(25))
|
|
customer_home_type = Column(Integer)
|
|
customer_apt = Column(String(140))
|
|
customer_address = Column(String(1000))
|
|
company_id = Column(Integer)
|
|
customer_latitude = Column(String(250))
|
|
customer_longitude = Column(String(250))
|
|
correct_address = Column(Boolean)
|
|
|
|
# --- ADD THIS ENTIRE NEW MODEL ---
|
|
class Card(Base):
|
|
__tablename__ = "cards"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
customer_id = Column(Integer, ForeignKey("customers.id"), nullable=False, index=True)
|
|
|
|
# This stores the payment profile ID for this specific card from Authorize.Net's CIM.
|
|
auth_net_payment_profile_id = Column(String, unique=True, index=True, nullable=False)
|
|
|
|
# Columns to store non-sensitive card info for display purposes
|
|
last_four = Column(String(4), nullable=False)
|
|
card_brand = Column(String(50), nullable=True)
|
|
expiration_month = Column(Integer, nullable=False)
|
|
expiration_year = Column(Integer, nullable=False)
|
|
|
|
class Transaction(Base):
|
|
__tablename__ = "transactions"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
# Recommended change: Use Numeric for precision
|
|
preauthorize_amount = Column(Numeric(10, 2), nullable=True)
|
|
charge_amount = Column(Numeric(10, 2), nullable=True)
|
|
|
|
transaction_type = Column(Integer)
|
|
status = Column(Integer)
|
|
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
|
customer_id = Column(Integer, ForeignKey("customers.id"))
|
|
service_id = Column(Integer, nullable=True)
|
|
delivery_id = Column(Integer, nullable=True)
|
|
card_id = Column(Integer, ForeignKey("cards.id"), nullable=True)
|
|
payment_gateway = Column(Integer, default=1)
|
|
rejection_reason = Column(String, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.datetime.utcnow) |