From b865fd4781773c5480c5f36d25c1dde9a62c9b59 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 12 Jul 2025 15:36:21 +0530 Subject: [PATCH] Create simple webhook testing page for debugging Stripe webhook delivery issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add webhook_test.html template with real-time webhook monitoring - Add simple_webhook_test endpoint that logs all incoming requests - Add webhook_logs endpoint to retrieve stored webhook data - Include copy webhook URL, test webhook, and export logs functionality - Enable live polling to monitor webhook events as they arrive ๐Ÿค– Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- core/urls.py | 3 + core/views.py | 46 +++- templates/core/webhook_test.html | 450 +++++++++++++++++++++++++++++++ 3 files changed, 498 insertions(+), 1 deletion(-) create mode 100644 templates/core/webhook_test.html diff --git a/core/urls.py b/core/urls.py index 538c5b3..f674355 100644 --- a/core/urls.py +++ b/core/urls.py @@ -16,5 +16,8 @@ urlpatterns = [ 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('webhook-test/', views.webhook_test_view, name='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 9279c64..617b6cb 100644 --- a/core/views.py +++ b/core/views.py @@ -1,7 +1,7 @@ from django.shortcuts import render, redirect, get_object_or_404 from django.contrib.auth.decorators import login_required from django.contrib import messages -from django.http import JsonResponse +from django.http import JsonResponse, HttpResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_http_methods from django.utils.decorators import method_decorator @@ -13,6 +13,7 @@ from agent_base.models import BaseAgent from wallet.stripe_handler import StripePaymentHandler from wallet.models import WalletTransaction import json +import datetime def homepage_view(request): @@ -221,6 +222,49 @@ def wallet_demo_check_balance(request): }) +# Simple webhook test page +def webhook_test_view(request): + """Simple HTML page for webhook testing""" + return render(request, 'core/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") + + +def get_webhook_logs(request): + """Get webhook logs for the test page""" + return JsonResponse({'logs': webhook_logs}) + + @csrf_exempt def stripe_webhook_view(request): """Handle Stripe webhook events""" diff --git a/templates/core/webhook_test.html b/templates/core/webhook_test.html new file mode 100644 index 0000000..64f5201 --- /dev/null +++ b/templates/core/webhook_test.html @@ -0,0 +1,450 @@ +{% 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