working auto
This commit is contained in:
@@ -90,6 +90,13 @@ def get_transaction_by_auth_id(db: Session, auth_net_transaction_id: str):
|
|||||||
models.Transaction.auth_net_transaction_id == auth_net_transaction_id
|
models.Transaction.auth_net_transaction_id == auth_net_transaction_id
|
||||||
).first()
|
).first()
|
||||||
|
|
||||||
|
def get_transaction_by_auto_id(db: Session, auto_id: int):
|
||||||
|
return db.query(models.Transaction).filter(
|
||||||
|
models.Transaction.auto_id == auto_id,
|
||||||
|
models.Transaction.transaction_type == 1,
|
||||||
|
models.Transaction.status == 0
|
||||||
|
).first()
|
||||||
|
|
||||||
def update_transaction_for_capture(db: Session, auth_net_transaction_id: str, charge_amount: Decimal, status: int, rejection_reason: str = None):
|
def update_transaction_for_capture(db: Session, auth_net_transaction_id: str, charge_amount: Decimal, status: int, rejection_reason: str = None):
|
||||||
transaction = db.query(models.Transaction).filter(models.Transaction.auth_net_transaction_id == auth_net_transaction_id).first()
|
transaction = db.query(models.Transaction).filter(models.Transaction.auth_net_transaction_id == auth_net_transaction_id).first()
|
||||||
if not transaction:
|
if not transaction:
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from .database import engine
|
|||||||
from . import models
|
from . import models
|
||||||
from .routers import payment
|
from .routers import payment
|
||||||
from .routers.transaction import transaction_router
|
from .routers.transaction import transaction_router
|
||||||
|
from .routers.auto import auto_router
|
||||||
from .routers.user_check import user_check_router
|
from .routers.user_check import user_check_router
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from config import load_config
|
from config import load_config
|
||||||
@@ -29,6 +30,7 @@ app.add_middleware(
|
|||||||
|
|
||||||
app.include_router(payment.router, prefix="/api", tags=["payment"])
|
app.include_router(payment.router, prefix="/api", tags=["payment"])
|
||||||
app.include_router(transaction_router, prefix="/api", tags=["transactions"])
|
app.include_router(transaction_router, prefix="/api", tags=["transactions"])
|
||||||
|
app.include_router(auto_router, prefix="/api", tags=["auto"])
|
||||||
app.include_router(user_check_router, prefix="/user", tags=["usercheck"])
|
app.include_router(user_check_router, prefix="/user", tags=["usercheck"])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
## File: your_app/models.py
|
## File: your_app/models.py
|
||||||
|
|
||||||
from sqlalchemy import Column, Integer, String, Float, DateTime, Boolean, ForeignKey, Numeric
|
from sqlalchemy import Column, Integer, String, DateTime, Boolean, ForeignKey, Numeric
|
||||||
from .database import Base
|
from .database import Base
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
@@ -68,7 +68,58 @@ class Transaction(Base):
|
|||||||
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
auth_net_transaction_id = Column(String, unique=True, index=True, nullable=True)
|
||||||
service_id = Column(Integer, nullable=True)
|
service_id = Column(Integer, nullable=True)
|
||||||
delivery_id = Column(Integer, nullable=True)
|
delivery_id = Column(Integer, nullable=True)
|
||||||
|
auto_id = Column(Integer, nullable=True)
|
||||||
card_id = Column(Integer, nullable=True)
|
card_id = Column(Integer, nullable=True)
|
||||||
payment_gateway = Column(Integer, default=1)
|
payment_gateway = Column(Integer, default=1)
|
||||||
rejection_reason = Column(String, nullable=True)
|
rejection_reason = Column(String, nullable=True)
|
||||||
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
created_at = Column(DateTime, default=datetime.datetime.utcnow)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class Auto_Delivery(Base):
|
||||||
|
__tablename__ = 'auto_delivery'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
customer_id = Column(Integer, nullable=False)
|
||||||
|
account_number = Column(String(25))
|
||||||
|
customer_town = Column(String(140))
|
||||||
|
customer_state = Column(Integer)
|
||||||
|
customer_address = Column(String(1000))
|
||||||
|
customer_zip = Column(String(25))
|
||||||
|
customer_full_name = Column(String(250))
|
||||||
|
last_fill = Column(DateTime, nullable=True)
|
||||||
|
days_since_last_fill = Column(Integer)
|
||||||
|
last_updated = Column(DateTime, nullable=True)
|
||||||
|
estimated_gallons_left = Column(Numeric(10, 2), nullable=True)
|
||||||
|
estimated_gallons_left_prev_day = Column(Numeric(10, 2), nullable=True)
|
||||||
|
tank_height = Column(String(25))
|
||||||
|
tank_size = Column(String(25))
|
||||||
|
house_factor = Column(Numeric(5, 2), nullable=True)
|
||||||
|
auto_status = Column(Integer, nullable=True)
|
||||||
|
open_ticket_id = Column(Integer, nullable=True)
|
||||||
|
|
||||||
|
class Tickets_Auto_Delivery(Base):
|
||||||
|
__tablename__ = 'auto_tickets'
|
||||||
|
|
||||||
|
id = Column(Integer, primary_key=True, index=True)
|
||||||
|
customer_id = Column(Integer, nullable=False)
|
||||||
|
account_number = Column(String(25))
|
||||||
|
|
||||||
|
customer_town = Column(String(140))
|
||||||
|
customer_state = Column(Integer)
|
||||||
|
customer_address = Column(String(1000))
|
||||||
|
customer_zip = Column(String(25))
|
||||||
|
customer_full_name = Column(String(250))
|
||||||
|
|
||||||
|
oil_prices_id = Column(Integer, nullable=True)
|
||||||
|
fill_date = Column(DateTime, nullable=True)
|
||||||
|
gallons_delivered = Column(Numeric(10, 2), nullable=True)
|
||||||
|
price_per_gallon = Column(Numeric(10, 2), nullable=True)
|
||||||
|
|
||||||
|
total_amount_customer = Column(Numeric(10, 2), nullable=True)
|
||||||
|
customer_town = Column(String(140))
|
||||||
|
|
||||||
|
payment_type = Column(Integer, nullable=True)
|
||||||
|
payment_card_id = Column(Integer, nullable=True)
|
||||||
|
payment_status = Column(Integer, nullable=True)
|
||||||
45
app/routers/auto.py
Normal file
45
app/routers/auto.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from app import crud, database
|
||||||
|
|
||||||
|
# Create a router for auto-specific transaction endpoints
|
||||||
|
auto_router = APIRouter(
|
||||||
|
prefix="/auto/transaction",
|
||||||
|
tags=["auto_transaction"],
|
||||||
|
responses={404: {"description": "Not found"}},
|
||||||
|
)
|
||||||
|
|
||||||
|
@auto_router.get("/delivery/{auto_id}", summary="Get pre-authorization transaction for auto delivery")
|
||||||
|
def get_auto_delivery_transaction(auto_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
"""
|
||||||
|
Get the pre-authorization transaction for an auto ticket delivery.
|
||||||
|
Used by the capture page for auto deliveries.
|
||||||
|
"""
|
||||||
|
transaction = crud.get_transaction_by_auto_id(db, auto_id=auto_id)
|
||||||
|
if not transaction:
|
||||||
|
raise HTTPException(status_code=404, detail="No pre-authorization transaction found for this auto delivery")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"id": transaction.id,
|
||||||
|
"transaction_type": transaction.transaction_type,
|
||||||
|
"status": transaction.status,
|
||||||
|
"auth_net_transaction_id": transaction.auth_net_transaction_id,
|
||||||
|
"preauthorize_amount": transaction.preauthorize_amount
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@auto_router.put("/delivery/{current_auto_id}/update/{new_auto_id}", summary="Update auto_id for transaction")
|
||||||
|
def update_transaction_auto_id(current_auto_id: int, new_auto_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
"""
|
||||||
|
Update the auto_id of a transaction based on the current auto_id.
|
||||||
|
Used to change transaction from auto_delivery.id to auto_ticket.id
|
||||||
|
"""
|
||||||
|
transaction = crud.get_transaction_by_auto_id(db, auto_id=current_auto_id)
|
||||||
|
if not transaction:
|
||||||
|
raise HTTPException(status_code=404, detail="No transaction found for this auto delivery")
|
||||||
|
|
||||||
|
transaction.delivery_id = new_auto_id
|
||||||
|
transaction.auto_id = new_auto_id
|
||||||
|
db.commit()
|
||||||
|
return {"message": "Transaction auto_id updated"}
|
||||||
@@ -238,18 +238,19 @@ def authorize_saved_card(customer_id: int, transaction_req: schemas.TransactionA
|
|||||||
)
|
)
|
||||||
|
|
||||||
status, auth_net_transaction_id, rejection_reason = _parse_authnet_response(auth_net_response)
|
status, auth_net_transaction_id, rejection_reason = _parse_authnet_response(auth_net_response)
|
||||||
|
print(transaction_req)
|
||||||
# Create the transaction record in your database with the correct type
|
# Create the transaction record in your database with the correct type
|
||||||
transaction_data = schemas.TransactionBase(
|
transaction_data = schemas.TransactionBase(
|
||||||
preauthorize_amount=transaction_req.preauthorize_amount,
|
preauthorize_amount=transaction_req.preauthorize_amount,
|
||||||
transaction_type=TransactionType.AUTHORIZE, # This is key
|
transaction_type=TransactionType.AUTHORIZE, # This is key
|
||||||
service_id=transaction_req.service_id,
|
service_id=transaction_req.service_id,
|
||||||
delivery_id=transaction_req.delivery_id,
|
delivery_id=transaction_req.delivery_id,
|
||||||
|
auto_id=transaction_req.auto_id,
|
||||||
card_id=transaction_req.card_id,
|
card_id=transaction_req.card_id,
|
||||||
rejection_reason=rejection_reason
|
rejection_reason=rejection_reason
|
||||||
)
|
)
|
||||||
|
|
||||||
return crud.create_transaction(
|
db_transaction = crud.create_transaction(
|
||||||
db=db,
|
db=db,
|
||||||
transaction=transaction_data,
|
transaction=transaction_data,
|
||||||
customer_id=customer_id,
|
customer_id=customer_id,
|
||||||
@@ -257,4 +258,6 @@ def authorize_saved_card(customer_id: int, transaction_req: schemas.TransactionA
|
|||||||
auth_net_transaction_id=auth_net_transaction_id
|
auth_net_transaction_id=auth_net_transaction_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
return db_transaction
|
||||||
|
|
||||||
# --- CAPTURE ENDPOINT MOVED TO TRANSACTION ROUTER ---
|
# --- CAPTURE ENDPOINT MOVED TO TRANSACTION ROUTER ---
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import sys
|
|||||||
import os
|
import os
|
||||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
|
||||||
|
|
||||||
from app import crud, database, schemas
|
from app import crud, database, schemas, models
|
||||||
from app.services import payment_service
|
from app.services import payment_service
|
||||||
|
|
||||||
# Create a router for transaction endpoints
|
# Create a router for transaction endpoints
|
||||||
@@ -42,6 +42,37 @@ def get_delivery_transaction(delivery_id: int, db: Session = Depends(database.ge
|
|||||||
"preauthorize_amount": transaction.preauthorize_amount
|
"preauthorize_amount": transaction.preauthorize_amount
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@transaction_router.put("/transaction/delivery/{delivery_id}/update/{new_delivery_id}", summary="Update delivery_id for transaction")
|
||||||
|
def update_transaction_delivery(delivery_id: int, new_delivery_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
"""
|
||||||
|
Update the delivery_id of a transaction based on the current delivery_id.
|
||||||
|
Used to change transaction from auto_delivery.id to auto_ticket.id
|
||||||
|
"""
|
||||||
|
transaction = crud.get_transaction_by_delivery_id(db, delivery_id=delivery_id)
|
||||||
|
if not transaction:
|
||||||
|
raise HTTPException(status_code=404, detail="No transaction found for this delivery")
|
||||||
|
|
||||||
|
transaction.delivery_id = new_delivery_id
|
||||||
|
db.commit()
|
||||||
|
return {"message": "Transaction delivery_id updated"}
|
||||||
|
|
||||||
|
|
||||||
|
@transaction_router.put("/transaction/{transaction_id}/update_auto_id/{new_auto_id}", summary="Update auto_id for transaction")
|
||||||
|
def update_transaction_auto_id(transaction_id: int, new_auto_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
"""
|
||||||
|
Update the auto_id of a transaction by its ID.
|
||||||
|
Used to set auto_id to auto_ticket.id after ticket creation.
|
||||||
|
"""
|
||||||
|
transaction = db.query(models.Transaction).filter(models.Transaction.id == transaction_id).first()
|
||||||
|
if not transaction:
|
||||||
|
raise HTTPException(status_code=404, detail="Transaction not found")
|
||||||
|
|
||||||
|
transaction.auto_id = new_auto_id
|
||||||
|
db.commit()
|
||||||
|
return {"message": "Transaction auto_id updated"}
|
||||||
|
|
||||||
|
|
||||||
@transaction_router.post("/capture/", response_model=schemas.Transaction, summary="Capture a previously authorized amount")
|
@transaction_router.post("/capture/", response_model=schemas.Transaction, summary="Capture a previously authorized amount")
|
||||||
def capture_authorized_amount(transaction: schemas.TransactionCapture, db: Session = Depends(database.get_db)):
|
def capture_authorized_amount(transaction: schemas.TransactionCapture, db: Session = Depends(database.get_db)):
|
||||||
# This endpoint captures a previously authorized transaction
|
# This endpoint captures a previously authorized transaction
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class TransactionAuthorizeByCardID(BaseModel):
|
|||||||
tax_amount: Optional[Decimal] = Decimal("0.0")
|
tax_amount: Optional[Decimal] = Decimal("0.0")
|
||||||
service_id: Optional[int] = None
|
service_id: Optional[int] = None
|
||||||
delivery_id: Optional[int] = None
|
delivery_id: Optional[int] = None
|
||||||
|
auto_id: Optional[int] = None
|
||||||
|
|
||||||
# --- YOUR EXISTING SCHEMAS (UPDATED for Pydantic V2) ---
|
# --- YOUR EXISTING SCHEMAS (UPDATED for Pydantic V2) ---
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ class TransactionBase(BaseModel):
|
|||||||
transaction_type: int
|
transaction_type: int
|
||||||
service_id: Optional[int] = None
|
service_id: Optional[int] = None
|
||||||
delivery_id: Optional[int] = None
|
delivery_id: Optional[int] = None
|
||||||
|
auto_id: Optional[int] = None
|
||||||
card_id: Optional[int] = None
|
card_id: Optional[int] = None
|
||||||
payment_gateway: int = 1
|
payment_gateway: int = 1
|
||||||
rejection_reason: Optional[str] = None
|
rejection_reason: Optional[str] = None
|
||||||
@@ -111,4 +113,4 @@ class CustomerCardResponse(Card):
|
|||||||
# Now, add the extra customer fields the frontend needs.
|
# Now, add the extra customer fields the frontend needs.
|
||||||
# We define it as a string because we will be returning the
|
# We define it as a string because we will be returning the
|
||||||
# two-letter abbreviation, not the database ID.
|
# two-letter abbreviation, not the database ID.
|
||||||
customer_state: str
|
customer_state: str
|
||||||
|
|||||||
Reference in New Issue
Block a user