small fixes working great
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user