Skip to main content

Webhook Admin Panel

Django-CFG includes a built-in webhook administration panel in the payments app that automatically displays active ngrok URLs and webhook status.

Overviewโ€‹

The Webhook Admin Panel provides:

โœ… Real-time Ngrok Status - See if tunnel is active โœ… Automatic URL Display - Current public ngrok URL โœ… Per-Provider Webhook URLs - URLs for Stripe, NowPayments, Telegram, etc. โœ… Webhook Events Log - History of all received webhooks โœ… Testing Tools - Test webhook endpoints directly


Enabling the Panelโ€‹

1. Enable Payments Appโ€‹

# config.py
from django_cfg import DjangoConfig, NgrokConfig

class MyConfig(DjangoConfig):
project_name: str = "My Project"

# Enable payments app (includes webhook panel)
enable_payments: bool = True

# Enable ngrok
ngrok: NgrokConfig = NgrokConfig(enabled=True)

config = MyConfig()

2. Run Migrationsโ€‹

# Create payments app tables
python manage.py migrate

3. Start Server with Ngrokโ€‹

# Start Django with ngrok tunnel
python manage.py runserver_ngrok

# Output:
# โœ… Ngrok tunnel ready: https://abc123.ngrok.io
# Django development server is running at http://127.0.0.1:8000/
# Public URL: https://abc123.ngrok.io

4. Access Admin Panelโ€‹

Open your browser to:

http://localhost:8000/admin/payments/webhook/

Login with your admin credentials.


Panel Featuresโ€‹

The Webhook Dashboard provides comprehensive webhook monitoring and testing capabilities.

1. Recent Webhook Eventsโ€‹

Real-time event log with filtering:

Features:

  • ๐Ÿ“‹ Event List - All received webhook events (e.g., payment.created)
  • ๐ŸŽฏ Smart Filters - Filter by event type and status
  • ๐Ÿ” Event Details - View/retry individual events
  • ๐Ÿงน Clear All - Clear event history
  • โœ… Status Indicators - Green (success), Red (failed)

Event Display:

payment.created [success]
Invalid Date
[View] [Retry]

payment.created [failed]
Invalid Date
[View] [Retry]

2. Ngrok Tunnel Statusโ€‹

Live ngrok tunnel information:

Displays:

  • ๐ŸŸข Status Indicator - Visual "Active" status with green dot
  • ๐ŸŒ Public URL - https://eed65489ae77.ngrok-free.app with copy button
  • ๐Ÿ”— Webhook URL - https://eed65489ae77.ngrok-free.app/api with copy button
  • ๐Ÿ”„ Refresh - Update tunnel status
  • ๐Ÿš€ Open Tunnel - Open ngrok web interface

Copy URLs: Each URL has a copy button (๐Ÿ“‹) for quick clipboard access.

3. Webhook Statsโ€‹

Real-time webhook statistics:

MetricValueColor
Total Events6White
Successful5Green
Failed0Red
Success Rateundefined%White

Live Updates: Stats update automatically as new webhooks are received.

4. Test Webhookโ€‹

Built-in webhook testing tool:

Fields:

  • Webhook URL - Enter target webhook endpoint (pre-filled with ngrok URL)
  • Event Type - Select from dropdown (e.g., payment.created, payment.updated)
  • Send Test Webhook - Button to trigger test request

Example Usage:

Webhook URL: https://your-site.com/webhook
Event Type: [Select event type...]
[Send Test Webhook]

5. Quick Actionsโ€‹

Convenient action buttons:

  • ๐Ÿ” Retry Failed Events (Orange) - Automatically retry all failed webhook events
  • ๐Ÿ  Back to Dashboard (Blue) - Return to main payments dashboard

Using the Panelโ€‹

Viewing Webhook URLsโ€‹

# The panel automatically shows webhook URLs for all providers

# Access panel via Django admin:
# http://localhost:8000/admin/payments/webhook/

# The panel displays:
# - Current ngrok tunnel URL
# - Webhook URLs for each provider
# - Status of each webhook endpoint

Copying Webhook URLsโ€‹

Click the "Copy" button next to any webhook URL to copy it to clipboard:

Stripe Webhook URL:
https://abc123.ngrok.io/api/webhooks/stripe/
[Copy] [Test]

Testing Webhooksโ€‹

Use the "Test" button to send a test webhook to your endpoint:

# Click "Test" button
# Panel sends test POST request to webhook endpoint
# Displays response status and body

Test Request:
POST https://abc123.ngrok.io/api/webhooks/stripe/
Content-Type: application/json

{"event": "test", "timestamp": "2025-10-01T14:35:00Z"}

