• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
ianmenethil

ianmenethil

ZenServer

Unlisted
Like
ZenServer
Home
Code
8
src
8
.vtignore
DOCUMENTATION.md
Dockerfile
README.md
deno.json
main.ts
openapi.yaml
Branches
1
Pull requests
Remixes
History
Environment variables
22
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
7/4/2025
Viewing readonly version of main branch: v18
View latest version
README.md

Secure Payment API

A production-ready payment API that solves the critical problem of payment fingerprint harvesting while maintaining publicly shareable booking links. Built with Deno, TypeScript, and enterprise-grade security controls.

πŸ›‘οΈ Security Architecture

  • Token-Based Booking Access: 256-bit secure tokens replace direct booking ID access
  • Dual Authentication: API key + nonce requirement for payment operations
  • Single-Use Nonces: IP-bound, 15-minute expiry with automatic invalidation
  • Environment Protection: Server requires critical secrets to start
  • Comprehensive Rate Limiting: Per-endpoint throttling prevents abuse

πŸš€ Quick Start

Prerequisites

# Required environment variables export PAYMENT_USERNAME=your_payment_gateway_username export PAYMENT_PASSWORD=your_payment_gateway_password export MERCHANT_CODE=your_merchant_code export API_KEY=your_secure_api_key

Run the Server

deno run --allow-net --allow-read --allow-env --allow-import --allow-write --allow-ffi main.ts

Server starts on http://localhost:5000 with:

  • 🌐 12 endpoints (5 public, 7 authenticated)
  • πŸ“‹ Interactive API documentation at /api/docs
  • πŸ›‘οΈ Multi-layered security with comprehensive logging

πŸ“š Documentation

πŸ“– Complete Documentation - Detailed architecture, security flows, and API reference

Key Sections:

  • Problem & Solution: Why this architecture prevents fingerprint harvesting
  • Security Model: Multi-layered protection mechanisms
  • API Reference: Complete endpoint documentation with examples
  • Frontend Integration: Required client-side functions and flow examples
  • File Structure: Purpose of each component in the system

πŸ”‘ Core API Endpoints

Booking Access

// Generate secure booking token (Admin) POST /api/generate-booking-token Authorization: Bearer {api_key} // Access booking with token (Public) GET /booking/{token}

Payment Security

// 1. Generate nonce POST /api/create-payment-nonce Body: { bookingId: "booking_123" } // 2. Create payment fingerprint (Dual Auth Required) POST /api/create-payment-hash Authorization: Bearer {api_key} X-Payment-Nonce: {nonce} // 3. Refresh session after failures POST /api/v1/payment/refresh Body: { bookingId: "booking_123" }

πŸ” Security Features Verified

βœ… Token-based booking access prevents ID enumeration
βœ… Dual authentication (API key + nonce) for payment operations
βœ… Environment secret validation prevents unauthorized deployment
βœ… Rate limiting (5-20 req/min per endpoint) blocks abuse
βœ… Single-use nonces with IP binding and 15-minute expiry
βœ… Dynamic schema validation from OpenAPI specifications
βœ… Comprehensive audit logging with structured security events

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Public User   β”‚    β”‚   Admin/Client   β”‚    β”‚ Payment Gateway β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
          β”‚                      β”‚                       β”‚
          β”‚ GET /booking/{token} β”‚                       β”‚
          β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚                       β”‚
          β”‚                      β”‚ Dual Auth Required    β”‚
          β”‚                      β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Ίβ”‚
          β”‚                      β”‚ Payment Fingerprint   β”‚
          β”‚                      │◄───────────────────────
          β”‚ Secure Payment Form  β”‚                       β”‚
          │◄──────────────────────                       β”‚
          β”‚                      β”‚                       β”‚

πŸ“Š System Benefits

Security Benefits

  • Prevents mass fingerprint harvesting through dual authentication
  • Blocks booking enumeration attacks with secure tokens
  • Eliminates replay attacks using single-use nonces
  • Provides comprehensive audit trails for compliance

Business Benefits

  • Maintains shareable booking links without compromising security
  • Reduces payment failures from fingerprint abuse
  • Enables public access while protecting sensitive operations
  • Supports compliance with industry security standards

πŸ”§ Development

File Structure

src/
β”œβ”€β”€ gateway/apiGateway.ts      # Centralized routing & security control
β”œβ”€β”€ handlers/                  # Endpoint handlers (booking, payment, etc.)
β”œβ”€β”€ middleware/               # Security middleware (CORS, rate limiting)
β”œβ”€β”€ services/                 # Core business logic (auth, nonce, payment)
└── utils/                    # Utilities (logging, validation, OpenAPI)

Testing

All endpoints tested and verified:

  • Booking token generation and access
  • Payment nonce and fingerprint creation
  • Security controls and rate limiting
  • Error handling and validation

πŸ“‹ Production Checklist

  • Environment variables configured
  • CORS origins set for production domains
  • SSL/TLS certificates installed
  • Monitoring and alerting configured
  • Database backup strategy implemented
  • Security event logging enabled

Built with Enterprise Security β€’ Production Ready β€’ Fully Documented

FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2026 Val Town, Inc.