The TSP Payment Gateway uses a payment orchestration architecture that connects merchants with multiple payment providers through a unified platform.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Merchants β
β (E-commerce, SaaS, etc.) β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β TSP Payment Gateway Platform β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β API Layer β β
β β (OAuth, Checkout, Settlement, Webhooks) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Business Logic Layer β β
β β (Routing, Fee Calculation, Reconciliation) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Data Layer β β
β β (Merchants, Transactions, Settlements) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββ βββββββββββ βββββββββββ
β Stripe β β PayPal β β Adyen β
β Connect β βCommerce β β (Future)β
βββββββββββ βββββββββββ βββββββββββ
β β β
βββββββββββββββΌββββββββββββββ
β
βΌ
ββββββββββββββββββββββββ
β Payment Networks β
β (Visa, Mastercard) β
ββββββββββββββββββββββββ
Responsibilities:
- Handle merchant requests
- Manage OAuth authentication
- Process payment requests
- Handle webhooks
- Provide settlement data
Key Endpoints:
POST /merchants/connect- OAuth initiationPOST /payments- Create paymentGET /payments/{id}- Get payment statusPOST /refunds- Create refundGET /settlements- Get settlement dataPOST /webhooks- Receive provider webhooks
Responsibilities:
- Route payments to appropriate provider
- Calculate application fees
- Handle payment reconciliation
- Manage merchant onboarding
- Process refunds and disputes
Key Components:
- Router: Determines which provider to use
- Fee Calculator: Calculates platform fees
- Reconciliation Engine: Matches transactions
- Settlement Manager: Manages payouts
- Dispute Handler: Handles chargebacks
Responsibilities:
- Store merchant data
- Store transaction data
- Store settlement data
- Maintain audit logs
- Provide data access
Key Tables:
merchants- Merchant informationtransactions- Payment transactionssettlements- Settlement recordsrefunds- Refund recordswebhooks- Webhook logsaudit_logs- Compliance audit trail
Responsibilities:
- Connect to payment providers
- Handle provider-specific logic
- Normalize provider responses
- Implement provider webhooks
Supported Providers:
- Stripe Connect
- PayPal Commerce Platform
- Adyen (future)
1. Merchant initiates payment
ββ> POST /payments
2. Platform validates request
ββ> Check merchant, amount, currency
3. Platform routes to provider
ββ> Determine best provider
4. Platform creates payment intent
ββ> Stripe/PayPal creates transaction
5. Customer completes payment
ββ> 3D Secure, card details, etc.
6. Provider confirms payment
ββ> Sends webhook to platform
7. Platform updates database
ββ> Stores transaction record
8. Platform notifies merchant
ββ> Webhook to merchant
9. Platform receives settlement
ββ> Funds arrive in merchant account
10. Platform receives application fee
ββ> Fee arrives in platform account
1. Provider settles transactions
ββ> Daily or weekly settlement
2. Funds arrive in merchant account
ββ> Provider transfers to merchant
3. Platform fees arrive
ββ> Provider transfers to platform
4. Platform reconciles
ββ> Matches transactions to settlements
5. Platform notifies merchant
ββ> Settlement report sent
6. Platform records settlement
ββ> Updates database
- Language: Python or Node.js
- Framework: Flask/FastAPI or Express
- Database: PostgreSQL
- Cache: Redis
- Message Queue: RabbitMQ or SQS
- Framework: React or Vue.js
- UI Library: Material-UI or Tailwind CSS
- State Management: Redux or Vuex
- Cloud: AWS or GCP
- Container: Docker
- Orchestration: Kubernetes
- CI/CD: GitHub Actions or GitLab CI
- Metrics: Prometheus
- Logging: ELK Stack or CloudWatch
- Tracing: Jaeger or DataDog
- Alerting: PagerDuty
- Encryption at Rest: AES-256
- Encryption in Transit: TLS 1.3
- Key Management: AWS KMS or HashiCorp Vault
- Merchant Auth: OAuth 2.0
- API Auth: API Keys + HMAC
- Internal Auth: JWT tokens
- Level: SAQ A (Hosted Fields only)
- Scope: Minimal card data handling
- Certification: Annual audit
- Transaction Monitoring: Real-time rules engine
- Velocity Checks: Limit transaction frequency
- Geolocation Checks: Detect suspicious locations
- Device Fingerprinting: Track devices
- Stateless API servers: Multiple instances behind load balancer
- Database replication: Read replicas for scaling reads
- Caching layer: Redis for frequently accessed data
- Message queue: Async processing of webhooks
- Database indexing: Optimize query performance
- Query optimization: Reduce N+1 queries
- Connection pooling: Reuse database connections
- API caching: Cache provider responses
- Metrics: Track system performance
- Logs: Centralized logging
- Traces: Distributed tracing
- Alerts: Proactive alerting
- Local development with Docker
- Local database
- Mock payment providers
- Staging server (AWS/GCP)
- Staging database
- Stripe/PayPal test accounts
- Production servers (AWS/GCP)
- Production database with backups
- Stripe/PayPal live accounts
- CDN for static assets
- OAuth for merchant onboarding
- Payment Intent API for payments
- Webhooks for payment updates
- Payout API for settlements
- Partner Referrals API for onboarding
- Orders API for payments
- Webhooks for updates
- Reporting API for settlements
- AML/KYC providers
- Compliance monitoring
- Audit logging
- Regulatory reporting
Route payments to multiple providers based on:
- Merchant preference
- Provider availability
- Cost optimization
- Geographic coverage
Prevent duplicate charges by:
- Using idempotency keys
- Caching request results
- Checking for duplicates
- Retrying safely
Use events for:
- Webhook processing
- Async notifications
- Audit logging
- Analytics
Handle provider failures by:
- Monitoring provider health
- Failing fast
- Falling back to alternative provider
- Alerting on failures
- Database: Daily backups, 30-day retention
- Code: Version control with GitHub
- Secrets: Encrypted in vault
- Logs: Archived for 1 year
- RTO (Recovery Time Objective): 1 hour
- RPO (Recovery Point Objective): 15 minutes
- Failover: Automatic to standby system
- Testing: Monthly disaster recovery drills
- Additional payment providers (Adyen, Square)
- Real-time settlement
- Advanced routing algorithms
- Machine learning for fraud detection
- Blockchain integration (future)
- Microservices architecture (Year 2)
- Event streaming (Kafka)
- GraphQL API
- Mobile app
- See
docs/TECHNICAL.mdfor detailed technical specification - See
knowledge-base/ARCHITECTURE_PATTERNS.mdfor design patterns - See
examples/for code examples
Document Version: 1.0
Last Updated: June 2026
Prepared For: Technical Teams