major claude changes
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import logging
|
||||
import traceback
|
||||
from authorizenet import apicontractsv1
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
from authorizenet.apicontrollers import (
|
||||
deleteCustomerProfileController,
|
||||
deleteCustomerPaymentProfileController
|
||||
@@ -53,7 +56,7 @@ def _get_authnet_error_message(response):
|
||||
text = msg.text if hasattr(msg, 'text') else 'No details provided.'
|
||||
return f"Error {code}: {text}"
|
||||
except Exception as e:
|
||||
print(f"Error while parsing Auth.Net error message: {e}")
|
||||
logger.debug(f"Error while parsing Auth.Net error message: {e}")
|
||||
return "An unparsable error occurred with the payment gateway."
|
||||
|
||||
return "An unknown error occurred with the payment gateway."
|
||||
@@ -98,29 +101,29 @@ def delete_user_account(db: Session, customer_id: int) -> dict:
|
||||
# Get customer's payment profiles/cards from database
|
||||
cards = crud.get_customer_cards(db, customer_id)
|
||||
|
||||
print(f"Starting deletion of Authorize.net account for customer {customer_id} (Profile ID: {profile_id_to_delete})")
|
||||
logger.debug(f"Starting deletion of Authorize.net account for customer {customer_id} (Profile ID: {profile_id_to_delete})")
|
||||
|
||||
# Step 1: Delete payment profiles first (must delete these before customer profile)
|
||||
deleted_payment_profiles = []
|
||||
if cards:
|
||||
print(f"Found {len(cards)} cards to delete from Authorize.net")
|
||||
logger.debug(f"Found {len(cards)} cards to delete from Authorize.net")
|
||||
|
||||
for card_index, card in enumerate(cards):
|
||||
if card.auth_net_payment_profile_id:
|
||||
try:
|
||||
print(f"Deleting payment profile {card.auth_net_payment_profile_id} for card {card.id}")
|
||||
logger.debug(f"Deleting payment profile {card.auth_net_payment_profile_id} for card {card.id}")
|
||||
|
||||
# Delete payment profile from Authorize.net
|
||||
success = _delete_payment_profile(profile_id_to_delete, card.auth_net_payment_profile_id)
|
||||
|
||||
if success:
|
||||
deleted_payment_profiles.append(card.auth_net_payment_profile_id)
|
||||
print(f"Successfully deleted payment profile {card.auth_net_payment_profile_id}")
|
||||
logger.debug(f"Successfully deleted payment profile {card.auth_net_payment_profile_id}")
|
||||
else:
|
||||
print(f"Failed to delete payment profile {card.auth_net_payment_profile_id} - it may not exist or already deleted")
|
||||
logger.debug(f"Failed to delete payment profile {card.auth_net_payment_profile_id} - it may not exist or already deleted")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error deleting payment profile {card.auth_net_payment_profile_id}: {str(e)}")
|
||||
logger.debug(f"Error deleting payment profile {card.auth_net_payment_profile_id}: {str(e)}")
|
||||
# Continue with other payment profiles - we want to delete as much as possible
|
||||
|
||||
# Always null out the payment profile ID in database (even if API delete failed)
|
||||
@@ -128,7 +131,7 @@ def delete_user_account(db: Session, customer_id: int) -> dict:
|
||||
db.add(card)
|
||||
|
||||
# Step 2: Delete customer profile
|
||||
print(f"Deleting customer profile {profile_id_to_delete}")
|
||||
logger.debug(f"Deleting customer profile {profile_id_to_delete}")
|
||||
profile_deleted_success = _delete_customer_profile(profile_id_to_delete)
|
||||
|
||||
# Step 3: Update database regardless of API results
|
||||
@@ -139,7 +142,7 @@ def delete_user_account(db: Session, customer_id: int) -> dict:
|
||||
db.commit()
|
||||
|
||||
if profile_deleted_success:
|
||||
print(f"Successfully deleted Authorize.net account for customer {customer_id}")
|
||||
logger.debug(f"Successfully deleted Authorize.net account for customer {customer_id}")
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"Successfully deleted Authorize.net account with profile ID {profile_id_to_delete}",
|
||||
@@ -148,7 +151,7 @@ def delete_user_account(db: Session, customer_id: int) -> dict:
|
||||
"deleted_payment_profiles": deleted_payment_profiles
|
||||
}
|
||||
else:
|
||||
print(f"Customer profile {profile_id_to_delete} may not have been completely removed from Authorize.net, but database has been updated")
|
||||
logger.debug(f"Customer profile {profile_id_to_delete} may not have been completely removed from Authorize.net, but database has been updated")
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"Profile {profile_id_to_delete} may not have been completely removed from Authorize.net, but database has been cleaned up",
|
||||
@@ -158,7 +161,7 @@ def delete_user_account(db: Session, customer_id: int) -> dict:
|
||||
}
|
||||
|
||||
except Exception as e:
|
||||
print(f"Critical exception during account deletion for customer {customer_id}: {traceback.format_exc()}")
|
||||
logger.debug(f"Critical exception during account deletion for customer {customer_id}: {traceback.format_exc()}")
|
||||
db.rollback()
|
||||
return {
|
||||
"success": False,
|
||||
@@ -200,23 +203,23 @@ def _delete_customer_profile(profile_id: str) -> bool:
|
||||
response = controller.getresponse()
|
||||
|
||||
if response is None:
|
||||
print(f"No response received when trying to delete profile {profile_id}")
|
||||
logger.debug(f"No response received when trying to delete profile {profile_id}")
|
||||
return False
|
||||
|
||||
if hasattr(response, 'messages') and response.messages.resultCode == "Ok":
|
||||
print(f"Successfully deleted customer profile {profile_id}")
|
||||
logger.debug(f"Successfully deleted customer profile {profile_id}")
|
||||
return True
|
||||
else:
|
||||
error_msg = _get_authnet_error_message(response)
|
||||
print(f"Failed to delete customer profile {profile_id}: {error_msg}")
|
||||
logger.debug(f"Failed to delete customer profile {profile_id}: {error_msg}")
|
||||
# Still count as success if the profile was already deleted/not found
|
||||
if "not found" in error_msg.lower() or "E00040" in error_msg or "E00035" in error_msg:
|
||||
print(f"Profile {profile_id} was already deleted or doesn't exist")
|
||||
logger.debug(f"Profile {profile_id} was already deleted or doesn't exist")
|
||||
return True
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"Exception during delete customer profile {profile_id}: {str(e)}")
|
||||
logger.debug(f"Exception during delete customer profile {profile_id}: {str(e)}")
|
||||
return False
|
||||
|
||||
|
||||
@@ -255,21 +258,21 @@ def _delete_payment_profile(customer_profile_id: str, payment_profile_id: str) -
|
||||
response = controller.getresponse()
|
||||
|
||||
if response is None:
|
||||
print(f"No response received when trying to delete payment profile {payment_profile_id}")
|
||||
logger.debug(f"No response received when trying to delete payment profile {payment_profile_id}")
|
||||
return False
|
||||
|
||||
if hasattr(response, 'messages') and response.messages.resultCode == "Ok":
|
||||
print(f"Successfully deleted payment profile {payment_profile_id}")
|
||||
logger.debug(f"Successfully deleted payment profile {payment_profile_id}")
|
||||
return True
|
||||
else:
|
||||
error_msg = _get_authnet_error_message(response)
|
||||
print(f"Failed to delete payment profile {payment_profile_id}: {error_msg}")
|
||||
logger.debug(f"Failed to delete payment profile {payment_profile_id}: {error_msg}")
|
||||
# Still count as success if the payment profile was already deleted/not found
|
||||
if "not found" in error_msg.lower() or "E00040" in error_msg or "E00035" in error_msg:
|
||||
print(f"Payment profile {payment_profile_id} was already deleted or doesn't exist")
|
||||
logger.debug(f"Payment profile {payment_profile_id} was already deleted or doesn't exist")
|
||||
return True
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"Exception during delete payment profile {payment_profile_id}: {str(e)}")
|
||||
logger.debug(f"Exception during delete payment profile {payment_profile_id}: {str(e)}")
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user