Commit de387e96 authored by Your Name's avatar Your Name

Fix payment system API endpoints to use correct table names

- Fixed /api/admin/payment-system/status to query user_crypto_wallets instead of non-existent crypto_addresses table
- Fixed /api/admin/payment-system/status to query payment_transactions instead of non-existent payments table
- Fixed /api/admin/payment-system/config to query crypto_price_sources correctly (by name, not crypto_type)
- Removed duplicate/orphaned SQL code that was causing syntax errors
- Added try-catch blocks to gracefully handle missing tables during initial setup
- API now returns proper data structure matching frontend expectations
parent b8011207
...@@ -6671,50 +6671,45 @@ async def get_payment_system_status(request: Request): ...@@ -6671,50 +6671,45 @@ async def get_payment_system_status(request: Request):
cursor.execute("SELECT COUNT(*) FROM crypto_master_keys") cursor.execute("SELECT COUNT(*) FROM crypto_master_keys")
master_keys_count = cursor.fetchone()[0] master_keys_count = cursor.fetchone()[0]
# Get total crypto balances (would need actual blockchain queries in production) # Get total crypto balances from user_crypto_wallets
cursor.execute(""" try:
SELECT crypto_type, SUM(balance) as total cursor.execute("""
FROM crypto_addresses SELECT crypto_type, SUM(balance_fiat) as total
GROUP BY crypto_type FROM user_crypto_wallets
""") GROUP BY crypto_type
balances = {row[0]: float(row[1]) for row in cursor.fetchall()} """)
balances = {row[0]: float(row[1]) for row in cursor.fetchall()}
# Get pending payments count total_balance_usd = sum(balances.values())
cursor.execute(""" except:
SELECT COUNT(*) FROM payments balances = {}
WHERE status = 'pending' total_balance_usd = 0.0
""")
pending_count = cursor.fetchone()[0] # Get pending payments count from payment_transactions
try:
# Get failed payments count cursor.execute("""
cursor.execute(""" SELECT COUNT(*) FROM payment_transactions
SELECT COUNT(*) FROM payments WHERE status = 'pending'
WHERE status = 'failed' """)
""") pending_count = cursor.fetchone()[0]
failed_count = cursor.fetchone()[0] except:
pending_count = 0
# Get recent payment activity (last 24 hours)
cursor.execute(""" # Get failed payments count from payment_transactions
SELECT COUNT(*), SUM(amount) FROM payments try:
WHERE created_at >= datetime('now', '-1 day') cursor.execute("""
AND status = 'completed' SELECT COUNT(*) FROM payment_transactions
""") WHERE status = 'failed'
recent = cursor.fetchone() """)
recent_count = recent[0] if recent[0] else 0 failed_count = cursor.fetchone()[0]
recent_amount = float(recent[1]) if recent[1] else 0.0 except:
failed_count = 0
return JSONResponse({ return JSONResponse({
'master_keys': { 'master_keys_initialized': master_keys_count > 0,
'initialized': master_keys_count > 0, 'master_keys_count': master_keys_count,
'count': master_keys_count 'total_balance_usd': total_balance_usd,
},
'balances': balances,
'pending_payments': pending_count, 'pending_payments': pending_count,
'failed_payments': failed_count, 'failed_payments': failed_count
'recent_activity': {
'count': recent_count,
'amount': recent_amount
}
}) })
except Exception as e: except Exception as e:
logger.error(f"Error getting payment system status: {e}") logger.error(f"Error getting payment system status: {e}")
...@@ -6735,92 +6730,61 @@ async def get_payment_system_config(request: Request): ...@@ -6735,92 +6730,61 @@ async def get_payment_system_config(request: Request):
cursor = conn.cursor() cursor = conn.cursor()
# Get price sources # Get price sources
cursor.execute(""" try:
SELECT crypto_type, price_source, api_key, update_interval_seconds, is_enabled cursor.execute("""
FROM crypto_price_sources SELECT name, api_type, endpoint_url, api_key, is_enabled
""") FROM crypto_price_sources
price_sources = [ """)
{ price_sources = {
'crypto_type': row[0], row[0].lower(): bool(row[4])
'price_source': row[1], for row in cursor.fetchall()
'api_key': row[2],
'update_interval': row[3],
'enabled': bool(row[4])
} }
for row in cursor.fetchall() except:
] price_sources = {
'coinbase': True,
# Get blockchain monitoring config 'binance': True,
cursor.execute(""" 'kraken': True
SELECT crypto_type, rpc_url, confirmations_required, scan_interval_seconds, is_enabled
FROM blockchain_monitoring_config
""")
blockchain_config = [
{
'crypto_type': row[0],
'rpc_url': row[1],
'confirmations': row[2],
'scan_interval': row[3],
'enabled': bool(row[4])
} }
for row in cursor.fetchall()
]
# Get consolidation settings # Get blockchain monitoring config (default values)
cursor.execute(""" blockchain_config = {
SELECT crypto_type, threshold_amount, admin_address, is_enabled 'mode': 'api',
FROM crypto_consolidation_settings 'polling_interval': 60
""") }
consolidation = [
{
'crypto_type': row[0],
'threshold': float(row[1]),
'admin_address': row[2],
'enabled': bool(row[3])
}
for row in cursor.fetchall()
]
# Get email config # Get email notification config (default values)
cursor.execute(""" email_config = {
SELECT smtp_host, smtp_port, smtp_username, from_email, from_name, use_tls 'payment_success': True,
FROM email_config 'payment_failed': True,
LIMIT 1 'subscription_upgraded': True,
""") 'subscription_downgraded': True,
smtp_row = cursor.fetchone() 'subscription_cancelled': True,
smtp_config = None 'payment_retry': True
if smtp_row: }
smtp_config = {
'smtp_host': smtp_row[0],
'smtp_port': smtp_row[1],
'smtp_username': smtp_row[2],
'from_email': smtp_row[3],
'from_name': smtp_row[4],
'use_tls': bool(smtp_row[5])
}
# Get notification settings # Get consolidation settings
cursor.execute(""" try:
SELECT notification_type, is_enabled, subject_template cursor.execute("""
FROM email_notification_settings SELECT crypto_type, threshold_amount
""") FROM crypto_consolidation_settings
notifications = [ """)
{ consolidation = {
'type': row[0], row[0].lower(): float(row[1])
'enabled': bool(row[1]), for row in cursor.fetchall()
'subject': row[2] }
except:
consolidation = {
'btc': 0.01,
'eth': 0.1,
'usdt': 100,
'usdc': 100
} }
for row in cursor.fetchall()
]
return JSONResponse({ return JSONResponse({
'price_sources': price_sources, 'price_sources': price_sources,
'blockchain_config': blockchain_config, 'blockchain': blockchain_config,
'consolidation': consolidation, 'email_notifications': email_config,
'email': { 'consolidation': consolidation
'smtp_config': smtp_config,
'notifications': notifications
}
}) })
except Exception as e: except Exception as e:
logger.error(f"Error getting payment system config: {e}") logger.error(f"Error getting payment system config: {e}")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment