mirror of
https://github.com/thecyberlearn/quantum-ai.git
synced 2026-08-18 16:32:59 +00:00
Clean up testing and debug code for production
🧹 CLEANUP COMPLETED: Removed unused testing/debugging code: - Wallet demo system (views, templates, URLs) - Webhook testing system (views, templates, URLs) - Manual payment verification (orphaned function) - External testing scripts - Cleaned up URL routes Kept essential production code: - Core wallet functionality - Payment flow (topup, success, cancel) - Stripe debug endpoint (for troubleshooting) - Main Stripe webhook handler Result: ~500+ lines of unused code removed, cleaner production codebase. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
8f56fcf35c
commit
58b92b98e4
@ -12,14 +12,7 @@ urlpatterns = [
|
|||||||
path('wallet/topup/', views.wallet_topup_view, name='wallet_topup'),
|
path('wallet/topup/', views.wallet_topup_view, name='wallet_topup'),
|
||||||
path('wallet/top-up/success/', views.wallet_topup_success_view, name='wallet_topup_success'),
|
path('wallet/top-up/success/', views.wallet_topup_success_view, name='wallet_topup_success'),
|
||||||
path('wallet/top-up/cancel/', views.wallet_topup_cancel_view, name='wallet_topup_cancel'),
|
path('wallet/top-up/cancel/', views.wallet_topup_cancel_view, name='wallet_topup_cancel'),
|
||||||
path('wallet/demo/', views.wallet_demo_view, name='wallet_demo'),
|
|
||||||
path('wallet/demo/test-payment/', views.wallet_demo_test_payment, name='wallet_demo_test_payment'),
|
|
||||||
path('wallet/demo/check-balance/', views.wallet_demo_check_balance, name='wallet_demo_check_balance'),
|
|
||||||
path('stripe/debug/', views.stripe_debug_view, name='stripe_debug'),
|
path('stripe/debug/', views.stripe_debug_view, name='stripe_debug'),
|
||||||
path('stripe/webhook/', views.stripe_webhook_view, name='stripe_webhook'),
|
path('stripe/webhook/', views.stripe_webhook_view, name='stripe_webhook'),
|
||||||
path('webhook-test/', views.webhook_test_view, name='webhook_test'),
|
|
||||||
path('stripe-webhook-test/', views.stripe_webhook_test_view, name='stripe_webhook_test'),
|
|
||||||
path('simple-webhook-test/', views.simple_webhook_test, name='simple_webhook_test'),
|
|
||||||
path('webhook-logs/', views.get_webhook_logs, name='webhook_logs'),
|
|
||||||
path('api/agents/', views.agents_api_view, name='agents_api'),
|
path('api/agents/', views.agents_api_view, name='agents_api'),
|
||||||
]
|
]
|
||||||
167
core/views.py
167
core/views.py
@ -172,122 +172,6 @@ def wallet_topup_cancel_view(request):
|
|||||||
return redirect('core:wallet_topup')
|
return redirect('core:wallet_topup')
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def wallet_demo_view(request):
|
|
||||||
"""Demo page for testing Stripe webhook integration"""
|
|
||||||
|
|
||||||
# Get recent transactions for debugging
|
|
||||||
recent_transactions = request.user.wallet_transactions.all()[:10]
|
|
||||||
|
|
||||||
# Get current balance
|
|
||||||
current_balance = request.user.wallet_balance
|
|
||||||
|
|
||||||
context = {
|
|
||||||
'current_balance': current_balance,
|
|
||||||
'recent_transactions': recent_transactions,
|
|
||||||
'user_id': request.user.id,
|
|
||||||
'user_email': request.user.email,
|
|
||||||
}
|
|
||||||
|
|
||||||
return render(request, 'core/wallet_demo.html', context)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def wallet_demo_test_payment(request):
|
|
||||||
"""Test payment creation for webhook testing"""
|
|
||||||
if request.method == 'POST':
|
|
||||||
try:
|
|
||||||
data = json.loads(request.body)
|
|
||||||
amount = float(data.get('amount', 10))
|
|
||||||
|
|
||||||
# Validate amount
|
|
||||||
if amount not in [10, 50, 100, 500]:
|
|
||||||
return JsonResponse({'error': 'Invalid amount'}, status=400)
|
|
||||||
|
|
||||||
print(f"🧪 DEMO: Creating test payment for {request.user.email}")
|
|
||||||
print(f"🧪 DEMO: Amount: {amount} AED, User ID: {request.user.id}")
|
|
||||||
|
|
||||||
# Create Stripe checkout session
|
|
||||||
stripe_handler = StripePaymentHandler()
|
|
||||||
session_data = stripe_handler.create_checkout_session(request.user, amount, request)
|
|
||||||
|
|
||||||
return JsonResponse({
|
|
||||||
'success': True,
|
|
||||||
'payment_url': session_data['payment_url'],
|
|
||||||
'session_id': session_data['session_id'],
|
|
||||||
'user_id': request.user.id,
|
|
||||||
'amount': amount
|
|
||||||
})
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
print(f"🧪 DEMO: Error creating payment: {e}")
|
|
||||||
return JsonResponse({'error': str(e)}, status=500)
|
|
||||||
|
|
||||||
return JsonResponse({'error': 'Method not allowed'}, status=405)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def wallet_demo_check_balance(request):
|
|
||||||
"""Check current wallet balance for demo"""
|
|
||||||
request.user.refresh_from_db()
|
|
||||||
|
|
||||||
# Get latest transactions
|
|
||||||
recent_transactions = []
|
|
||||||
for transaction in request.user.wallet_transactions.all()[:5]:
|
|
||||||
recent_transactions.append({
|
|
||||||
'amount': float(transaction.amount),
|
|
||||||
'type': transaction.type,
|
|
||||||
'description': transaction.description,
|
|
||||||
'created_at': transaction.created_at.isoformat(),
|
|
||||||
'stripe_session_id': transaction.stripe_session_id
|
|
||||||
})
|
|
||||||
|
|
||||||
return JsonResponse({
|
|
||||||
'balance': float(request.user.wallet_balance),
|
|
||||||
'user_id': request.user.id,
|
|
||||||
'recent_transactions': recent_transactions,
|
|
||||||
'timestamp': request.user.updated_at.isoformat() if hasattr(request.user, 'updated_at') else None
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
|
||||||
def verify_payment_view(request):
|
|
||||||
"""Manual payment verification endpoint (fallback for webhook issues)"""
|
|
||||||
if request.method == 'POST':
|
|
||||||
try:
|
|
||||||
data = json.loads(request.body)
|
|
||||||
session_id = data.get('session_id', '').strip()
|
|
||||||
|
|
||||||
if not session_id:
|
|
||||||
return JsonResponse({'error': 'Session ID is required'}, status=400)
|
|
||||||
|
|
||||||
# Verify payment with Stripe
|
|
||||||
from wallet.stripe_handler import StripePaymentHandler
|
|
||||||
stripe_handler = StripePaymentHandler()
|
|
||||||
|
|
||||||
print(f"🔍 [MANUAL VERIFY] User {request.user.id} verifying session: {session_id}")
|
|
||||||
result = stripe_handler.verify_payment(session_id)
|
|
||||||
|
|
||||||
if result['success']:
|
|
||||||
return JsonResponse({
|
|
||||||
'success': True,
|
|
||||||
'processed': result['processed'],
|
|
||||||
'amount': result.get('amount', 0),
|
|
||||||
'message': result['message']
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
return JsonResponse({
|
|
||||||
'success': False,
|
|
||||||
'error': result['error']
|
|
||||||
})
|
|
||||||
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
return JsonResponse({'error': 'Invalid JSON data'}, status=400)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ [MANUAL VERIFY] Error: {e}")
|
|
||||||
return JsonResponse({'error': str(e)}, status=500)
|
|
||||||
|
|
||||||
return JsonResponse({'error': 'Method not allowed'}, status=405)
|
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
@ -382,57 +266,6 @@ def stripe_debug_view(request):
|
|||||||
return JsonResponse(debug_info, indent=2)
|
return JsonResponse(debug_info, indent=2)
|
||||||
|
|
||||||
|
|
||||||
# Simple webhook test page
|
|
||||||
def webhook_test_view(request):
|
|
||||||
"""Simple HTML page for webhook testing"""
|
|
||||||
return render(request, 'core/webhook_test.html')
|
|
||||||
|
|
||||||
|
|
||||||
def stripe_webhook_test_view(request):
|
|
||||||
"""Stripe-specific webhook testing page"""
|
|
||||||
return render(request, 'core/stripe_webhook_test.html')
|
|
||||||
|
|
||||||
|
|
||||||
# Store webhook logs in memory for the test page
|
|
||||||
webhook_logs = []
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
def simple_webhook_test(request):
|
|
||||||
"""Ultra simple webhook endpoint for testing"""
|
|
||||||
timestamp = datetime.datetime.now().strftime("%H:%M:%S")
|
|
||||||
|
|
||||||
log_entry = {
|
|
||||||
'timestamp': timestamp,
|
|
||||||
'method': request.method,
|
|
||||||
'headers': dict(request.META),
|
|
||||||
'body': request.body.decode('utf-8') if request.body else '',
|
|
||||||
'content_type': request.content_type,
|
|
||||||
'query_params': dict(request.GET),
|
|
||||||
}
|
|
||||||
|
|
||||||
# Store in memory (keep only last 50 logs)
|
|
||||||
webhook_logs.append(log_entry)
|
|
||||||
if len(webhook_logs) > 50:
|
|
||||||
webhook_logs.pop(0)
|
|
||||||
|
|
||||||
# Also print to console
|
|
||||||
print(f"🧪 SIMPLE WEBHOOK [{timestamp}] Method: {request.method}")
|
|
||||||
print(f"🧪 SIMPLE WEBHOOK [{timestamp}] Content-Type: {request.content_type}")
|
|
||||||
print(f"🧪 SIMPLE WEBHOOK [{timestamp}] Body length: {len(request.body)} bytes")
|
|
||||||
print(f"🧪 SIMPLE WEBHOOK [{timestamp}] Headers: {dict(request.META)}")
|
|
||||||
|
|
||||||
# Return simple success response
|
|
||||||
return HttpResponse("WEBHOOK RECEIVED OK", content_type="text/plain")
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
|
||||||
def get_webhook_logs(request):
|
|
||||||
"""Get webhook logs for the test page"""
|
|
||||||
try:
|
|
||||||
return JsonResponse({'logs': webhook_logs})
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error in get_webhook_logs: {e}")
|
|
||||||
return JsonResponse({'logs': [], 'error': str(e)})
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
|||||||
@ -1,573 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
{% load static %}
|
|
||||||
|
|
||||||
{% block title %}Stripe Webhook Testing{% endblock %}
|
|
||||||
|
|
||||||
{% block extra_css %}
|
|
||||||
<style>
|
|
||||||
.test-page {
|
|
||||||
background: var(--gradient-hero);
|
|
||||||
min-height: calc(100vh - 80px);
|
|
||||||
padding: clamp(20px, 5vw, 40px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-container {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 24px;
|
|
||||||
align-items: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-card {
|
|
||||||
background: rgba(255, 255, 255, 0.95);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 24px;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-title {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--text-primary);
|
|
||||||
margin-bottom: 20px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-indicator {
|
|
||||||
width: 12px;
|
|
||||||
height: 12px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: #e74c3c;
|
|
||||||
animation: pulse 2s infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-indicator.connected {
|
|
||||||
background: #27ae60;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse {
|
|
||||||
0% { opacity: 1; }
|
|
||||||
50% { opacity: 0.5; }
|
|
||||||
100% { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.webhook-url {
|
|
||||||
background: #f8fafc;
|
|
||||||
border: 2px solid #e2e8f0;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 15px 0;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
word-break: break-all;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 8px;
|
|
||||||
right: 8px;
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
font-size: 11px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-buttons {
|
|
||||||
display: flex;
|
|
||||||
gap: 12px;
|
|
||||||
margin: 20px 0;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 120px;
|
|
||||||
padding: 10px 16px;
|
|
||||||
border: 2px solid var(--primary-blue);
|
|
||||||
background: transparent;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
border-radius: 6px;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 13px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn:hover {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn.primary {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn.primary:hover {
|
|
||||||
background: var(--primary-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
.webhook-logs {
|
|
||||||
background: #1a1a1a;
|
|
||||||
color: #00ff00;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 15px 0;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.4;
|
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: auto;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-entry {
|
|
||||||
margin: 2px 0;
|
|
||||||
padding: 2px 0;
|
|
||||||
border-left: 3px solid transparent;
|
|
||||||
padding-left: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-stripe {
|
|
||||||
border-left-color: #00ff00;
|
|
||||||
background: rgba(0, 255, 0, 0.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-test {
|
|
||||||
border-left-color: #74c0fc;
|
|
||||||
background: rgba(116, 192, 252, 0.05);
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-timestamp {
|
|
||||||
color: #888;
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-success {
|
|
||||||
color: #00ff00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-error {
|
|
||||||
color: #ff6b6b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-info {
|
|
||||||
color: #74c0fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-warning {
|
|
||||||
color: #ffd43b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-grid {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-item {
|
|
||||||
background: #f8fafc;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 12px;
|
|
||||||
text-align: center;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-value {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
margin-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.instructions {
|
|
||||||
background: #e3f2fd;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clear-logs {
|
|
||||||
position: absolute;
|
|
||||||
top: 8px;
|
|
||||||
right: 8px;
|
|
||||||
background: #444;
|
|
||||||
color: #fff;
|
|
||||||
border: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 4px 8px;
|
|
||||||
font-size: 10px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stripe-dashboard-link {
|
|
||||||
display: inline-block;
|
|
||||||
background: #635bff;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
padding: 8px 16px;
|
|
||||||
border-radius: 6px;
|
|
||||||
font-weight: 600;
|
|
||||||
font-size: 13px;
|
|
||||||
margin: 10px 0;
|
|
||||||
transition: background 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.stripe-dashboard-link:hover {
|
|
||||||
background: #5a54d6;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="test-page">
|
|
||||||
<div class="test-container">
|
|
||||||
<!-- Stripe Webhook Configuration -->
|
|
||||||
<div class="test-card">
|
|
||||||
<h2 class="test-title">
|
|
||||||
⚡ Stripe Webhook Config
|
|
||||||
<div class="status-indicator" id="configStatus"></div>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div class="instructions">
|
|
||||||
<strong>📋 Setup Instructions:</strong><br>
|
|
||||||
1. Copy the webhook URL below<br>
|
|
||||||
2. Go to Stripe Dashboard → Webhooks<br>
|
|
||||||
3. Create new endpoint with this URL<br>
|
|
||||||
4. Select "checkout.session.completed" event<br>
|
|
||||||
5. Test with payment below
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="webhook-url">
|
|
||||||
<strong>Stripe Webhook URL:</strong><br>
|
|
||||||
<span id="stripeWebhookUrl">https://netcop.up.railway.app/stripe/webhook/</span>
|
|
||||||
<button class="copy-btn" onclick="copyUrl('stripeWebhookUrl')">📋 Copy</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="webhook-url">
|
|
||||||
<strong>Simple Test URL:</strong><br>
|
|
||||||
<span id="simpleWebhookUrl">https://netcop.up.railway.app/simple-webhook-test/</span>
|
|
||||||
<button class="copy-btn" onclick="copyUrl('simpleWebhookUrl')">📋 Copy</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<a href="https://dashboard.stripe.com/test/webhooks" target="_blank" class="stripe-dashboard-link">
|
|
||||||
🔗 Open Stripe Dashboard
|
|
||||||
</a>
|
|
||||||
|
|
||||||
<div class="status-grid">
|
|
||||||
<div class="status-item">
|
|
||||||
<div class="status-value" id="stripeEvents">0</div>
|
|
||||||
<div>Stripe Events</div>
|
|
||||||
</div>
|
|
||||||
<div class="status-item">
|
|
||||||
<div class="status-value" id="testEvents">0</div>
|
|
||||||
<div>Test Events</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test-buttons">
|
|
||||||
<button class="test-btn" onclick="testStripeWebhook()">🧪 Test Stripe Endpoint</button>
|
|
||||||
<button class="test-btn" onclick="testSimpleWebhook()">📡 Test Simple Endpoint</button>
|
|
||||||
<button class="test-btn" onclick="refreshLogs()">🔄 Refresh</button>
|
|
||||||
<button class="test-btn" onclick="clearLogs()">🗑️ Clear</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Payment Testing -->
|
|
||||||
<div class="test-card">
|
|
||||||
<h2 class="test-title">
|
|
||||||
💳 Payment Testing
|
|
||||||
<div class="status-indicator" id="paymentStatus"></div>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div class="instructions">
|
|
||||||
<strong>💡 Test Payment Flow:</strong><br>
|
|
||||||
1. Click "Create Test Payment"<br>
|
|
||||||
2. Use test card: 4242 4242 4242 4242<br>
|
|
||||||
3. Watch for webhook events in logs<br>
|
|
||||||
4. Check if Stripe delivers the webhook
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test-buttons">
|
|
||||||
<button class="test-btn primary" onclick="createTestPayment(10)">💳 Pay 10 AED</button>
|
|
||||||
<button class="test-btn primary" onclick="createTestPayment(50)">💳 Pay 50 AED</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="paymentInfo" style="display: none; margin-top: 15px; padding: 15px; background: #e3f2fd; border-radius: 8px; font-size: 13px;">
|
|
||||||
<strong>Payment Link Created:</strong><br>
|
|
||||||
<a href="#" id="paymentLink" target="_blank" style="color: var(--primary-blue); font-weight: 600;">🔗 Complete Payment</a>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3 style="margin-top: 25px;">📊 Webhook Activity</h3>
|
|
||||||
<div class="webhook-logs" id="webhookLogs">
|
|
||||||
<button class="clear-logs" onclick="clearLogs()">Clear</button>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INIT]</span> Webhook monitoring started...
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-success">
|
|
||||||
<span class="log-timestamp">[READY]</span> Waiting for Stripe events...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let pollingInterval = null;
|
|
||||||
let stripeEventCount = 0;
|
|
||||||
let testEventCount = 0;
|
|
||||||
|
|
||||||
// Initialize
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
startPolling();
|
|
||||||
updateConfigStatus(true);
|
|
||||||
logMessage('Stripe webhook testing initialized', 'success');
|
|
||||||
});
|
|
||||||
|
|
||||||
function copyUrl(elementId) {
|
|
||||||
const url = document.getElementById(elementId).textContent;
|
|
||||||
navigator.clipboard.writeText(url).then(() => {
|
|
||||||
logMessage(`URL copied: ${url}`, 'success');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function testStripeWebhook() {
|
|
||||||
logMessage('Testing Stripe webhook endpoint...', 'info');
|
|
||||||
|
|
||||||
fetch('/stripe/webhook/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Test-Source': 'webhook-test-page'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
test: true,
|
|
||||||
type: 'test_webhook',
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
logMessage(`Stripe endpoint response: ${JSON.stringify(data)}`, 'success');
|
|
||||||
testEventCount++;
|
|
||||||
updateEventCounts();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Stripe endpoint error: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function testSimpleWebhook() {
|
|
||||||
logMessage('Testing simple webhook endpoint...', 'info');
|
|
||||||
|
|
||||||
fetch('/simple-webhook-test/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Test-Source': 'webhook-test-page'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
test: true,
|
|
||||||
type: 'simple_test',
|
|
||||||
timestamp: new Date().toISOString()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(data => {
|
|
||||||
logMessage(`Simple endpoint response: ${data}`, 'success');
|
|
||||||
testEventCount++;
|
|
||||||
updateEventCounts();
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Simple endpoint error: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTestPayment(amount) {
|
|
||||||
logMessage(`Creating test payment for ${amount} AED...`, 'info');
|
|
||||||
|
|
||||||
fetch('/wallet/demo/test-payment/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRFToken': getCsrfToken()
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ amount: amount })
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
document.getElementById('paymentLink').href = data.payment_url;
|
|
||||||
document.getElementById('paymentInfo').style.display = 'block';
|
|
||||||
logMessage(`Payment created: ${data.session_id}`, 'success');
|
|
||||||
logMessage('Complete payment to trigger webhook...', 'info');
|
|
||||||
updatePaymentStatus(true);
|
|
||||||
} else {
|
|
||||||
logMessage(`Payment creation failed: ${data.error}`, 'error');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Payment error: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshLogs() {
|
|
||||||
logMessage('Refreshing webhook logs...', 'info');
|
|
||||||
|
|
||||||
fetch('/webhook-logs/')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
displayLogs(data.logs);
|
|
||||||
logMessage(`Logs refreshed - ${data.logs.length} total entries`, 'success');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Log refresh error: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayLogs(logs) {
|
|
||||||
const container = document.getElementById('webhookLogs');
|
|
||||||
|
|
||||||
// Keep clear button and initial messages
|
|
||||||
const existingContent = container.innerHTML.split('<div class="log-entry')[0];
|
|
||||||
container.innerHTML = existingContent;
|
|
||||||
|
|
||||||
// Reset counters
|
|
||||||
stripeEventCount = 0;
|
|
||||||
testEventCount = 0;
|
|
||||||
|
|
||||||
if (logs.length === 0) {
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = 'log-entry log-info';
|
|
||||||
entry.innerHTML = '<span class="log-timestamp">[INFO]</span> No webhook events received yet';
|
|
||||||
container.appendChild(entry);
|
|
||||||
} else {
|
|
||||||
logs.forEach(log => {
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
const isStripe = log.source === 'stripe_webhook' ||
|
|
||||||
(log.headers && log.headers['HTTP_USER_AGENT'] && log.headers['HTTP_USER_AGENT'].includes('Stripe'));
|
|
||||||
|
|
||||||
if (isStripe) {
|
|
||||||
entry.className = 'log-entry log-success log-stripe';
|
|
||||||
stripeEventCount++;
|
|
||||||
} else {
|
|
||||||
entry.className = 'log-entry log-info log-test';
|
|
||||||
testEventCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
const source = isStripe ? '[STRIPE]' : '[TEST]';
|
|
||||||
const bodyPreview = log.body ?
|
|
||||||
(log.body.length > 80 ? log.body.substring(0, 80) + '...' : log.body) :
|
|
||||||
'empty';
|
|
||||||
const ip = log.ip_address || 'unknown';
|
|
||||||
|
|
||||||
entry.innerHTML = `
|
|
||||||
<span class="log-timestamp">[${log.timestamp}]</span>
|
|
||||||
${source} ${log.method} from ${ip}<br>
|
|
||||||
<small style="color: #aaa; margin-left: 60px;">Body: ${bodyPreview}</small>
|
|
||||||
`;
|
|
||||||
container.appendChild(entry);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateEventCounts();
|
|
||||||
container.scrollTop = container.scrollHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearLogs() {
|
|
||||||
const container = document.getElementById('webhookLogs');
|
|
||||||
container.innerHTML = `
|
|
||||||
<button class="clear-logs" onclick="clearLogs()">Clear</button>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INIT]</span> Webhook monitoring started...
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-success">
|
|
||||||
<span class="log-timestamp">[READY]</span> Waiting for Stripe events...
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
stripeEventCount = 0;
|
|
||||||
testEventCount = 0;
|
|
||||||
updateEventCounts();
|
|
||||||
logMessage('Logs cleared', 'info');
|
|
||||||
}
|
|
||||||
|
|
||||||
function startPolling() {
|
|
||||||
pollingInterval = setInterval(refreshLogs, 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateConfigStatus(status) {
|
|
||||||
const indicator = document.getElementById('configStatus');
|
|
||||||
if (status) {
|
|
||||||
indicator.classList.add('connected');
|
|
||||||
} else {
|
|
||||||
indicator.classList.remove('connected');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updatePaymentStatus(status) {
|
|
||||||
const indicator = document.getElementById('paymentStatus');
|
|
||||||
if (status) {
|
|
||||||
indicator.classList.add('connected');
|
|
||||||
} else {
|
|
||||||
indicator.classList.remove('connected');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateEventCounts() {
|
|
||||||
document.getElementById('stripeEvents').textContent = stripeEventCount;
|
|
||||||
document.getElementById('testEvents').textContent = testEventCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
function logMessage(message, type = 'info') {
|
|
||||||
const container = document.getElementById('webhookLogs');
|
|
||||||
const timestamp = new Date().toLocaleTimeString();
|
|
||||||
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = `log-entry log-${type}`;
|
|
||||||
entry.innerHTML = `<span class="log-timestamp">[${timestamp}]</span> ${message}`;
|
|
||||||
|
|
||||||
container.appendChild(entry);
|
|
||||||
container.scrollTop = container.scrollHeight;
|
|
||||||
|
|
||||||
// Keep only last 50 entries
|
|
||||||
while (container.children.length > 52) {
|
|
||||||
container.removeChild(container.children[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getCsrfToken() {
|
|
||||||
const cookies = document.cookie.split(';');
|
|
||||||
for (let cookie of cookies) {
|
|
||||||
const [name, value] = cookie.trim().split('=');
|
|
||||||
if (name === 'csrftoken') {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
window.addEventListener('beforeunload', function() {
|
|
||||||
if (pollingInterval) {
|
|
||||||
clearInterval(pollingInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@ -1,502 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
{% load static %}
|
|
||||||
|
|
||||||
{% block title %}Wallet Demo - Stripe Webhook Testing{% endblock %}
|
|
||||||
|
|
||||||
{% block extra_css %}
|
|
||||||
<style>
|
|
||||||
.demo-page {
|
|
||||||
background: var(--gradient-hero);
|
|
||||||
min-height: calc(100vh - 80px);
|
|
||||||
padding: clamp(20px, 5vw, 40px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.demo-container {
|
|
||||||
max-width: 1200px;
|
|
||||||
margin: 0 auto;
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 24px;
|
|
||||||
align-items: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.demo-card {
|
|
||||||
background: rgba(255, 255, 255, 0.95);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 24px;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.demo-title {
|
|
||||||
font-size: 24px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--text-primary);
|
|
||||||
margin-bottom: 20px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-indicator {
|
|
||||||
width: 12px;
|
|
||||||
height: 12px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: #e74c3c;
|
|
||||||
animation: pulse 2s infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-indicator.connected {
|
|
||||||
background: #27ae60;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse {
|
|
||||||
0% { opacity: 1; }
|
|
||||||
50% { opacity: 0.5; }
|
|
||||||
100% { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.balance-display {
|
|
||||||
font-size: 36px;
|
|
||||||
font-weight: 800;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
text-align: center;
|
|
||||||
margin: 20px 0;
|
|
||||||
padding: 20px;
|
|
||||||
background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
|
|
||||||
border-radius: 12px;
|
|
||||||
border: 2px solid var(--border-light);
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-info {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: 1fr 1fr;
|
|
||||||
gap: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
padding: 15px;
|
|
||||||
background: #f8fafc;
|
|
||||||
border-radius: 8px;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.user-info strong {
|
|
||||||
color: var(--text-primary);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-amounts {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(2, 1fr);
|
|
||||||
gap: 12px;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount-btn {
|
|
||||||
padding: 12px 20px;
|
|
||||||
border: 2px solid var(--primary-blue);
|
|
||||||
background: transparent;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
border-radius: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount-btn:hover {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.amount-btn:disabled {
|
|
||||||
opacity: 0.5;
|
|
||||||
cursor: not-allowed;
|
|
||||||
}
|
|
||||||
|
|
||||||
.control-buttons {
|
|
||||||
display: flex;
|
|
||||||
gap: 12px;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary {
|
|
||||||
flex: 1;
|
|
||||||
padding: 12px 24px;
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-primary:hover {
|
|
||||||
background: var(--primary-dark);
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-secondary {
|
|
||||||
flex: 1;
|
|
||||||
padding: 12px 24px;
|
|
||||||
background: transparent;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
border: 2px solid var(--primary-blue);
|
|
||||||
border-radius: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn-secondary:hover {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-log {
|
|
||||||
max-height: 300px;
|
|
||||||
overflow-y: auto;
|
|
||||||
background: #f8fafc;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-item {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
padding: 8px 0;
|
|
||||||
border-bottom: 1px solid #e2e8f0;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-item:last-child {
|
|
||||||
border-bottom: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-amount {
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-amount.positive {
|
|
||||||
color: #27ae60;
|
|
||||||
}
|
|
||||||
|
|
||||||
.transaction-amount.negative {
|
|
||||||
color: #e74c3c;
|
|
||||||
}
|
|
||||||
|
|
||||||
.webhook-logs {
|
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: auto;
|
|
||||||
background: #1a1a1a;
|
|
||||||
color: #00ff00;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 12px;
|
|
||||||
line-height: 1.4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-entry {
|
|
||||||
margin: 2px 0;
|
|
||||||
padding: 2px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-timestamp {
|
|
||||||
color: #888;
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-success {
|
|
||||||
color: #00ff00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-error {
|
|
||||||
color: #ff6b6b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-info {
|
|
||||||
color: #74c0fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.selected-amount {
|
|
||||||
background: var(--primary-blue) !important;
|
|
||||||
color: white !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
|
||||||
.demo-container {
|
|
||||||
grid-template-columns: 1fr;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-amounts {
|
|
||||||
grid-template-columns: repeat(2, 1fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
.control-buttons {
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="demo-page">
|
|
||||||
<div class="demo-container">
|
|
||||||
<!-- Payment Testing Panel -->
|
|
||||||
<div class="demo-card">
|
|
||||||
<h2 class="demo-title">
|
|
||||||
🧪 Payment Testing
|
|
||||||
<div class="status-indicator" id="paymentStatus"></div>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<div class="balance-display" id="currentBalance">
|
|
||||||
{{ current_balance|floatformat:2 }} AED
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="user-info">
|
|
||||||
<div><strong>User ID:</strong> {{ user_id }}</div>
|
|
||||||
<div><strong>Email:</strong> {{ user_email }}</div>
|
|
||||||
<div><strong>Environment:</strong> Railway</div>
|
|
||||||
<div><strong>Webhook:</strong> Active</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3>Test Amounts</h3>
|
|
||||||
<div class="test-amounts">
|
|
||||||
<button class="amount-btn" data-amount="10">10 AED</button>
|
|
||||||
<button class="amount-btn" data-amount="50">50 AED</button>
|
|
||||||
<button class="amount-btn" data-amount="100">100 AED</button>
|
|
||||||
<button class="amount-btn" data-amount="500">500 AED</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="control-buttons">
|
|
||||||
<button class="btn-primary" id="createPayment" disabled>
|
|
||||||
💳 Create Test Payment
|
|
||||||
</button>
|
|
||||||
<button class="btn-secondary" id="refreshBalance">
|
|
||||||
🔄 Refresh Balance
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div id="paymentInfo" style="display: none; margin-top: 15px; padding: 15px; background: #e3f2fd; border-radius: 8px; font-size: 14px;">
|
|
||||||
<strong>Payment Created:</strong><br>
|
|
||||||
<span id="sessionId"></span><br>
|
|
||||||
<a href="#" id="paymentLink" target="_blank" style="color: var(--primary-blue); font-weight: 600;">🔗 Complete Payment</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Webhook Monitoring Panel -->
|
|
||||||
<div class="demo-card">
|
|
||||||
<h2 class="demo-title">
|
|
||||||
📡 Webhook Monitor
|
|
||||||
<div class="status-indicator" id="webhookStatus"></div>
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<h3>Recent Transactions</h3>
|
|
||||||
<div class="transaction-log" id="transactionLog">
|
|
||||||
{% for transaction in recent_transactions %}
|
|
||||||
<div class="transaction-item">
|
|
||||||
<div>
|
|
||||||
<div>{{ transaction.description|default:"Wallet Transaction" }}</div>
|
|
||||||
<div style="font-size: 12px; color: #666;">{{ transaction.created_at|date:"M d, H:i" }}</div>
|
|
||||||
</div>
|
|
||||||
<div class="transaction-amount {% if transaction.amount >= 0 %}positive{% else %}negative{% endif %}">
|
|
||||||
{% if transaction.amount >= 0 %}+{% endif %}{{ transaction.amount|floatformat:2 }} AED
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% empty %}
|
|
||||||
<div style="text-align: center; color: #666; padding: 20px;">
|
|
||||||
No transactions yet. Create a test payment to see webhook activity.
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<h3>Webhook Logs</h3>
|
|
||||||
<div class="webhook-logs" id="webhookLogs">
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INIT]</span> Webhook monitoring started...
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INFO]</span> Endpoint: https://netcop.up.railway.app/stripe/webhook/
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INFO]</span> Waiting for webhook events...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Include CSRF token for AJAX requests -->
|
|
||||||
{% csrf_token %}
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let selectedAmount = null;
|
|
||||||
let pollingInterval = null;
|
|
||||||
|
|
||||||
// Get CSRF token
|
|
||||||
const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;
|
|
||||||
|
|
||||||
// Initialize page
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
setupEventListeners();
|
|
||||||
startPolling();
|
|
||||||
updateStatus('webhook', true);
|
|
||||||
logMessage('System initialized successfully', 'success');
|
|
||||||
});
|
|
||||||
|
|
||||||
function setupEventListeners() {
|
|
||||||
// Amount button selection
|
|
||||||
document.querySelectorAll('.amount-btn').forEach(btn => {
|
|
||||||
btn.addEventListener('click', function() {
|
|
||||||
selectedAmount = parseFloat(this.dataset.amount);
|
|
||||||
|
|
||||||
// Update UI
|
|
||||||
document.querySelectorAll('.amount-btn').forEach(b => b.classList.remove('selected-amount'));
|
|
||||||
this.classList.add('selected-amount');
|
|
||||||
document.getElementById('createPayment').disabled = false;
|
|
||||||
|
|
||||||
logMessage(`Selected amount: ${selectedAmount} AED`, 'info');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Create payment button
|
|
||||||
document.getElementById('createPayment').addEventListener('click', createTestPayment);
|
|
||||||
|
|
||||||
// Refresh balance button
|
|
||||||
document.getElementById('refreshBalance').addEventListener('click', refreshBalance);
|
|
||||||
}
|
|
||||||
|
|
||||||
function createTestPayment() {
|
|
||||||
if (!selectedAmount) {
|
|
||||||
logMessage('Please select an amount first', 'error');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const btn = document.getElementById('createPayment');
|
|
||||||
btn.disabled = true;
|
|
||||||
btn.textContent = '⏳ Creating Payment...';
|
|
||||||
|
|
||||||
logMessage(`Creating payment session for ${selectedAmount} AED...`, 'info');
|
|
||||||
|
|
||||||
fetch('/wallet/demo/test-payment/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-CSRFToken': csrfToken
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ amount: selectedAmount })
|
|
||||||
})
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
if (data.success) {
|
|
||||||
document.getElementById('sessionId').textContent = data.session_id;
|
|
||||||
document.getElementById('paymentLink').href = data.payment_url;
|
|
||||||
document.getElementById('paymentInfo').style.display = 'block';
|
|
||||||
|
|
||||||
logMessage(`Payment session created: ${data.session_id}`, 'success');
|
|
||||||
logMessage(`User ID in session: ${data.user_id}`, 'info');
|
|
||||||
logMessage('Complete payment to test webhook...', 'info');
|
|
||||||
|
|
||||||
updateStatus('payment', true);
|
|
||||||
} else {
|
|
||||||
logMessage(`Payment creation failed: ${data.error}`, 'error');
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Error: ${error.message}`, 'error');
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
btn.disabled = false;
|
|
||||||
btn.textContent = '💳 Create Test Payment';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshBalance() {
|
|
||||||
logMessage('Refreshing balance...', 'info');
|
|
||||||
|
|
||||||
fetch('/wallet/demo/check-balance/')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
document.getElementById('currentBalance').textContent = `${data.balance.toFixed(2)} AED`;
|
|
||||||
updateTransactionLog(data.recent_transactions);
|
|
||||||
logMessage(`Balance updated: ${data.balance.toFixed(2)} AED`, 'success');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Error refreshing balance: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateTransactionLog(transactions) {
|
|
||||||
const log = document.getElementById('transactionLog');
|
|
||||||
log.innerHTML = '';
|
|
||||||
|
|
||||||
if (transactions.length === 0) {
|
|
||||||
log.innerHTML = '<div style="text-align: center; color: #666; padding: 20px;">No transactions yet.</div>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
transactions.forEach(transaction => {
|
|
||||||
const item = document.createElement('div');
|
|
||||||
item.className = 'transaction-item';
|
|
||||||
|
|
||||||
const date = new Date(transaction.created_at).toLocaleString();
|
|
||||||
const amountClass = transaction.amount >= 0 ? 'positive' : 'negative';
|
|
||||||
const amountPrefix = transaction.amount >= 0 ? '+' : '';
|
|
||||||
|
|
||||||
item.innerHTML = `
|
|
||||||
<div>
|
|
||||||
<div>${transaction.description || 'Wallet Transaction'}</div>
|
|
||||||
<div style="font-size: 12px; color: #666;">${date}</div>
|
|
||||||
</div>
|
|
||||||
<div class="transaction-amount ${amountClass}">
|
|
||||||
${amountPrefix}${transaction.amount.toFixed(2)} AED
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
log.appendChild(item);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function startPolling() {
|
|
||||||
// Poll for balance changes every 5 seconds
|
|
||||||
pollingInterval = setInterval(refreshBalance, 5000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateStatus(type, connected) {
|
|
||||||
const indicator = document.getElementById(type + 'Status');
|
|
||||||
if (connected) {
|
|
||||||
indicator.classList.add('connected');
|
|
||||||
} else {
|
|
||||||
indicator.classList.remove('connected');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function logMessage(message, type = 'info') {
|
|
||||||
const logs = document.getElementById('webhookLogs');
|
|
||||||
const timestamp = new Date().toLocaleTimeString();
|
|
||||||
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = `log-entry log-${type}`;
|
|
||||||
entry.innerHTML = `<span class="log-timestamp">[${timestamp}]</span> ${message}`;
|
|
||||||
|
|
||||||
logs.appendChild(entry);
|
|
||||||
logs.scrollTop = logs.scrollHeight;
|
|
||||||
|
|
||||||
// Keep only last 50 log entries
|
|
||||||
while (logs.children.length > 50) {
|
|
||||||
logs.removeChild(logs.firstChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup on page unload
|
|
||||||
window.addEventListener('beforeunload', function() {
|
|
||||||
if (pollingInterval) {
|
|
||||||
clearInterval(pollingInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@ -1,450 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
{% load static %}
|
|
||||||
|
|
||||||
{% block title %}Simple Webhook Test{% endblock %}
|
|
||||||
|
|
||||||
{% block extra_css %}
|
|
||||||
<style>
|
|
||||||
.test-page {
|
|
||||||
background: var(--gradient-hero);
|
|
||||||
min-height: calc(100vh - 80px);
|
|
||||||
padding: clamp(20px, 5vw, 40px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-container {
|
|
||||||
max-width: 900px;
|
|
||||||
margin: 0 auto;
|
|
||||||
background: rgba(255, 255, 255, 0.95);
|
|
||||||
border-radius: 16px;
|
|
||||||
padding: 30px;
|
|
||||||
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
||||||
backdrop-filter: blur(20px);
|
|
||||||
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-title {
|
|
||||||
font-size: 28px;
|
|
||||||
font-weight: 700;
|
|
||||||
color: var(--text-primary);
|
|
||||||
margin-bottom: 20px;
|
|
||||||
text-align: center;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.webhook-url {
|
|
||||||
background: #f8fafc;
|
|
||||||
border: 2px solid #e2e8f0;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 14px;
|
|
||||||
word-break: break-all;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.copy-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 10px;
|
|
||||||
right: 10px;
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
font-size: 12px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-buttons {
|
|
||||||
display: flex;
|
|
||||||
gap: 15px;
|
|
||||||
margin: 25px 0;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn {
|
|
||||||
flex: 1;
|
|
||||||
min-width: 150px;
|
|
||||||
padding: 12px 20px;
|
|
||||||
border: 2px solid var(--primary-blue);
|
|
||||||
background: transparent;
|
|
||||||
color: var(--primary-blue);
|
|
||||||
border-radius: 8px;
|
|
||||||
font-weight: 600;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: all 0.2s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn:hover {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn.primary {
|
|
||||||
background: var(--primary-blue);
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.test-btn.primary:hover {
|
|
||||||
background: var(--primary-dark);
|
|
||||||
}
|
|
||||||
|
|
||||||
.logs-container {
|
|
||||||
background: #1a1a1a;
|
|
||||||
color: #00ff00;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 20px;
|
|
||||||
margin: 20px 0;
|
|
||||||
font-family: 'Courier New', monospace;
|
|
||||||
font-size: 13px;
|
|
||||||
line-height: 1.5;
|
|
||||||
max-height: 400px;
|
|
||||||
overflow-y: auto;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-entry {
|
|
||||||
margin: 3px 0;
|
|
||||||
padding: 2px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-timestamp {
|
|
||||||
color: #888;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-method {
|
|
||||||
color: #74c0fc;
|
|
||||||
font-weight: bold;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-success {
|
|
||||||
color: #00ff00;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-error {
|
|
||||||
color: #ff6b6b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-info {
|
|
||||||
color: #74c0fc;
|
|
||||||
}
|
|
||||||
|
|
||||||
.log-warning {
|
|
||||||
color: #ffd43b;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-bar {
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
background: #f8fafc;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-item {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-dot {
|
|
||||||
width: 10px;
|
|
||||||
height: 10px;
|
|
||||||
border-radius: 50%;
|
|
||||||
background: #e74c3c;
|
|
||||||
animation: pulse 2s infinite;
|
|
||||||
}
|
|
||||||
|
|
||||||
.status-dot.active {
|
|
||||||
background: #27ae60;
|
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes pulse {
|
|
||||||
0% { opacity: 1; }
|
|
||||||
50% { opacity: 0.5; }
|
|
||||||
100% { opacity: 1; }
|
|
||||||
}
|
|
||||||
|
|
||||||
.info-section {
|
|
||||||
background: #e3f2fd;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 15px;
|
|
||||||
margin: 20px 0;
|
|
||||||
font-size: 14px;
|
|
||||||
line-height: 1.6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clear-logs {
|
|
||||||
position: absolute;
|
|
||||||
top: 10px;
|
|
||||||
right: 10px;
|
|
||||||
background: #444;
|
|
||||||
color: #fff;
|
|
||||||
border: none;
|
|
||||||
border-radius: 4px;
|
|
||||||
padding: 5px 10px;
|
|
||||||
font-size: 11px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.clear-logs:hover {
|
|
||||||
background: #666;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div class="test-page">
|
|
||||||
<div class="test-container">
|
|
||||||
<h1 class="test-title">
|
|
||||||
🧪 Simple Webhook Test
|
|
||||||
<div class="status-dot" id="statusDot"></div>
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<div class="info-section">
|
|
||||||
<strong>💡 How to use:</strong><br>
|
|
||||||
1. Copy the webhook URL below<br>
|
|
||||||
2. Use it in Stripe dashboard or any webhook testing tool<br>
|
|
||||||
3. Send test webhooks and watch the logs below<br>
|
|
||||||
4. This endpoint accepts any HTTP method and logs all details
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="webhook-url">
|
|
||||||
<strong>Webhook Test URL:</strong><br>
|
|
||||||
<span id="webhookUrl">https://netcop.up.railway.app/simple-webhook-test/</span>
|
|
||||||
<button class="copy-btn" onclick="copyWebhookUrl()">📋 Copy</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="status-bar">
|
|
||||||
<div class="status-item">
|
|
||||||
<div class="status-dot active" id="endpointStatus"></div>
|
|
||||||
<span>Endpoint: Active</span>
|
|
||||||
</div>
|
|
||||||
<div class="status-item">
|
|
||||||
<div class="status-dot" id="webhookStatus"></div>
|
|
||||||
<span id="webhookStatusText">Waiting for webhooks...</span>
|
|
||||||
</div>
|
|
||||||
<div class="status-item">
|
|
||||||
<span>Logs: <span id="logCount">0</span></span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="test-buttons">
|
|
||||||
<button class="test-btn primary" onclick="sendTestWebhook()">📡 Send Test Webhook</button>
|
|
||||||
<button class="test-btn" onclick="refreshLogs()">🔄 Refresh Logs</button>
|
|
||||||
<button class="test-btn" onclick="clearLogs()">🗑️ Clear Logs</button>
|
|
||||||
<button class="test-btn" onclick="exportLogs()">💾 Export Logs</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="logs-container" id="logsContainer">
|
|
||||||
<button class="clear-logs" onclick="clearLogs()">Clear</button>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INIT]</span> Webhook test endpoint initialized
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-success">
|
|
||||||
<span class="log-timestamp">[READY]</span> Listening for webhook events...
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
let pollingInterval = null;
|
|
||||||
let logCount = 0;
|
|
||||||
|
|
||||||
// Initialize
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
|
||||||
startPolling();
|
|
||||||
updateWebhookUrl();
|
|
||||||
logMessage('System ready for webhook testing', 'success');
|
|
||||||
});
|
|
||||||
|
|
||||||
function updateWebhookUrl() {
|
|
||||||
const protocol = window.location.protocol;
|
|
||||||
const host = window.location.host;
|
|
||||||
const url = `${protocol}//${host}/simple-webhook-test/`;
|
|
||||||
document.getElementById('webhookUrl').textContent = url;
|
|
||||||
}
|
|
||||||
|
|
||||||
function copyWebhookUrl() {
|
|
||||||
const url = document.getElementById('webhookUrl').textContent;
|
|
||||||
navigator.clipboard.writeText(url).then(() => {
|
|
||||||
logMessage('Webhook URL copied to clipboard', 'success');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendTestWebhook() {
|
|
||||||
const url = document.getElementById('webhookUrl').textContent;
|
|
||||||
logMessage('Sending test POST request to webhook endpoint...', 'info');
|
|
||||||
|
|
||||||
fetch('/simple-webhook-test/', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
'X-Test-Header': 'webhook-test'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
test: true,
|
|
||||||
timestamp: new Date().toISOString(),
|
|
||||||
source: 'webhook-test-page'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.then(response => response.text())
|
|
||||||
.then(data => {
|
|
||||||
logMessage(`Test webhook sent successfully: ${data}`, 'success');
|
|
||||||
updateWebhookStatus(true);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Test webhook failed: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function refreshLogs() {
|
|
||||||
logMessage('Refreshing webhook logs...', 'info');
|
|
||||||
|
|
||||||
fetch('/webhook-logs/')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
displayLogs(data.logs);
|
|
||||||
logMessage(`Logs refreshed - ${data.logs.length} entries`, 'success');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Failed to refresh logs: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayLogs(logs) {
|
|
||||||
const container = document.getElementById('logsContainer');
|
|
||||||
|
|
||||||
// Keep the clear button and initial messages
|
|
||||||
const existingContent = container.innerHTML.split('<div class="log-entry')[0];
|
|
||||||
container.innerHTML = existingContent;
|
|
||||||
|
|
||||||
if (logs.length === 0) {
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = 'log-entry log-info';
|
|
||||||
entry.innerHTML = '<span class="log-timestamp">[INFO]</span> No webhook events received yet';
|
|
||||||
container.appendChild(entry);
|
|
||||||
} else {
|
|
||||||
logs.forEach(log => {
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = 'log-entry log-success';
|
|
||||||
|
|
||||||
const bodyPreview = log.body ?
|
|
||||||
(log.body.length > 100 ? log.body.substring(0, 100) + '...' : log.body) :
|
|
||||||
'no body';
|
|
||||||
|
|
||||||
entry.innerHTML = `
|
|
||||||
<span class="log-timestamp">[${log.timestamp}]</span>
|
|
||||||
<span class="log-method">${log.method}</span>
|
|
||||||
${log.content_type} - Body: ${bodyPreview}
|
|
||||||
`;
|
|
||||||
container.appendChild(entry);
|
|
||||||
});
|
|
||||||
|
|
||||||
updateWebhookStatus(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update log count
|
|
||||||
logCount = logs.length;
|
|
||||||
document.getElementById('logCount').textContent = logCount;
|
|
||||||
|
|
||||||
// Scroll to bottom
|
|
||||||
container.scrollTop = container.scrollHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearLogs() {
|
|
||||||
const container = document.getElementById('logsContainer');
|
|
||||||
|
|
||||||
// Reset to initial state
|
|
||||||
container.innerHTML = `
|
|
||||||
<button class="clear-logs" onclick="clearLogs()">Clear</button>
|
|
||||||
<div class="log-entry log-info">
|
|
||||||
<span class="log-timestamp">[INIT]</span> Webhook test endpoint initialized
|
|
||||||
</div>
|
|
||||||
<div class="log-entry log-success">
|
|
||||||
<span class="log-timestamp">[READY]</span> Listening for webhook events...
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
logCount = 0;
|
|
||||||
document.getElementById('logCount').textContent = logCount;
|
|
||||||
updateWebhookStatus(false);
|
|
||||||
|
|
||||||
logMessage('Logs cleared', 'info');
|
|
||||||
}
|
|
||||||
|
|
||||||
function exportLogs() {
|
|
||||||
fetch('/webhook-logs/')
|
|
||||||
.then(response => response.json())
|
|
||||||
.then(data => {
|
|
||||||
const blob = new Blob([JSON.stringify(data.logs, null, 2)], {
|
|
||||||
type: 'application/json'
|
|
||||||
});
|
|
||||||
const url = URL.createObjectURL(blob);
|
|
||||||
const a = document.createElement('a');
|
|
||||||
a.href = url;
|
|
||||||
a.download = `webhook-logs-${new Date().toISOString().split('T')[0]}.json`;
|
|
||||||
a.click();
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
|
|
||||||
logMessage('Logs exported successfully', 'success');
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
logMessage(`Export failed: ${error.message}`, 'error');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function startPolling() {
|
|
||||||
// Poll for new logs every 3 seconds
|
|
||||||
pollingInterval = setInterval(refreshLogs, 3000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateWebhookStatus(received) {
|
|
||||||
const statusDot = document.getElementById('webhookStatus');
|
|
||||||
const statusText = document.getElementById('webhookStatusText');
|
|
||||||
|
|
||||||
if (received) {
|
|
||||||
statusDot.classList.add('active');
|
|
||||||
statusText.textContent = 'Webhooks received!';
|
|
||||||
} else {
|
|
||||||
statusDot.classList.remove('active');
|
|
||||||
statusText.textContent = 'Waiting for webhooks...';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function logMessage(message, type = 'info') {
|
|
||||||
const container = document.getElementById('logsContainer');
|
|
||||||
const timestamp = new Date().toLocaleTimeString();
|
|
||||||
|
|
||||||
const entry = document.createElement('div');
|
|
||||||
entry.className = `log-entry log-${type}`;
|
|
||||||
entry.innerHTML = `<span class="log-timestamp">[${timestamp}]</span> ${message}`;
|
|
||||||
|
|
||||||
container.appendChild(entry);
|
|
||||||
container.scrollTop = container.scrollHeight;
|
|
||||||
|
|
||||||
// Keep only last 100 entries
|
|
||||||
while (container.children.length > 102) { // +2 for clear button and initial messages
|
|
||||||
container.removeChild(container.children[1]); // Skip clear button
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup on page unload
|
|
||||||
window.addEventListener('beforeunload', function() {
|
|
||||||
if (pollingInterval) {
|
|
||||||
clearInterval(pollingInterval);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
|
||||||
@ -1,62 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""
|
|
||||||
Test external webhook accessibility
|
|
||||||
"""
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
def test_webhook_accessibility():
|
|
||||||
"""Test if Railway webhook endpoints are accessible externally"""
|
|
||||||
|
|
||||||
base_url = "https://netcop.up.railway.app"
|
|
||||||
|
|
||||||
endpoints = [
|
|
||||||
"/simple-webhook-test/",
|
|
||||||
"/stripe/webhook/",
|
|
||||||
]
|
|
||||||
|
|
||||||
print("🧪 Testing Railway webhook endpoint accessibility...")
|
|
||||||
print(f"📍 Base URL: {base_url}")
|
|
||||||
print("-" * 60)
|
|
||||||
|
|
||||||
for endpoint in endpoints:
|
|
||||||
url = base_url + endpoint
|
|
||||||
|
|
||||||
try:
|
|
||||||
print(f"\n🔍 Testing: {url}")
|
|
||||||
|
|
||||||
# Test with POST request
|
|
||||||
response = requests.post(
|
|
||||||
url,
|
|
||||||
json={
|
|
||||||
"test": True,
|
|
||||||
"source": "external_test_script",
|
|
||||||
"timestamp": datetime.now().isoformat()
|
|
||||||
},
|
|
||||||
headers={
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
"User-Agent": "WebhookTester/1.0",
|
|
||||||
"X-Test-Source": "external"
|
|
||||||
},
|
|
||||||
timeout=10
|
|
||||||
)
|
|
||||||
|
|
||||||
print(f"✅ Status: {response.status_code}")
|
|
||||||
print(f"✅ Response: {response.text[:200]}")
|
|
||||||
|
|
||||||
if response.status_code < 400:
|
|
||||||
print(f"✅ SUCCESS: {endpoint} is accessible")
|
|
||||||
else:
|
|
||||||
print(f"❌ FAILED: {endpoint} returned {response.status_code}")
|
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
print(f"❌ CONNECTION ERROR: {e}")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"❌ UNEXPECTED ERROR: {e}")
|
|
||||||
|
|
||||||
print("\n" + "=" * 60)
|
|
||||||
print("🏁 External accessibility test completed")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
test_webhook_accessibility()
|
|
||||||
Loading…
Reference in New Issue
Block a user