small fixes working great
This commit is contained in:
@@ -90,9 +90,9 @@ def verify_customer_authorize_account(db: Session, customer_id: int) -> dict:
|
||||
|
||||
# Check for payment profiles (cards)
|
||||
has_payment_methods = False
|
||||
if hasattr(response, 'profile') and response.profile:
|
||||
if hasattr(response, 'profile') and response.profile is not None:
|
||||
payment_profiles = response.profile.paymentProfiles
|
||||
if payment_profiles and len(payment_profiles) > 0:
|
||||
if len(payment_profiles) > 0:
|
||||
has_payment_methods = True
|
||||
|
||||
missing_components = []
|
||||
@@ -127,7 +127,7 @@ def _is_profile_valid(response) -> bool:
|
||||
"""
|
||||
try:
|
||||
# Check basic response validity
|
||||
if not response:
|
||||
if response is None:
|
||||
return False
|
||||
|
||||
# Check if result code indicates success
|
||||
@@ -139,7 +139,7 @@ def _is_profile_valid(response) -> bool:
|
||||
return False
|
||||
|
||||
# Check for any error messages that indicate profile doesn't exist
|
||||
if hasattr(response, 'messages') and response.messages.message:
|
||||
if hasattr(response, 'messages') and len(response.messages.message) > 0:
|
||||
for message in response.messages.message:
|
||||
# Check for specific error codes that indicate profile doesn't exist
|
||||
if hasattr(message, 'code'):
|
||||
|
||||
@@ -25,11 +25,11 @@ if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
|
||||
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
|
||||
else:
|
||||
constants.environment = constants.SANDBOX
|
||||
constants.show_url_on_request = True # Very useful for debugging
|
||||
VALIDATION_MODE = "testMode"
|
||||
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
|
||||
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
|
||||
|
||||
constants.show_url_on_request = True # Very useful for debugging
|
||||
|
||||
def _is_e00121_response(response):
|
||||
"""
|
||||
@@ -71,7 +71,7 @@ def _get_authnet_error_message(response):
|
||||
return "No response from payment gateway."
|
||||
try:
|
||||
if hasattr(response, 'messages') and response.messages is not None:
|
||||
if hasattr(response, 'transactionResponse') and response.transactionResponse and hasattr(response.transactionResponse, 'errors') and response.transactionResponse.errors:
|
||||
if hasattr(response, 'transactionResponse') and response.transactionResponse is not None and hasattr(response.transactionResponse, 'errors') and response.transactionResponse.errors:
|
||||
error = response.transactionResponse.errors[0]
|
||||
return f"Error {error.errorCode}: {error.errorText}"
|
||||
if hasattr(response.messages, 'message'):
|
||||
@@ -251,11 +251,11 @@ def _perform_authorization(customer_profile_id: str, payment_profile_id: str, tr
|
||||
response = controller.getresponse()
|
||||
|
||||
# Log response details
|
||||
if response and hasattr(response, 'messages'):
|
||||
if response is not None and hasattr(response, 'messages'):
|
||||
result_code = getattr(response.messages, 'resultCode', 'Unknown')
|
||||
print(f"Authorize response: resultCode='{result_code}'")
|
||||
print(f"✅ Authorize response: resultCode='{result_code}'")
|
||||
else:
|
||||
print("Authorize response: No standard response structure")
|
||||
print("✅ Authorize response: No standard response structure")
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@@ -13,8 +13,6 @@ from sqlalchemy.orm import Session
|
||||
from . import payment_service
|
||||
from .. import schemas
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Load Authorize.net credentials
|
||||
ApplicationConfig = load_config()
|
||||
|
||||
@@ -181,8 +179,8 @@ def create_user_account(db: Session, customer_id: int) -> dict:
|
||||
print(f"Assigning {num_to_update} payment profile IDs to cards")
|
||||
|
||||
if len(payment_profile_ids) != len(cards):
|
||||
logger.warning(f"Mismatch between payment profile count ({len(payment_profile_ids)}) and card count ({len(cards)})")
|
||||
logger.warning("This could cause incorrect payment profile assignments!")
|
||||
print(f"Mismatch between payment profile count ({len(payment_profile_ids)}) and card count ({len(cards)})")
|
||||
print("This could cause incorrect payment profile assignments!")
|
||||
|
||||
cards_updated = 0
|
||||
for i in range(num_to_update):
|
||||
@@ -224,7 +222,7 @@ def create_user_account(db: Session, customer_id: int) -> dict:
|
||||
# 🔄 PROACTIVELY REFRESH PAYMENT PROFILES TO ENSURE VALIDITY
|
||||
print(f"🔄 Auto-refresh START: customer_id={customer_id}, auth_profile_id={auth_profile_id}")
|
||||
print(f"🔄 Auto-refresh BEFORE: Cards have these payment profile IDs: {[f'card_{c.id}={c.auth_net_payment_profile_id}' for c in cards]}")
|
||||
|
||||
|
||||
|
||||
# Check what changed after refresh
|
||||
cards_after = crud.get_customer_cards(db, customer_id)
|
||||
@@ -278,7 +276,7 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
|
||||
payment_profile_ids = payment_service.get_customer_payment_profiles(auth_profile_id)
|
||||
print(f"🔄 Retrieved {len(payment_profile_ids)} payment profiles from Authorize.net: {payment_profile_ids}")
|
||||
except Exception as e:
|
||||
logger.warning(f"🔄 Could not retrieve payment profiles from Authorize.net: {str(e)}")
|
||||
print(f"🔄 Could not retrieve payment profiles from Authorize.net: {str(e)}")
|
||||
print("🔄 Will attempt to recreate missing payment profiles")
|
||||
|
||||
# STEP 2: Check if we have enough payment profiles for our cards
|
||||
@@ -290,7 +288,7 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
|
||||
elif str(card.auth_net_payment_profile_id) not in [str(pid) for pid in payment_profile_ids if pid]:
|
||||
# Payment profile ID exists in DB but not found in Authorize.net - likely invalid
|
||||
cards_need_update.append(card)
|
||||
logger.warning(f"🔄 Card {card.id} has payment profile ID {card.auth_net_payment_profile_id} but it's not found in Authorize.net - NEEDS RECREATION")
|
||||
print(f"🔄 Card {card.id} has payment profile ID {card.auth_net_payment_profile_id} but it's not found in Authorize.net - NEEDS RECREATION")
|
||||
else:
|
||||
if ApplicationConfig.penny_test_transaction:
|
||||
# Profile exists in Authorize.net, but let's double-check it's usable by doing a quick test
|
||||
@@ -311,7 +309,7 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
|
||||
_, _, test_reason = payment_service._parse_authnet_response(test_response)
|
||||
if "E00121" in str(test_reason):
|
||||
cards_need_update.append(card)
|
||||
logger.warning(f"🔄 Card {card.id} has profile {card.auth_net_payment_profile_id} that EXISTS but is CORRUPTED - NEEDS RECREATION")
|
||||
print(f"🔄 Card {card.id} has profile {card.auth_net_payment_profile_id} that EXISTS but is CORRUPTED - NEEDS RECREATION")
|
||||
# Explicitly delete the corrupted profile first
|
||||
try:
|
||||
from . import user_delete
|
||||
@@ -321,14 +319,14 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
|
||||
card.auth_net_payment_profile_id = None
|
||||
db.add(card)
|
||||
except Exception as del_e:
|
||||
logger.warning(f"🔄 Failed to delete corrupted profile {card.auth_net_payment_profile_id}: {str(del_e)}")
|
||||
print(f"🔄 Failed to delete corrupted profile {card.auth_net_payment_profile_id}: {str(del_e)}")
|
||||
else:
|
||||
logger.debug(f"🔄 Card {card.id} has valid and usable payment profile ID {card.auth_net_payment_profile_id}")
|
||||
print(f"🔄 Card {card.id} has valid and usable payment profile ID {card.auth_net_payment_profile_id}")
|
||||
except Exception as test_e:
|
||||
logger.warning(f"🔄 Could not test usability of profile {card.auth_net_payment_profile_id} for card {card.id}: {str(test_e)} - assuming it's okay")
|
||||
print(f"🔄 Could not test usability of profile {card.auth_net_payment_profile_id} for card {card.id}: {str(test_e)} - assuming it's okay")
|
||||
else:
|
||||
print(f"🔄 Skipping penny test transaction for card {card.id} (disabled in config)")
|
||||
logger.debug(f"🔄 Card {card.id} has payment profile ID {card.auth_net_payment_profile_id} in Authorize.net - skipping usability test (config disabled)")
|
||||
print(f"🔄 Card {card.id} has payment profile ID {card.auth_net_payment_profile_id} in Authorize.net - skipping usability test (config disabled)")
|
||||
|
||||
# STEP 3: If we don't have enough valid payment profiles, recreate missing ones
|
||||
if len(cards_need_update) > 0:
|
||||
@@ -400,7 +398,7 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
|
||||
print(f"🔄 Refresh COMPLETE: All {len(cards_final)} cards have valid payment profile IDs")
|
||||
return True
|
||||
else:
|
||||
logger.warning("🔄 Refresh PARTIAL: Some cards may still have invalid payment profile IDs")
|
||||
print("🔄 Refresh PARTIAL: Some cards may still have invalid payment profile IDs")
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -21,7 +21,7 @@ else:
|
||||
constants.environment = constants.SANDBOX
|
||||
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
|
||||
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
|
||||
constants.show_url_on_request = True
|
||||
constants.show_url_on_request = True
|
||||
|
||||
|
||||
def _get_authnet_error_message(response):
|
||||
|
||||
Reference in New Issue
Block a user