From 0714ec21e580b0bb749e577619740894c7fc2afe Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 12 Jul 2025 14:51:08 +0530 Subject: [PATCH] Add comprehensive Stripe webhook testing demo page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created /wallet/demo/ page for testing Stripe payment integration - Real-time balance monitoring and transaction logging - Interactive payment testing with amount selection - Live webhook status monitoring and debugging logs - AJAX-powered balance refresh and payment creation - Visual indicators for webhook connectivity status - Detailed session ID and payment link display This demo page will help debug webhook delivery issues and test the complete payment flow from session creation to balance updates. ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- core/urls.py | 3 + core/views.py | 74 ++++- templates/core/wallet_demo.html | 502 ++++++++++++++++++++++++++++++++ 3 files changed, 578 insertions(+), 1 deletion(-) create mode 100644 templates/core/wallet_demo.html diff --git a/core/urls.py b/core/urls.py index de2fc48..538c5b3 100644 --- a/core/urls.py +++ b/core/urls.py @@ -12,6 +12,9 @@ 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/webhook/', views.stripe_webhook_view, name='stripe_webhook'), 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 ca16627..99cd467 100644 --- a/core/views.py +++ b/core/views.py @@ -143,6 +143,78 @@ 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 = list(request.user.wallet_transactions.all()[:5].values( + 'amount', 'type', 'description', 'created_at', '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 + }) + + @csrf_exempt @require_http_methods(["POST"]) def stripe_webhook_view(request): @@ -193,4 +265,4 @@ def agents_api_view(request): return JsonResponse({ 'agents': agents_data, 'total_count': len(agents_data), - }) + }) \ No newline at end of file diff --git a/templates/core/wallet_demo.html b/templates/core/wallet_demo.html new file mode 100644 index 0000000..deb4cd4 --- /dev/null +++ b/templates/core/wallet_demo.html @@ -0,0 +1,502 @@ +{% 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