diff --git a/core/urls.py b/core/urls.py index f674355..fc681e0 100644 --- a/core/urls.py +++ b/core/urls.py @@ -17,6 +17,7 @@ urlpatterns = [ 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('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'), diff --git a/core/views.py b/core/views.py index 13907af..229b6dc 100644 --- a/core/views.py +++ b/core/views.py @@ -228,6 +228,11 @@ def webhook_test_view(request): 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 = [] @@ -272,9 +277,33 @@ def get_webhook_logs(request): @csrf_exempt def stripe_webhook_view(request): - """Handle Stripe webhook events""" - print(f"๐ŸŽฏ Stripe webhook received! Method: {request.method}") - print(f"๐ŸŽฏ Headers: {dict(request.META)}") + """Handle Stripe webhook events with comprehensive logging""" + timestamp = datetime.datetime.now().strftime("%H:%M:%S") + + # Log everything for debugging + print(f"๐ŸŽฏ [{timestamp}] Stripe webhook received!") + print(f"๐ŸŽฏ Method: {request.method}") + print(f"๐ŸŽฏ Content-Type: {request.content_type}") + print(f"๐ŸŽฏ Remote IP: {request.META.get('REMOTE_ADDR', 'unknown')}") + print(f"๐ŸŽฏ User Agent: {request.META.get('HTTP_USER_AGENT', 'unknown')}") + print(f"๐ŸŽฏ Full headers: {dict(request.META)}") + + # Store in webhook logs for the test page + webhook_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, + 'source': 'stripe_webhook', + 'ip_address': request.META.get('REMOTE_ADDR', 'unknown'), + 'user_agent': request.META.get('HTTP_USER_AGENT', 'unknown') + } + + # Add to webhook logs + webhook_logs.append(webhook_log_entry) + if len(webhook_logs) > 50: + webhook_logs.pop(0) if request.method != 'POST': print(f"โŒ Invalid method: {request.method}") @@ -284,9 +313,15 @@ def stripe_webhook_view(request): sig_header = request.META.get('HTTP_STRIPE_SIGNATURE') print(f"๐Ÿ“ฆ Payload length: {len(payload)} bytes") + print(f"๐Ÿ“ฆ Payload preview: {payload[:200]}...") print(f"๐Ÿ” Signature header: {sig_header is not None}") print(f"๐Ÿ” Full signature header: {sig_header}") + # Always return success first to see if Stripe is reaching us + if not sig_header: + print(f"โš ๏ธ No Stripe signature - might be a test request") + return JsonResponse({'status': 'received', 'message': 'No signature verification'}) + stripe_handler = StripePaymentHandler() result = stripe_handler.handle_webhook(payload, sig_header) diff --git a/templates/core/stripe_webhook_test.html b/templates/core/stripe_webhook_test.html new file mode 100644 index 0000000..dc934ca --- /dev/null +++ b/templates/core/stripe_webhook_test.html @@ -0,0 +1,573 @@ +{% 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