diff --git a/core/urls.py b/core/urls.py index 0aa055c..94da12d 100644 --- a/core/urls.py +++ b/core/urls.py @@ -12,14 +12,7 @@ urlpatterns = [ 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/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/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'), ] \ No newline at end of file diff --git a/core/views.py b/core/views.py index a63c45f..a205afc 100644 --- a/core/views.py +++ b/core/views.py @@ -172,122 +172,6 @@ def wallet_topup_cancel_view(request): 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 @@ -382,57 +266,6 @@ def stripe_debug_view(request): 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 diff --git a/templates/core/stripe_webhook_test.html b/templates/core/stripe_webhook_test.html deleted file mode 100644 index dc934ca..0000000 --- a/templates/core/stripe_webhook_test.html +++ /dev/null @@ -1,573 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block title %}Stripe Webhook Testing{% endblock %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-
- -
-

- โšก Stripe Webhook Config -
-

- -
- ๐Ÿ“‹ Setup Instructions:
- 1. Copy the webhook URL below
- 2. Go to Stripe Dashboard โ†’ Webhooks
- 3. Create new endpoint with this URL
- 4. Select "checkout.session.completed" event
- 5. Test with payment below -
- -
- Stripe Webhook URL:
- https://netcop.up.railway.app/stripe/webhook/ - -
- -
- Simple Test URL:
- https://netcop.up.railway.app/simple-webhook-test/ - -
- - - ๐Ÿ”— Open Stripe Dashboard - - -
-
-
0
-
Stripe Events
-
-
-
0
-
Test Events
-
-
- -
- - - - -
-
- - -
-

- ๐Ÿ’ณ Payment Testing -
-

- -
- ๐Ÿ’ก Test Payment Flow:
- 1. Click "Create Test Payment"
- 2. Use test card: 4242 4242 4242 4242
- 3. Watch for webhook events in logs
- 4. Check if Stripe delivers the webhook -
- -
- - -
- - - -

๐Ÿ“Š Webhook Activity

-
- -
- [INIT] Webhook monitoring started... -
-
- [READY] Waiting for Stripe events... -
-
-
-
-
- - -{% endblock %} \ No newline at end of file diff --git a/templates/core/wallet_demo.html b/templates/core/wallet_demo.html deleted file mode 100644 index deb4cd4..0000000 --- a/templates/core/wallet_demo.html +++ /dev/null @@ -1,502 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block title %}Wallet Demo - Stripe Webhook Testing{% endblock %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-
- -
-

- ๐Ÿงช Payment Testing -
-

- -
- {{ current_balance|floatformat:2 }} AED -
- - - -

Test Amounts

-
- - - - -
- -
- - -
- - -
- - -
-

- ๐Ÿ“ก Webhook Monitor -
-

- -

Recent Transactions

-
- {% for transaction in recent_transactions %} -
-
-
{{ transaction.description|default:"Wallet Transaction" }}
-
{{ transaction.created_at|date:"M d, H:i" }}
-
-
- {% if transaction.amount >= 0 %}+{% endif %}{{ transaction.amount|floatformat:2 }} AED -
-
- {% empty %} -
- No transactions yet. Create a test payment to see webhook activity. -
- {% endfor %} -
- -

Webhook Logs

-
-
- [INIT] Webhook monitoring started... -
-
- [INFO] Endpoint: https://netcop.up.railway.app/stripe/webhook/ -
-
- [INFO] Waiting for webhook events... -
-
-
-
-
- - -{% csrf_token %} - - -{% endblock %} \ No newline at end of file diff --git a/templates/core/webhook_test.html b/templates/core/webhook_test.html deleted file mode 100644 index 64f5201..0000000 --- a/templates/core/webhook_test.html +++ /dev/null @@ -1,450 +0,0 @@ -{% extends 'base.html' %} -{% load static %} - -{% block title %}Simple Webhook Test{% endblock %} - -{% block extra_css %} - -{% endblock %} - -{% block content %} -
-
-

- ๐Ÿงช Simple Webhook Test -
-

- -
- ๐Ÿ’ก How to use:
- 1. Copy the webhook URL below
- 2. Use it in Stripe dashboard or any webhook testing tool
- 3. Send test webhooks and watch the logs below
- 4. This endpoint accepts any HTTP method and logs all details -
- -
- Webhook Test URL:
- https://netcop.up.railway.app/simple-webhook-test/ - -
- -
-
-
- Endpoint: Active -
-
-
- Waiting for webhooks... -
-
- Logs: 0 -
-
- -
- - - - -
- -
- -
- [INIT] Webhook test endpoint initialized -
-
- [READY] Listening for webhook events... -
-
-
-
- - -{% endblock %} \ No newline at end of file diff --git a/test_webhook_external.py b/test_webhook_external.py deleted file mode 100644 index 425c396..0000000 --- a/test_webhook_external.py +++ /dev/null @@ -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() \ No newline at end of file