Response:
Status: 200 OK
Body: {"status": "success"}

API Referenceโ€‹

The webhook panel provides an API for programmatic access.

Get Webhook URLsโ€‹

# In your Django code:
from django_cfg.apps.payments.services.integrations import get_webhook_url_for_provider

# Get webhook URL for specific provider
stripe_webhook = get_webhook_url_for_provider("stripe")
# "https://abc123.ngrok.io/api/webhooks/stripe/"

nowpayments_webhook = get_webhook_url_for_provider("nowpayments")
# "https://abc123.ngrok.io/api/webhooks/nowpayments/"

telegram_webhook = get_webhook_url_for_provider("telegram")
# "https://abc123.ngrok.io/api/webhooks/telegram/"

Check Ngrok Statusโ€‹

from django_cfg.modules.django_ngrok import is_tunnel_active, get_tunnel_url

# Check if tunnel is active
if is_tunnel_active():
print(f"โœ… Tunnel active: {get_tunnel_url()}")
else:
print("โš ๏ธ Tunnel not active")

List All Webhook URLsโ€‹

from django_cfg.apps.payments.services.integrations.ngrok_service import get_all_webhook_urls

# Get dictionary of all webhook URLs
webhook_urls = get_all_webhook_urls()

# Returns:
# {
# "stripe": "https://abc123.ngrok.io/api/webhooks/stripe/",
# "nowpayments": "https://abc123.ngrok.io/api/webhooks/nowpayments/",
# "telegram": "https://abc123.ngrok.io/api/webhooks/telegram/",
# }

for provider, url in webhook_urls.items():
print(f"{provider}: {url}")

Built-in Integrationโ€‹

The payments app automatically integrates with ngrok:

Automatic URL Updatesโ€‹

# payments/services/integrations/ngrok_service.py (built-in!)

def get_webhook_url_for_provider(provider: str) -> str:
"""Automatically gets webhook URL for provider."""
from django_cfg.modules.django_ngrok import get_webhook_url
return get_webhook_url(f"/api/webhooks/{provider}/")

# Usage in payments code:
from django_cfg.apps.payments.services.integrations import get_webhook_url_for_provider

# Automatically correct URL!
nowpayments_webhook = get_webhook_url_for_provider("nowpayments")
# "https://abc123.ngrok.io/api/webhooks/nowpayments/"

Webhook Event Loggingโ€‹

All webhook events are automatically logged in the admin panel:

# Built-in webhook logging
from django_cfg.apps.payments.models import WebhookEvent

# Automatically created for each webhook
event = WebhookEvent.objects.create(
provider="stripe",
event_type="payment_intent.succeeded",
payload=request.body,
status="success",
response_time_ms=45
)

# View all events in admin panel

Configurationโ€‹

Custom Webhook Pathsโ€‹

# config.py
from django_cfg import NgrokConfig

ngrok: NgrokConfig = NgrokConfig(
enabled=True,
webhook_path="/webhooks/" # Custom base path
)

# Webhook URLs will be:
# https://abc123.ngrok.io/webhooks/stripe/
# https://abc123.ngrok.io/webhooks/nowpayments/
# https://abc123.ngrok.io/webhooks/telegram/

Custom Provider Pathsโ€‹

# urls.py
from django.urls import path
from . import webhook_views

urlpatterns = [
# Custom webhook paths
path('webhooks/stripe/', webhook_views.stripe_webhook),
path('webhooks/crypto/', webhook_views.nowpayments_webhook), # Custom!
path('webhooks/bot/', webhook_views.telegram_webhook), # Custom!
]

# Panel will show:
# - Stripe: https://abc123.ngrok.io/webhooks/stripe/
# - NowPayments: https://abc123.ngrok.io/webhooks/crypto/
# - Telegram: https://abc123.ngrok.io/webhooks/bot/

Development Workflowโ€‹

Complete Workflow Exampleโ€‹

# 1. Configure payments app and ngrok
class MyConfig(DjangoConfig):
enable_payments: bool = True
ngrok: NgrokConfig = NgrokConfig(enabled=True)

# 2. Start server
# $ python manage.py runserver_ngrok
# โœ… Ngrok tunnel ready: https://abc123.ngrok.io

# 3. Open webhook admin panel
# http://localhost:8000/admin/payments/webhook/

# 4. Copy webhook URLs from panel
# Stripe: https://abc123.ngrok.io/api/webhooks/stripe/
# NowPayments: https://abc123.ngrok.io/api/webhooks/nowpayments/

