46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
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"}
|