Commit Graph

23 Commits

Author SHA1 Message Date
Tengku Achmad 77bc718c09 docs: rewrite README with backend setup, security, and tooling references
Root README.md was frontend-only and didn't mention the backend at all.
server/README.md was stale relative to the endpoint/security changes in this
branch (missing POST /api/payment-links, the sanitized order_id behavior,
rate limiting, CORS, log retention, state persistence, admin auth) and linked
to a temp/README.md that no longer exists. Both now point to /docs, /openapi.json,
and the Postman collection as the source of truth for the API surface.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:49:48 +07:00
Tengku Achmad c9149eec12 feat: add internal admin tooling — log viewer and Scalar API docs
- server/logviewer.html: readable log viewer at GET /api/logs/view — level
  filter chips, free-text search, and click-to-trace (clicking any field value
  re-filters to every line sharing it, e.g. an order_id or request id across
  its whole lifecycle). GET /api/logs/files/:filename now redirects browser
  navigation here instead of returning raw JSON (Accept: application/json
  still gets the JSON body).
- server/openapi.json + server/api-docs.html: OpenAPI 3.0 spec and a Scalar
  reference page served at GET /openapi.json and GET /docs. Scalar is loaded
  from a version-pinned CDN URL with a Subresource Integrity hash rather than
  installed as a dependency.
- Generalize requireLogBasicAuth -> requireAdminAuth since the same HTTP Basic
  Auth credentials now gate /api/logs*, /openapi.json, and /docs alike.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:49:26 +07:00
Tengku Achmad 441e6261a2 fix: harden payment-creation endpoints and persist server state
- ecosystem.config.cjs: NODE_ENV was hardcoded to "development" even for the
  production pm2 process, silently disabling every isDevEnv()-gated security
  check (API key bypass, admin auth bypass) in production. Now "production".
