Documentation Index
Fetch the complete documentation index at: https://docs-paymentgateway.redahaloubi.com/llms.txt
Use this file to discover all available pages before exploring further.
Welcome to Payment Gateway
A complete payment processing platform built for scale, security, and learning Payment Gateway is a production-ready microservices ecosystem that handles the full payment lifecycle—from card tokenization to settlement. Built with Go, PostgreSQL, Redis, and Kubernetes, it demonstrates real-world distributed systems architecture while serving as a powerful learning resource.What is Payment Gateway?
Payment Gateway is both a functional payment platform and an educational resource showcasing:Microservices Architecture
PCI-DSS Compliance
Financial Operations
Production Practices
Key Features
Payment Operations
Authorization & Capture
Authorization & Capture
Payment Intents
Payment Intents
- Hosted checkout flow with browser-friendly authentication
- Client secret-based security (no API keys in browser)
- Automatic expiration after 1 hour
- Payment attempt tracking and limits
Multi-Currency Support
Multi-Currency Support
- Supported: USD, EUR, MAD (Moroccan Dirham)
- Automatic currency conversion
- Real-time exchange rates
- Processing fees calculated per currency
Security & Compliance
Card Tokenization
Card Tokenization
- PCI-compliant token-based system
- AES-256-GCM encryption per merchant
- Card fingerprinting for duplicate detection
- Single-use tokens for sensitive operations
Access Control
Access Control
- Role-based access control (RBAC)
- Granular permissions (resource:action format)
- Multi-tenant support (different roles per merchant)
- API key management with usage tracking
Audit & Compliance
Audit & Compliance
- Complete transaction history
- Event logging for all state changes
- PCI-compliant activity logs
- Webhook delivery with retry logic
Developer Experience
Multiple Integration Options
Multiple Integration Options
- REST APIs for public merchant access
- gRPC for high-performance internal communication
- Hosted checkout page (no PCI scope for merchants)
- CLI tool for quick testing
Developer-Friendly Features
Developer-Friendly Features
- Idempotency support (24-hour cache)
- Rate limiting per merchant
- Comprehensive test cards
- Webhook notifications with HMAC signatures
System Architecture
High-Level Overview
Payment Gateway consists of 7 core microservices organized into layers based on access level and responsibility.Service Architecture Layers
External Layer
Public Layer
Internal Layer
Service Overview
1. API Gateway (Port 8080)
Entry point for all client requestsResponsibilities
Responsibilities
- CORS handling and security headers
- Request/response logging
- Rate limiting per merchant (configurable per endpoint)
- Request routing to backend services
- Circuit breaking for failing services
Key Features
Key Features
- Per-route rate limits (20 payments/sec, 5 login attempts/min)
- Request ID generation for tracing
- Health check aggregation
- Graceful shutdown with connection draining
2. Auth Service (Port 8001, gRPC: 50051)
Authentication, authorization, and access controlResponsibilities
Responsibilities
- User registration and login (JWT tokens)
- Role-based access control (RBAC)
- Permission management (resource:action format)
- API key generation and validation
- Session management with Redis
Key Features
Key Features
- bcrypt password hashing (cost 10)
- Account lockout after 5 failed attempts (30-minute lock)
- Multi-tenant role assignments
- Redis-cached permissions for fast validation
- JWT with 24-hour access tokens, 7-day refresh tokens
3. Merchant Service (Port 8002)
Merchant account and team managementResponsibilities
Responsibilities
- Merchant onboarding and verification
- Business profile management
- Team member invitations and role assignment
- Payment settings configuration (currencies, webhooks)
- Multi-merchant support per user
Key Features
Key Features
- Invitation system with email tokens
- Role-based team permissions (Owner, Admin, Manager, Staff)
- Webhook configuration per merchant
- Payment method and currency preferences
4. Payment API Service (Port 8004)
Public payment processing gatewayResponsibilities
Responsibilities
- Payment orchestration (authorize, capture, void, refund)
- Payment Intents for hosted checkout
- Idempotency handling (24-hour cache)
- Webhook delivery with retry logic
- Transaction status tracking
Key Features
Key Features
- Single-step (sale) and multi-step (auth → capture) payments
- Payment attempt tracking with limits
- Automatic expiration (1 hour for intents)
- Test card support for development
- Rate limiting: 20 payments/sec, 10,000/hour per merchant
5. Tokenization Service (Port 50052 - gRPC Only)
PCI-compliant card tokenizationResponsibilities
Responsibilities
- Card data encryption (AES-256-GCM)
- Token generation and validation
- Card fingerprinting (SHA-256) for duplicate detection
- Encryption key rotation (90 days or 1M operations)
- BIN database lookups
Key Features
Key Features
- Per-merchant encryption keys
- Single-use tokens for sensitive operations
- Luhn validation, expiry checks, CVV validation
- Never logs full PAN or CVV
- Token lifecycle management (active, expired, revoked, used)
6. Transaction Service (Port 50053 - gRPC Only)
Core payment transaction engineResponsibilities
Responsibilities
- Transaction lifecycle management (state machine)
- Card simulator for testing (no real card processing)
- Multi-currency conversion (USD, EUR, MAD)
- Settlement batch processing (daily at midnight, T+2)
- Chargeback handling
Key Features
Key Features
- Auto-void expired authorizations (7 days)
- Processing fee calculation (2.9% + $0.30 in MAD)
- Daily settlement reports
- Currency conversion with hourly rate updates
- Complete transaction event history
7. Payment Checkout (Port 3000)
Hosted checkout application for customersResponsibilities
Responsibilities
- Browser-friendly payment flow
- Client secret authentication (no API keys exposed)
- Payment Intent confirmation
- Redirect to success/cancel URLs
- Card input validation
Key Features
Key Features
- Built with Next.js 15 and React 19
- Real-time card validation (Luhn, expiry, CVV)
- Responsive mobile-first design
- Automatic expiration handling
- Success animation with redirect
Complete Payment Flow
Here’s how a payment flows through the entire system:Flow Breakdown
Merchant Creates Payment Intent
/payment-intents with amount, currency, and redirect URLs. Receives client_secret for browser authentication.Customer Redirected to Checkout
client_secret in URL.Customer Enters Card & Confirms
- Checkout validates card details client-side (Luhn, expiry, CVV)
- Sends card data to Payment API (secured by client_secret)
- Payment API calls Tokenization Service to encrypt card
- Tokenization returns token (never stores plain card data)
Transaction Processing
- Payment API calls Transaction Service with token
- Transaction Service simulates card processing
- Returns authorization code or decline reason
- Payment API updates intent status
Customer Redirected Back
success_url or cancel_url based on result.Technology Stack
Backend Services
Language
HTTP Framework
gRPC
ORM
Data Layer
Database
Cache
Security
Authentication
Encryption
Hashing
Secrets
Infrastructure
Orchestration
Ingress
Monitoring
Cloud
Frontend
Framework
Styling
Database Architecture
Each microservice has its own dedicated PostgreSQL database, following microservices best practices:- Independent scaling per service
- Schema changes don’t cascade
- Service failures isolated
- Enhanced security (each service has credentials only to its DB)
Redis Usage
Single Redis instance shared across services for:- Session storage (Auth JWT sessions)
- Rate limiting (API Gateway)
- Caching (Merchant/Payment data)
- Idempotency (24-hour request cache)
Security & Compliance
PCI-DSS Compliance
Encryption Strategy
Per-Merchant Encryption Keys
Field-Level Encryption
Automatic Key Rotation
Authentication Methods
- JWT Tokens
- API Keys
- Client Secrets
- Access Token: 24-hour expiry
- Refresh Token: 7-day expiry
- Algorithm: HS256 (HMAC-SHA256)
Deployment Architecture
Production Environment
Live Platform
- Cloud Provider: AWS
- Instance Type: EC2 (Auto-scaling enabled)
- Orchestration: Kubernetes (k3d cluster)
- Ingress: NGINX Ingress Controller with Cloudflare Tunnel
- TLS: Cloudflare SSL termination
- Monitoring: Prometheus + Grafana (NodePort access)
Network Architecture
What’s Next?
Quick Start
Auth API
Merchant API
Payment API
Support & Resources
GitHub Repository
Email Support
Kubernetes Guide
CLI Tool
Version: 1.0.0
Last Updated: January 2026
Status: Production Ready