CIFO Dev
d051c46ac4
feat: Epic 6 Stories 6.1-6.5 - Snap Hybrid Payment Strategy
...
Implemented comprehensive Snap integration with hybrid Core/Snap payment strategy:
Story 6.1 - Environment Switching:
- Added PAYMENT_GATEWAY_MODE env variable (CORE/SNAP)
- Created paymentMode.ts utilities for mode detection
- Added startup validation in main.tsx
- Implemented mode-aware logging with [CORE]/[SNAP] prefixes
Story 6.2 - Snap Payment Flow:
- Created /api/payments/snap/token endpoint
- Implemented SnapPaymentTrigger component with conditional rendering
- Added Snap.js script loading for SNAP mode
- Integrated hosted payment interface
Story 6.3 - Unified Webhook Handler:
- Enhanced /api/payments/notification for Core & Snap
- Implemented mode detection from payload structure
- Added unified signature verification
- Created shared status mapping and ledger updates
Story 6.4 - Shared Backend Logic:
- Created TransactionLogger for unified mode-aware logging
- Implemented OrderManager for shared validation logic
- Added CustomerDataHandler for consistent data sanitization
- Integrated shared utilities across payment endpoints
Story 6.5 - Code Organization:
- Reorganized into core/, snap/, shared/, lib/ structure
- Moved Core components to payments/core/
- Created PaymentAdapter for factory pattern routing
- Added SnapTokenService for token management
- Updated all import paths for new structure
Key Benefits:
✅ Instant rollback via environment variable
✅ Infrastructure offloading to Midtrans hosted interface
✅ Clean separation of Core vs Snap implementations
✅ Unified webhook processing for both modes
✅ Shared utilities eliminate code duplication
Technical Details:
- TypeScript compilation successful (549KB bundle)
- All payment methods work in both CORE and SNAP modes
- Dynamic component loading for Core components
- Mode-aware logging throughout payment flow
- Backwards compatible with existing Core API implementation
2025-12-03 15:33:22 +07:00