Updated for local

This commit is contained in:
2025-11-04 19:34:46 -05:00
parent 8d139063a8
commit 034beee614
6 changed files with 82 additions and 112 deletions

View File

@@ -17,20 +17,27 @@ from config import load_config # Assuming you have this
# Load Authorize.net credentials
ApplicationConfig = load_config()
# Set Authorize.net environment based on configuration
# Set Authorize.net environment based on configuration
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
constants.environment = constants.PRODUCTION
VALIDATION_MODE = "liveMode"
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
constants.environment = constants.PRODUCTION
VALIDATION_MODE = "liveMode"
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
else:
constants.environment = constants.SANDBOX
constants.show_url_on_request = True # Very useful for debugging
constants.show_url_on_request = True
VALIDATION_MODE = "testMode"
API_LOGIN_ID = ApplicationConfig.API_LOGIN_ID
TRANSACTION_KEY = ApplicationConfig.TRANSACTION_KEY
def _is_e00121_response(response):
"""
Check if the Authorize.Net response contains E00121 error (invalid payment profile ID).
@@ -95,7 +102,8 @@ def create_customer_profile(customer: schemas.Customer, card_info: schemas.CardC
This version sanitizes and trims customer data before sending.
"""
print(f"Attempting to create Auth.Net profile for customer ID: {customer.id}")
print(API_LOGIN_ID)
print(TRANSACTION_KEY)
try:
merchantAuth = apicontractsv1.merchantAuthenticationType(name=API_LOGIN_ID, transactionKey=TRANSACTION_KEY)
except Exception as e:
@@ -121,6 +129,9 @@ def create_customer_profile(customer: schemas.Customer, card_info: schemas.CardC
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()
response = controller.getresponse()
@@ -245,6 +256,9 @@ def _perform_authorization(customer_profile_id: str, payment_profile_id: str, tr
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()
@@ -284,6 +298,9 @@ def capture_authorized_transaction(transaction_req: schemas.TransactionCapture):
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()
@@ -365,6 +382,9 @@ def add_payment_profile_to_customer(customer_profile_id: str, customer: schemas.
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()
@@ -412,6 +432,9 @@ def get_customer_payment_profiles(customer_profile_id: str):
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()
@@ -463,6 +486,9 @@ def charge_customer_profile(customer_profile_id: str, payment_profile_id: str, t
if ApplicationConfig.CURRENT_SETTINGS == 'PRODUCTION':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
elif ApplicationConfig.CURRENT_SETTINGS == 'LOCAL':
controller.setenvironment(constants.PRODUCTION)
controller.execute()
else:
controller.execute()