54 lines
2.3 KiB
Python
54 lines
2.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
# Import database dependency
|
|
from ..database import get_db
|
|
from ..services.check_user_service import verify_customer_authorize_account
|
|
from ..services.user_delete import delete_user_account
|
|
from ..services.user_create import create_user_account
|
|
|
|
# Create router for user check endpoints
|
|
user_check_router = APIRouter()
|
|
|
|
|
|
@user_check_router.get("/check-authorize-account/{customer_id}", summary="Check if customer has valid Authorize.net account setup")
|
|
def check_authorize_account(customer_id: int, db: Session = Depends(get_db)):
|
|
"""
|
|
Check if customer has a valid Authorize.net account and payment methods for charging.
|
|
|
|
Returns status indicating what's needed for payment processing.
|
|
"""
|
|
try:
|
|
result = verify_customer_authorize_account(db, customer_id)
|
|
return result
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Error checking authorize account: {str(e)}")
|
|
|
|
|
|
@user_check_router.post("/create-account/{customer_id}", summary="Create customer's Authorize.net account using existing cards")
|
|
def create_account(customer_id: int, db: Session = Depends(get_db)):
|
|
"""
|
|
Create the complete Authorize.net account for a customer using their existing cards.
|
|
This creates the customer profile and all associated payment profiles in Authorize.net,
|
|
and updates the database with the profile IDs.
|
|
"""
|
|
try:
|
|
result = create_user_account(db, customer_id)
|
|
return result
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Error creating authorize account: {str(e)}")
|
|
|
|
|
|
@user_check_router.delete("/delete-account/{customer_id}", summary="Delete customer's Authorize.net account and all payment profiles")
|
|
def delete_account(customer_id: int, db: Session = Depends(get_db)):
|
|
"""
|
|
Delete the complete Authorize.net account for a customer.
|
|
This removes the customer profile and all associated payment profiles from Authorize.net,
|
|
and updates the database to null out the ID fields.
|
|
"""
|
|
try:
|
|
result = delete_user_account(db, customer_id)
|
|
return result
|
|
except Exception as e:
|
|
raise HTTPException(status_code=500, detail=f"Error deleting authorize account: {str(e)}")
|