# 5. Configure webhooks in external services
# - Stripe Dashboard: Set webhook URL
# - NowPayments API: Set IPN callback URL
# - Telegram: Set bot webhook

# 6. Test webhooks locally
# - Send test payments
# - View webhook events in admin panel
# - Debug issues in real-time

# 7. Monitor webhook events
# - Check webhook events log
# - View response times
# - Debug failed webhooks

Panel Screenshotsโ€‹

Webhook Dashboard Interfaceโ€‹

The Webhook Dashboard provides a modern, user-friendly interface for webhook monitoring and testing:

Webhook Dashboard

Real-time webhook monitoring with ngrok tunnel status, event filtering, and testing tools.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Payment Admin Dashboard Payments Webhooks โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ”‚
โ”‚ Webhook Dashboard โ”‚
โ”‚ Monitor and test webhook endpoints โ”‚
โ”‚ โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Recent Webhook Events [Clear All]โ”‚ ๐ŸŒ Ngrok Tunnel [๐Ÿ”„] โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ [All Events โ–ผ] [All Status โ–ผ] โ”‚ ๐ŸŸข Status: Active โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โญ• payment.created [failed] โ”‚ Public URL โ”‚
โ”‚ Invalid Date [๐Ÿ‘] [๐Ÿ”„] โ”‚ https://eed65489ae77... [๐Ÿ“‹] โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โœ… payment.created [success] โ”‚ Webhook URL โ”‚
โ”‚ Invalid Date [๐Ÿ‘] [๐Ÿ”„] โ”‚ https://eed65489ae77... [๐Ÿ“‹] โ”‚
โ”‚ โ”‚ โ”‚
โ”‚ โœ… payment.created [success] โ”‚ [๐Ÿš€ Open Tunnel] โ”‚
โ”‚ Invalid Date [๐Ÿ‘] [๐Ÿ”„] โ”‚ โ”‚
โ”‚ โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค Webhook Stats โ”‚
โ”‚ Test Webhook โ”‚ โ”‚
โ”‚ โ”‚ Total Events 6 โ”‚
โ”‚ Webhook URL โ”‚ Successful 5 โ”‚
โ”‚ [https://your-site.com/webhook ] โ”‚ Failed 0 โ”‚
โ”‚ โ”‚ Success Rate undefined% โ”‚
โ”‚ Event Type โ”‚ โ”‚
โ”‚ [Select event type... โ–ผ]โ”‚โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”‚
โ”‚ โ”‚ Quick Actions โ”‚
โ”‚ [Send Test Webhook ] โ”‚ โ”‚
โ”‚ โ”‚ [๐Ÿ” Retry Failed Events ] โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค [๐Ÿ  Back to Dashboard ] โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Features Visible:

  • ๐Ÿ“‹ Event filtering by type and status
  • ๐ŸŸข Real-time tunnel status indicator
  • ๐Ÿ“‹ One-click URL copying
  • ๐Ÿ”„ Individual event retry
  • ๐Ÿ“Š Live webhook statistics
  • ๐Ÿงช Built-in webhook testing tool
  • ๐Ÿ” Bulk retry for failed events

Best Practicesโ€‹

1. Check Panel Before Testingโ€‹

Always verify ngrok status in panel before testing webhooks:

# โœ… CORRECT - check panel first
# 1. Open http://localhost:8000/admin/payments/webhook/
# 2. Verify "Tunnel Active: Yes"
# 3. Copy webhook URLs
# 4. Configure external services

2. Monitor Webhook Eventsโ€‹

Use the events log to debug webhook issues:

# View recent webhook events
# - Check response status
# - View payload details
# - Monitor response times
# - Debug failed webhooks

3. Use Test Featureโ€‹

Test webhooks before configuring external services:

# โœ… CORRECT - test first
# 1. Click "Test" button in panel
# 2. Verify webhook endpoint responds correctly
# 3. Fix any issues
# 4. Then configure external services

Troubleshootingโ€‹

Panel Shows "Tunnel Not Active"โ€‹

# If panel shows tunnel not active:

# 1. Make sure you used runserver_ngrok
python manage.py runserver_ngrok # NOT runserver!

# 2. Check ngrok configuration
# config.py
ngrok: NgrokConfig = NgrokConfig(
enabled=True # Must be True
)

# 3. Verify DEBUG=True
# Ngrok only works in development mode

Webhook URLs Not Displayingโ€‹

# If webhook URLs not showing:

# 1. Ensure payments app is enabled
enable_payments: bool = True

# 2. Run migrations
python manage.py migrate

# 3. Restart server
python manage.py runserver_ngrok

Next Stepsโ€‹

See Alsoโ€‹