Fixed e00007 error

This commit is contained in:
2025-09-28 10:17:35 -04:00
parent 5b4a05566a
commit 940be20852
10 changed files with 179 additions and 124 deletions

View File

@@ -17,18 +17,29 @@ logger = logging.getLogger(__name__)
# Load Authorize.net credentials
ApplicationConfig = load_config()
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
# Set Authorize.net environment based on configuration
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
constants.environment = constants.PRODUCTION
#constants.environment = constants.PRODUCTION
print("Constants:", ApplicationConfig.CURRENT_SETTINGS)
print("Authorize.Net URL:", constants.environment)
API_LOGIN_ID = '4d2Mn6H23R'
TRANSACTION_KEY = '7B94d8xfTQXv37WS'
# Override to standard production endpoint
constants.environment = "https://api.authorize.net/xml/v1/request.api"
print("Overridden Authorize.Net URL:", constants.environment)
else:
print("Constants:", ApplicationConfig.CURRENT_SETTINGS)
constants.environment = constants.SANDBOX
print("Authorize.Net URL:", constants.environment)
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
constants.show_url_on_request = True
def _get_error_message(response):
"""
Robust error parsing function that correctly handles the API's response format.
@@ -81,7 +92,7 @@ def create_user_account(db: Session, customer_id: int) -> dict:
"message": f"Customer {customer_id} not found",
"profile_id": None
}
print(customer)
# Get customer's cards from database
cards = crud.get_customer_cards(db, customer_id)
if not cards:
@@ -96,15 +107,17 @@ def create_user_account(db: Session, customer_id: int) -> dict:
# Get the first card to use for initial profile creation
first_card = cards[0]
logger.info(f"Using first card ID={first_card.id} for profile creation")
logger.info(f"Card Number: {first_card.card_number[:4]}**** ****{first_card.card_number[-4:]}")
logger.info(f"Expiration: {first_card.expiration_month}/{first_card.expiration_year}")
# Create CardCreate object for the first card
# Format expiration date for string values - pad year to 4 digits and month to 2 digits
expiration_year = first_card.expiration_year.zfill(4) if len(first_card.expiration_year) < 4 else first_card.expiration_year
expiration_month = first_card.expiration_month.zfill(2) if len(first_card.expiration_month) < 2 else first_card.expiration_month
# Convert to string first to handle cases where database returns int instead of string
exp_year_str = str(first_card.expiration_year)
exp_month_str = str(first_card.expiration_month)
expiration_year = exp_year_str.zfill(4) if len(exp_year_str) < 4 else exp_year_str
expiration_month = exp_month_str.zfill(2) if len(exp_month_str) < 2 else exp_month_str
expiration_date = f"{expiration_year}-{expiration_month}"
card_info = schemas.CardCreate(
card_number=first_card.card_number,
@@ -161,8 +174,11 @@ def create_user_account(db: Session, customer_id: int) -> dict:
for card in cards[1:]:
try:
# Format expiration date for string values
exp_year = card.expiration_year.zfill(4) if len(card.expiration_year) < 4 else card.expiration_year
exp_month = card.expiration_month.zfill(2) if len(card.expiration_month) < 2 else card.expiration_month
# Convert to string first to handle cases where database returns int instead of string
exp_year_str = str(card.expiration_year)
exp_month_str = str(card.expiration_month)
exp_year = exp_year_str.zfill(4) if len(exp_year_str) < 4 else exp_year_str
exp_month = exp_month_str.zfill(2) if len(exp_month_str) < 2 else exp_month_str
exp_date = f"{exp_year}-{exp_month}"
card_info_additional = schemas.CardCreate(
@@ -359,8 +375,11 @@ def refresh_customer_payment_profiles(db: Session, customer_id: int, auth_profil
for card in cards_need_update:
try:
# Format expiration date for recreation
exp_year = card.expiration_year.zfill(4) if len(card.expiration_year) < 4 else card.expiration_year
exp_month = card.expiration_month.zfill(2) if len(card.expiration_month) < 2 else card.expiration_month
# Convert to string first to handle cases where database returns int instead of string
exp_year_str = str(card.expiration_year)
exp_month_str = str(card.expiration_month)
exp_year = exp_year_str.zfill(4) if len(exp_year_str) < 4 else exp_year_str
exp_month = exp_month_str.zfill(2) if len(exp_month_str) < 2 else exp_month_str
exp_date = f"{exp_year}-{exp_month}"
card_create_data = schemas.CardCreate(