Working payment accopunts
This commit is contained in:
@@ -205,15 +205,36 @@ def authorize_saved_card(customer_id: int, transaction_req: schemas.TransactionA
|
||||
|
||||
if not db_customer or not db_card or db_card.user_id != customer_id:
|
||||
raise HTTPException(status_code=404, detail="Customer or card not found for this account")
|
||||
|
||||
|
||||
# Add CRITICAL DEBUGGING to see exactly what's in the database
|
||||
print(f"ROUTER DEBUG: Customer ID: {customer_id}")
|
||||
print(f"ROUTER DEBUG: db_customer: {db_customer}")
|
||||
print(f"ROUTER DEBUG: db_customer.auth_net_profile_id: '{db_customer.auth_net_profile_id}' (type: {type(db_customer.auth_net_profile_id)})")
|
||||
print(f"ROUTER DEBUG: db_card: {db_card}")
|
||||
print(f"ROUTER DEBUG: db_card.auth_net_payment_profile_id: '{db_card.auth_net_payment_profile_id}' (type: {type(db_card.auth_net_payment_profile_id)})")
|
||||
|
||||
# Check for specific problem values
|
||||
if db_card.auth_net_payment_profile_id is None:
|
||||
print("ROUTER DEBUG: CRITICAL - payment_profile_id is None - this will cause E00121!")
|
||||
elif db_card.auth_net_payment_profile_id == "":
|
||||
print("ROUTER DEBUG: CRITICAL - payment_profile_id is empty string - this will cause E00121!")
|
||||
elif str(db_card.auth_net_payment_profile_id).lower() == "none":
|
||||
print("ROUTER DEBUG: CRITICAL - payment_profile_id is string 'None' - this will cause E00121!")
|
||||
else:
|
||||
print(f"ROUTER DEBUG: payment_profile_id appears valid: '{db_card.auth_net_payment_profile_id}'")
|
||||
|
||||
if not db_customer.auth_net_profile_id or not db_card.auth_net_payment_profile_id:
|
||||
print(f"ROUTER DEBUG: WILL THROW HTTP 400 ERROR: auth_net_profile_id='{db_customer.auth_net_profile_id}', payment_profile_id='{db_card.auth_net_payment_profile_id}'")
|
||||
raise HTTPException(status_code=400, detail="Payment profile is not set up correctly for this customer/card")
|
||||
|
||||
# Call the NEW service function for authorization
|
||||
# Call the service function for authorization with auto-recovery enabled
|
||||
auth_net_response = payment_service.authorize_customer_profile(
|
||||
customer_profile_id=db_customer.auth_net_profile_id,
|
||||
payment_profile_id=db_card.auth_net_payment_profile_id,
|
||||
transaction_req=transaction_req
|
||||
transaction_req=transaction_req,
|
||||
db_session=db, # For auto-recovery
|
||||
customer_id=customer_id, # For auto-recovery
|
||||
card_id=db_card.id # For auto-recovery
|
||||
)
|
||||
|
||||
status, auth_net_transaction_id, rejection_reason = _parse_authnet_response(auth_net_response)
|
||||
|
||||
53
app/routers/user_check.py
Normal file
53
app/routers/user_check.py
Normal file
@@ -0,0 +1,53 @@
|
||||
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)}")
|
||||
Reference in New Issue
Block a user