Commit Graph

79 Commits

Author SHA1 Message Date
Tengku Achmad 97349e9d1e chore: add .env.example
Documents every environment variable read by server/index.cjs and the Vite
frontend (grep-verified against process.env.* / import.meta.env.* usage),
with placeholder values only — no real secrets. Not gitignored (.gitignore
already carves out an exception for it).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:49:57 +07:00
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 14c305b6bf feat: document full API surface in Postman collection
Reorganize into folders (Health & Config, Payment Links, Payment Operations,
Webhook, Logs & Docs, Dev/Test) and add every route that was missing:
GET/POST /api/config, POST /createtransaksi (ERP shape), Charge (Core API),
Create Snap Token, GET /api/logs, GET /api/logs/files, GET /api/logs/view,
GET /openapi.json, GET /docs, and the LOG_EXPOSE_API-only echo/echo2/
test-notify-erp endpoints. The Logs & Docs folder carries collection-level
Basic Auth (log_user/log_pass variables) shared by all its requests.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:49:38 +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 04c9ec233e chore: remove BMad-Method leftover files
v4-backup/ and web-bundles/ contain the BMad-Method agent-orchestration
framework (agent definitions, checklists, templates, game-dev/creative-writing
expansion packs) accidentally left in the repo. Nothing in server/ or src/
references either directory.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 22:48:05 +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 8578f1622b Merge branch 'main' of https://git.winteraccess.id/root/Midtrans-Middleware 2026-01-06 20:46:26 +07:00
root a5489c3a9e Merge pull request 'dev' (#23) from dev into main
Reviewed-on: #23
2025-12-08 05:11:32 +00:00
root 9a65fef3cf Merge pull request 'fix: update webhook signature retrieval and enhance error logging; correct file path in payment link test' (#22) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #22
2025-12-08 05:06:10 +00: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
root 137dc5c130 Merge pull request 'dev' (#21) from dev into main
Reviewed-on: #21
2025-12-08 04:09:48 +00:00
root b03806fae6 Merge pull request 'feat: add endpoints to list and read log files; enhance log retrieval functionality' (#20) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #20
2025-12-05 08:29:20 +00: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
root ea2fb9ca61 Merge pull request 'epic-6-snap-hybrid-complete' (#19) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #19
2025-12-05 08:26:02 +00: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 e70fd7be81 fix: comment out unused DemoStorePage imports in router 2025-12-04 23:02:31 +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
root 9d4d2f1ea8 Merge pull request 'epic-6-snap-hybrid-complete' (#18) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #18
2025-12-04 10:11:22 +00:00
CIFO Dev 29b28a389e Fix UX 2025-12-04 17:09:57 +07:00
CIFO Dev 6aa9a0658b fix build 2025-12-04 17:06:02 +07:00
root a9bb11f080 Merge pull request 'UX FIX' (#17) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #17
2025-12-04 10:01:03 +00:00
CIFO Dev e9016d507d UX FIX 2025-12-04 16:47:31 +07:00
root 01179d646e Merge pull request 'fix ux' (#16) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #16
2025-12-04 08:49:07 +00:00
CIFO Dev 7ebb5faa2f fix ux 2025-12-04 15:47:52 +07:00
root 5976f8e088 Merge pull request 'epic-6-snap-hybrid-complete' (#15) from epic-6-snap-hybrid-complete into dev
Reviewed-on: #15
2025-12-04 08:25:49 +00:00
CIFO Dev 3512fa4a4d fix ux 2025-12-04 14:56:53 +07:00
CIFO Dev c6225e3d35 feat: Add customer name display and improve Snap payment UX
- Add customerName prop to PaymentSheet component
- Display customer name in payment summary below Order ID
- Pass customer name from CheckoutPage form to PaymentSheet
- Fix TypeScript build errors (remove unused variables)
- Improve error logging in API interceptor
- Clean up snapLoader (remove unused snapLoading variable)
- Clean up PayPage (remove unused allowedMethods, runtimeCfg)
- Move lockOrder call to onSuccess callback in PayPage
- Add BOM handling in test-create-payment-link script
- Update test payment data (REFNO-002, TKG-2512041)
2025-12-04 12:45:05 +07:00
CIFO Dev 1f1393be30 Fix auto-payment trigger: wait for valid orderId before triggering Snap
- Add guard in AutoSnapPayment to only trigger when orderId and amount are valid
- Show loading state while waiting for payment data to resolve
- Prevent premature Snap token creation with empty/invalid data
- Fix PayPage and CheckoutPage auto-payment flow
2025-12-04 10:39:54 +07:00
CIFO Dev 386c84a26f Auto-trigger Snap payment: remove manual 'Bayar Sekarang' button click
- Add AutoSnapPayment component that auto-triggers Snap popup on mount
- Update CheckoutPage: auto-open Snap payment after form submission
- Update PayPage: auto-open Snap payment on page load
- Remove manual button clicks for smoother UX
- Add loading states and error handling for auto-payment flow
2025-12-04 10:35:32 +07:00
CIFO Dev 4bca71aeb3 Fix Snap payment flow: direct to payment UI in step 2 and add customer/item details to API request
- Remove intermediate payment method selection step in PayPage and CheckoutPage
- Update PayPage: direct step 2 payment interface (no wizard)
- Update CheckoutPage: 2-step wizard (form → payment)
- Add customer details (name, email, phone) to SnapPaymentTrigger
- Add item_details to Snap token request (required by Midtrans API)
- Fix 400 error from /api/payments/snap/token endpoint
- Clean up unused imports and variables
- Create payment link generation script (scripts/create-test-payment.mjs)
2025-12-03 17:01:12 +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
Ariq 34ee97848d adding ecosystem 2025-11-28 07:24:50 +00:00
root 7dce250966 Merge pull request 'feat/payment-ux-story-1-1' (#14) from feat/payment-ux-story-1-1 into dev
Reviewed-on: #14
2025-11-28 01:14:24 +00:00
CIFO Dev 4e36c42136 chore: remove .bmad, .trae, and docs folders from Git tracking 2025-11-28 08:06:53 +07:00
CIFO Dev 9754232d4c chore: update .gitignore to exclude .bmad, .trae folders and docs folder 2025-11-28 06:16:18 +07:00
CIFO Dev dd975ad222 new improvement 2025-11-25 16:24:52 +07:00
CIFO Dev d08b0bd312 feat(payments): complete Story 1.1 - Add loading overlay and error messages to all payment panels
- Updated GoPayPanel with LoadingOverlay and mapErrorToUserMessage
- Updated CStorePanel with LoadingOverlay and mapErrorToUserMessage
- All 3 payment methods now show user-friendly Bahasa Indonesia error messages
- Full-screen loading overlay prevents duplicate payment code generation

Story: 1.1 - Prevent Duplicate VA/QR/Code Generation & Improve Feedback
Status: Complete
2025-11-25 14:24:54 +07:00
CIFO Dev 4eccff2c03 feat(payments): implement Story 1.1 - Add error messages utility, loading overlay, and update BankTransferPanel
- Created src/lib/errorMessages.ts for user-friendly Bahasa Indonesia error messages
- Created src/components/LoadingOverlay.tsx with Framer Motion animations
- Updated BankTransferPanel with LoadingOverlay and mapErrorToUserMessage
- All 4 error catch blocks now use user-friendly messages
- GoPayPanel imports restored (ready for next iteration)

Story: 1.1 - Prevent Duplicate VA/QR/Code Generation & Improve Feedback
Status: Partial (BankTransferPanel complete, GoPayPanel & CStorePanel pending)
2025-11-25 14:04:41 +07:00
CIFO Dev 9a0f6d85f8 Merge remote-tracking branch 'origin/feat/payment-link-flow' 2025-11-25 13:52:49 +07:00
CIFO Dev 90923de3bd docs: Add Phase 1 Payment UX Improvements planning (problem-solution, tech-spec, epic, stories) 2025-11-25 13:51:14 +07:00
root c5995f7b39 Merge pull request 'feat/payment-link-flow' (#13) from feat/payment-link-flow into main
Reviewed-on: #13
2025-11-24 13:36:36 +00:00
Tengku Achmad b98c50cea8 refactor(payments): remove indomaret support and update navigation 2025-11-24 20:22:01 +07:00
Tengku Achmad 5034ecf1e4 feat: replace demo store with initial page and improve payment UI 2025-11-24 09:53:20 +07:00
root 18513b5968 Merge pull request 'feat/payment-link-flow' (#12) from feat/payment-link-flow into main
Reviewed-on: #12
2025-11-22 05:01:17 +00:00
Tengku Achmad c6b17bfab6 feat: update favicon and page title for branding 2025-11-22 11:58:37 +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
root 2494f3cedd Merge pull request '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' (#11) from feat/payment-link-flow into main
Reviewed-on: #11
2025-11-17 06:40:53 +00:00