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 |
||
|---|---|---|
| public | ||
| scripts | ||
| server | ||
| src | ||
| v4-backup/.bmad-core | ||
| web-bundles | ||
| .gitignore | ||
| README.md | ||
| coreApiSimpleExample.js | ||
| eslint.config.js | ||
| index.html | ||
| package-lock.json | ||
| package.json | ||
| postcss.config.cjs | ||
| tailwind.config.ts | ||
| tmp-createtransaksi.json | ||
| tmp-sig.txt | ||
| tmp-sig2.txt | ||
| tmp-sig3.txt | ||
| tsconfig.app.json | ||
| tsconfig.json | ||
| tsconfig.node.json | ||
| vite.config.ts | ||
README.md
Core Midtrans CIFO (Frontend)
Frontend Vite + React untuk integrasi Midtrans Core API dengan UI kustom.
Setup
- Duplikasi file contoh env dan isi nilainya:
cp .env.example .env.local
Isi .env.local (lihat .env.example untuk referensi):
VITE_API_BASE_URL=http://localhost:8000/api
VITE_MIDTRANS_CLIENT_KEY=YOUR_CLIENT_KEY
VITE_MIDTRANS_ENV=sandbox
- Jalankan pengembangan:
npm install
npm run dev
App akan tersedia di http://localhost:5173/ (atau port lain jika 5173 dipakai).
Catatan Integrasi Midtrans
- Client Key hanya digunakan di frontend (mis. tokenisasi kartu/3DS). Server Key TIDAK pernah di frontend.
- Semua request ke Midtrans dilakukan lewat backend (
VITE_API_BASE_URL). Frontend memanggil endpoint seperti/payments/:orderId/status. - Status real-time dapat diimplementasikan via polling (TanStack Query) atau SSE/WebSocket dari backend.
Struktur Env di Kode
- Akses env melalui modul
src/lib/env.ts:Env.API_BASE_URLEnv.MIDTRANS_CLIENT_KEYEnv.MIDTRANS_ENV
Lisensi
Internal project skeleton.