Payment webhook service with a .NET 8 backend, Next.js frontend, and local PostgreSQL through Docker Compose.
Payhook validates signed payment webhook payloads, stores raw events, handles duplicate deliveries idempotently, processes accepted events asynchronously, and exposes a dashboard for filtering and monitoring payment status.
payhook/
backend/
src/
Payhook.Api/ # Web API .NET 8
frontend/ # Next.js + TypeScript
- Docker and Docker Compose
- .NET SDK 8
- Node.js 22 or later
- pnpm
- Copy the environment variables:
cp .env.example .env- Start the database, pgAdmin, and backend:
docker compose up --buildIn Development, the backend applies EF Core migrations during startup when it uses a relational database provider. This keeps an existing local Docker volume aligned with the current schema.
- Run the frontend outside Docker Compose:
pnpm install
pnpm frontend:devpnpm lint
pnpm lint:fix
pnpm format:check
pnpm formatdotnet test backend/tests/Payhook.Api.TestsThe webhook endpoint validates X-Signature as an HMAC SHA-256 signature using WEBHOOK_SIGNATURE_SECRET.
Expected responses:
202 Accepted: first valid delivery saved for background processing200 OK: duplicatetransaction_idalready received400 Bad Request: invalid JSON or payload validation error401 Unauthorized: missing or invalid signature
Example payload:
{"transaction_id":"txn_manual_001","contract_id":"contract_manual_001","amount":10.50,"payment_date":"2026-09-01T00:00:00Z","status":"Paid"}PowerShell example:
$secret = "dev-payhook-secret"
$payload = '{"transaction_id":"txn_manual_001","contract_id":"contract_manual_001","amount":10.50,"payment_date":"2026-09-01T00:00:00Z","status":"Paid"}'
$key = [Text.Encoding]::UTF8.GetBytes($secret)
$bytes = [Text.Encoding]::UTF8.GetBytes($payload)
$hmac = [Security.Cryptography.HMACSHA256]::new($key)
$signature = "sha256=" + (($hmac.ComputeHash($bytes) | ForEach-Object { $_.ToString("x2") }) -join "")
Invoke-WebRequest -Uri "http://localhost:5000/webhooks/payment" -Method Post -ContentType "application/json" -Body $payload -Headers @{ "X-Signature" = $signature }Send the same payload again to validate idempotency. The second response should be 200 OK.
You can also import collections/payhook.postman_collection.json into Postman. It includes valid, duplicate, invalid signature, invalid JSON, validation error, and query examples.
- Frontend:
https://payhook-frontend.vercel.app/ - Backend health check:
https://payhook-backend.onrender.com/health - Backend Swagger UI:
https://payhook-backend.onrender.com/swagger
The backend is hosted on Render's free tier, so the first request after a period of inactivity can take longer while the service wakes up.
Render backend environment variables:
ASPNETCORE_ENVIRONMENT=Development
ASPNETCORE_URLS=http://+:10000
ConnectionStrings__DefaultConnection=<render-postgres-connection-string>
WebhookSecurity__SignatureSecret=<webhook-signature-secret>
DOTNET_USE_POLLING_FILE_WATCHER=true
DOTNET_hostBuilder__reloadConfigOnChange=false
PaymentProcessing__ProcessingDelay=00:00:02
PaymentProcessing__QueueCapacity=1000
PaymentProcessing__PendingScanInterval=00:00:10
PaymentProcessing__PendingBatchSize=50
Vercel frontend environment variables:
PAYHOOK_API_BASE_URL=https://payhook-backend.onrender.com
Postman manual validation:
- Import
collections/payhook.postman_collection.json. - Set
base_urltohttps://payhook-backend.onrender.com. - Set
signature_secretto the same value configured in Render. - Run
Health Check,Webhook - Valid Payment,Webhook - Duplicate Payment, andPayments - List.
The API stores each accepted webhook in PostgreSQL before returning 202 Accepted. New events are pushed to a bounded in-memory Channel, and a hosted worker processes them outside the request path after the configured delay.
PostgreSQL remains the source of truth: the worker also scans pending events periodically, so events saved before an application restart can still be processed.
For production, a durable external broker such as RabbitMQ or Azure Service Bus would be preferred. Those services provide stronger delivery guarantees, independent worker scaling, dead-letter handling, and better operational visibility. The in-memory channel keeps local development lightweight while still supporting asynchronous processing and backpressure.
The dashboard lists received payments, supports filters by processing status and contract ID, and refreshes automatically every 5 seconds with TanStack Query polling. This is the current real-time behavior; it is polling, not WebSocket or SignalR.
The Next.js frontend calls its local /api/payments route, which proxies requests to the backend configured by PAYHOOK_API_BASE_URL to avoid browser CORS issues during local development.
- Backend:
http://localhost:5000 - Health check:
http://localhost:5000/health - Swagger UI:
http://localhost:5000/swagger - Frontend:
http://localhost:3000 - pgAdmin:
http://localhost:5050