- Restrict CORS via configurable CORS_ALLOWED_ORIGINS (falls back to allow-all
  with a warning when unset, so this doesn't break existing traffic on deploy).
- Add an in-process, dependency-free rate limiter on /createtransaksi,
  /api/payment-links, /api/payments/charge, and /api/payments/snap/token to
  curb bot abuse / card-testing on endpoints the browser checkout must be able
  to call directly (an API-key gate would break that legitimate flow).
- Auto-delete LOGS_*.log files older than LOG_RETENTION_DAYS (default 30).
- Persist activeOrders, notifiedOrders, orderRetryCount, and orderMerchantId to
  server/data/state.json via Proxy-wrapped Map/Set (schedulePersist on every
  mutation), so idempotency and retry-suffix tracking survive restarts/crashes
  instead of resetting to empty every deploy.
- Remove processPaymentCompletion, dead code with no call sites.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:48:37 +07:00
Tengku Achmad 35bb27fc38 fix: align order_id state keys and secure log endpoints with Basic Auth
State maps (activeOrders, notifiedOrders, orderRetryCount, orderMerchantId)
were keyed by the raw order_id in /createtransaksi and /api/payment-links,
but Midtrans webhooks and status checks always report back the sanitized
('.'-joined) order_id. Whenever the original order_id contained characters
Midtrans disallows (e.g. ':'), the two never matched — breaking duplicate/
already-completed detection and retry-suffix lookups. Both endpoints now
key exclusively on the sanitized order_id, with retry-suffix support added
to /api/payment-links for parity with /createtransaksi.

Also add HTTP Basic Auth (requireLogBasicAuth) in front of /api/logs,
/api/logs/files, and /api/logs/files/:filename — these were previously
gated only by LOG_EXPOSE_API, which defaults to true, leaving order data
and transaction details publicly readable with no credentials.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:03:47 +07:00
Tengku Achmad c671468462 feat: add POST /api/payment-links to accept direct order_id/customer/expire_at payload
Adds a new endpoint that creates a shareable Midtrans Snap payment link
straight from { order_id, nominal, customer, expire_at } without remapping
to the mercant_id/item[] shape required by /createtransaksi.

order_id is sanitized (':' and other disallowed chars -> '.') before being
sent to Midtrans, while the mercant_id used for ERP webhook notification is
derived from the original, unsanitized order_id so ERP always gets a clean
identifier instead of the full composite order_id.

Includes a Postman collection covering link creation, resolution, status
check, and replaying a captured Midtrans notification payload for local
webhook debugging.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 21:47:15 +07:00
Tengku Achmad 80f92aba84 fix: replace colon separator in order_id with Midtrans-allowed character
Midtrans rejects order_id values containing ':' (only alphanumeric and
- _ ~ . are allowed). The composite mercant_id:item_id order_id and the
:rN retry suffix violated this, causing Snap token requests to fail
with a 400 once both a mercant_id and item_id were present.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 20:14:00 +07:00
Tengku Achmad 1db068bfb2 fix: update webhook signature retrieval and enhance error logging; correct file path in payment link test 2025-12-08 11:58:44 +07:00
Tengku Achmad 164e62c234 feat: add endpoints to list and read log files; enhance log retrieval functionality 2025-12-05 15:28:14 +07:00
Tengku Achmad 405f150724 feat: add fs and path dependencies; update server logging and webhook handling 2025-12-05 15:05:51 +07:00
Tengku Achmad c32ac1882d feat: update global styles and Tailwind configuration with Inter font; remove obsolete test files and add server documentation
- Added 'Inter' font to global CSS and Tailwind config for improved typography.
- Deleted unused test files related to payment link creation and Snap token testing.
- Created comprehensive README for server setup, API endpoints, and payment flow.
- Added testing documentation for easier integration and usage of the payment system.
2025-12-04 22:57:38 +07:00
CIFO Dev 3512fa4a4d fix ux 2025-12-04 14:56:53 +07:00
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
Tengku Achmad ec96b71161 feat(payments): extend payment link expiration to 24 hours
Update default payment link TTL from 30 minutes to 24 hours across frontend and backend. Also modify countdown display to show hours in addition to minutes and seconds.
2025-11-22 11:54:46 +07:00
CIFO Dev 96c4cd3aba feat(server): support multiple ERP notification URLs (ERP_NOTIFICATION_URLS)\n\n- Add env ERP_NOTIFICATION_URLS (comma-separated) with fallback to ERP_NOTIFICATION_URL\n- Update
otifyERP to broadcast payload to all endpoints and aggregate results\n- Log per-endpoint result and summary via erp.notify.success and erp.notify.summary\n- Add dev endpoint /api/echo2 for local multi-URL testing\n\nThis ensures signature is included in body for all endpoints and improves visibility in logs.
2025-11-17 13:33:03 +07:00
CIFO Dev 8c42768ec3 ERP: gunakan ERP_CLIENT_SECRET untuk signature; perbaiki fallback; tambah log detail HTTP request/response; endpoint GET /api/logs untuk akses log via browser; log payload ERP dengan signature length dan presence 2025-11-17 10:58:44 +07:00
Tengku Achmad e1dbe911c9 refactor(erp): make computeErpSignature async and improve signature handling 2025-11-14 16:43:31 +07:00
CIFO Dev 80fb683dcc Remove dev-only status mock; always query Midtrans API. Add helper script to compute Midtrans webhook signature for local tests. 2025-11-14 10:04:53 +07:00
CIFO Dev 6472e95310 fixing merchant id 2025-11-12 10:29:37 +07:00
CIFO Dev 4b43c61365 update merchat order id 2025-11-11 15:11:22 +07:00
CIFO Dev baed44ecd7 Align PayPage flow and update /createtransaksi schema 2025-11-11 10:19:50 +07:00
CIFO Dev a940fda6b2 payment link change 2025-11-10 16:39:10 +07:00
CIFO Dev 85d0c9a58b improvisasi 2025-11-10 15:32:41 +07:00
CIFO Dev 4862c32978 feat(payments): stabilisasi QRIS & CStore; hapus tombol Buat QR
GoPay: spinner QRIS dalam frame, hilangkan QR dummy saat menunggu, hapus tombol Buat QR, sanitasi URL actions. CStore: panel pilihan toko di Step 2, auto-generate kode dengan guard StrictMode, perbaiki busy agar tidak nyangkut setelah respons 201. Checkout: jangan auto-advance untuk CStore, oper defaultStore sesuai pilihan. BankTransfer: stabilisasi in-flight promise untuk VA (sebelumnya).
2025-11-10 11:10:35 +07:00