Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ VITE_GA_MEASUREMENT_ID=G-VNQJ3XPCGG
VITE_CLARITY_PROJECT_ID=wf7x39iiqr
VITE_SENTRY_DSN=
VITE_SENTRY_TRACES_SAMPLE_RATE=0
# Midtrans secret/server keys are backend-only. Do not add VITE_MIDTRANS_* keys.
# Mayar API key / webhook token are backend-only. Never add VITE_MAYAR_* keys.

# ── Affiliate & Referral Safe Rollout Flags ───────────────────────
# Defaults are off. Enable gradually per docs/RELEASE_CHECKLIST_AFFILIATE_REFERRAL.md.
Expand Down
4 changes: 1 addition & 3 deletions .env.staging.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ VITE_APP_ENV=staging
VITE_STAGING_PROFILE=minimal
VITE_API_BASE_URL=https://staging-api.example.com
VITE_ANALYTICS_ENABLED=false
VITE_MIDTRANS_IS_PRODUCTION=false

# Smoke runner env (local only; do not commit real values)
KAFFEPOS_STAGING_API_URL=https://staging-api.example.com
Expand All @@ -23,7 +22,6 @@ KAFFEPOS_STOCK_SMOKE_CONFIRM=1
VITE_GA4_MEASUREMENT_ID=G-XXXXXXXXXX
VITE_CLARITY_PROJECT_ID=change-me
VITE_PUBLIC_ASSET_BASE_URL=https://assets.example.com
VITE_MIDTRANS_CLIENT_KEY=SB-Mid-client-change-me

# Feature flags
VITE_AFFILIATE_REFERRAL_ENABLED=false
Expand All @@ -32,7 +30,7 @@ VITE_AFFILIATE_ENABLED=false
VITE_ADMIN_COMMISSION_ENABLED=false

# C. Optional integrations skipped in minimal mode
# GA4, Clarity, Midtrans Snap client key, and public asset CDN may remain placeholders in minimal staging.
# GA4, Clarity, and public asset CDN may remain placeholders in minimal staging.

# Frontend payment provider only; no Mayar secrets in frontend
VITE_PAYMENT_GATEWAY_PROVIDER=mayar
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ The repair command reads ignored local staging env files, requires `STAGING_PROF
| **Deployment Guide** | [`docs/launch/DEPLOYMENT_GUIDE.md`](docs/launch/DEPLOYMENT_GUIDE.md) | Production deployment procedures |
| **Validation Checklist** | [`docs/launch/VALIDATION_CHECKLIST.md`](docs/launch/VALIDATION_CHECKLIST.md) | End-to-end validation |
| **Android Release Signing** | [`docs/launch/ANDROID_RELEASE_SIGNING.md`](docs/launch/ANDROID_RELEASE_SIGNING.md) | Android APK signing guide |
| **Midtrans Production Switch** | [`docs/launch/MIDTRANS_PRODUCTION_SWITCH.md`](docs/launch/MIDTRANS_PRODUCTION_SWITCH.md) | Payment production setup |
| **Mayar Integration Guide** | [`docs/engineering/MAYAR_INTEGRATION_GUIDE.md`](docs/engineering/MAYAR_INTEGRATION_GUIDE.md) | Payment gateway setup (API key, webhook token, webhook URL) |

### Operations Documentation

Expand Down Expand Up @@ -215,7 +215,7 @@ The repair command reads ignored local staging env files, requires `STAGING_PROF

### Infrastructure & Cloud Services
- **Cloud Backend & Database:** InsForge Cloud PostgreSQL (`6x4q2bgn.ap-southeast.insforge.app`, 46 tables with full RLS + 160+ indexes) & InsForge Edge Functions (`@insforge/sdk`)
- **Payment Gateway:** Mayar Headless API v2 (`https://api.mayar.id/hl/v2` production / `https://api.mayar.club/hl/v2` sandbox)
- **Payment Gateway:** Mayar Headless API v2 (`https://api.mayar.id/hl/v2` production / `https://api.mayar.io/hl/v2` sandbox)
- **CDN & Storage:** Cloudflare CDN & R2 / InsForge Storage
- **Transactional Email:** Resend
- **Analytics & Observability:** Google Analytics 4, Microsoft Clarity, Sentry Error Tracking & Custom Database APM
Expand Down Expand Up @@ -495,15 +495,15 @@ KaffePOS uses PostgreSQL with a custom migration system.

## 💳 Mayar Payment Gateway (Headless API v2)

- Payment gateway default menggunakan **Mayar (`PAYMENT_GATEWAY_PROVIDER=mayar`)** berbasis REST API v2 resmi (`https://api.mayar.id/hl/v2` untuk production dan `https://api.mayar.club/hl/v2` untuk sandbox).
- Mendukung baik **Subscription Billing** (`POST /api/payments/start` dan `POST /api/subscriptions/payments/create`) maupun **POS Online Checkout** (`POST /api/payment/create`).
- Daftarkan URL Webhook Mayar pada **Mayar Dashboard → Integration → Webhook**:
- `https://api.kaffepos.my.id/api/webhooks/mayar`
- Customer redirect URL setelah pembayaran:
- `https://kaffepos.my.id/settings?billing=mayar-return`
- Verifikasi pembayaran dilakukan sepenuhnya di sisi server melalui webhook terautentikasi (`x-callback-token` / `x-mayar-signature` / `HMAC-SHA256`) atau pengecekan status server (`POST /api/payments/:paymentId/check` → `GET /hl/v2/payments/:id`).
- `MAYAR_API_KEY` dan `MAYAR_WEBHOOK_TOKEN` bersifat **backend-only** dan tidak pernah diekspos ke bundle frontend (`VITE_*`).
- Smoke test integrasi Mayar & InsForge:
- `npm run smoke:insforge`
- Mayar adalah **satu-satunya** payment gateway (`PAYMENT_GATEWAY_PROVIDER=mayar`; DOKU sudah dihapus). API resmi: `https://api.mayar.id/hl/v2` (production) dan `https://api.mayar.io/hl/v2` (sandbox).
- Dipakai untuk **Subscription Billing** (`POST /api/payments/start`, `POST /api/subscriptions/payments/create`) dan **POS Online Checkout** (`POST /api/payment/create-transaction`).
- Tiga hal yang menghubungkan KaffePOS ke Mayar (semuanya backend-only, tidak pernah `VITE_*`):
- `MAYAR_API_KEY` — Bearer key untuk membuat payment request & cek status.
- `MAYAR_WEBHOOK_TOKEN` — Web Token dari dashboard Mayar; Mayar mengirimnya di header `X-Callback-Token` (`?token=` di URL juga diterima).
- URL webhook di **Mayar → Integrasi → Webhook**: `https://api.kaffepos.my.id/api/webhooks/mayar`.
- Webhook `payment.received` tidak pernah dipercaya begitu saja: backend mengecek ulang `GET /hl/v2/payments/:id` (status `paid` + nominal sama) sebelum melunasi order POS atau mengaktifkan langganan. Cek manual: `POST /api/payments/:paymentId/check`.
- Hubungkan & uji:
- `node scripts/mayar-connect.mjs --register` (di container backend) atau `npm run mayar:connect -- --register`
- `MAYAR_API_KEY=... MAYAR_ENVIRONMENT=sandbox npm run smoke:staging:mayar`
- Implementasi provider: [`backend/src/payments/providers/mayar.provider.ts`](backend/src/payments/providers/mayar.provider.ts) & skill referensi: [`.agent/skills/mayar/SKILL.md`](.agent/skills/mayar/SKILL.md).
- `npm run smoke:local:mayar` (end-to-end dengan Mayar palsu + Postgres lokal)
- Panduan lengkap: [`docs/engineering/MAYAR_INTEGRATION_GUIDE.md`](docs/engineering/MAYAR_INTEGRATION_GUIDE.md) · Implementasi: [`backend/src/payments/providers/mayar.provider.ts`](backend/src/payments/providers/mayar.provider.ts), [`backend/src/routes/webhooks.ts`](backend/src/routes/webhooks.ts).
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ undo the exposure.
| `SESSION_SECRET` | ❌ no refs | Dead config. No rotation needed. |
| `ENCRYPTION_KEY` | ❌ no refs | Dead — the code reads `PII_ENCRYPTION_KEY`, not `ENCRYPTION_KEY`. No rotation needed. |

(Duitku/Midtrans have since been removed; the gateway is DOKU. Treat any committed `DOKU_SECRET_KEY` as compromised and rotate it in the DOKU Back Office.)
(Duitku, Midtrans and DOKU have since been removed; the only gateway is Mayar. Treat any committed `DOKU_SECRET_KEY` as compromised and revoke it in the DOKU Back Office. `MAYAR_API_KEY` and `MAYAR_WEBHOOK_TOKEN` are backend-only secrets: if either leaks, create a new API key / Web Token in the Mayar dashboard, update Coolify, and re-run `node scripts/mayar-connect.mjs` — see `docs/engineering/MAYAR_INTEGRATION_GUIDE.md`.)

> ⚠️ **DB password ↔ PII key coupling.** `lib/encryption.ts` derives the
> affiliate payout/bank-account (PII) encryption key from `PII_ENCRYPTION_KEY`,
Expand Down
32 changes: 14 additions & 18 deletions backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,13 @@ DB_SSL_CA=
RESEND_API_KEY=
RESEND_FROM_EMAIL=KaffePOS <[email protected]>

# Midtrans subscription payments
MIDTRANS_ENVIRONMENT=sandbox
MIDTRANS_SERVER_KEY=
MIDTRANS_CLIENT_KEY=
MIDTRANS_MERCHANT_ID=
MIDTRANS_SNAP_ENABLED=true
MIDTRANS_WEBHOOK_BASE_URL=https://api.kaffepos.my.id
MIDTRANS_FINISH_URL=https://kaffepos.my.id/settings?billing=success
MIDTRANS_UNFINISH_URL=https://kaffepos.my.id/settings?billing=pending
MIDTRANS_ERROR_URL=https://kaffepos.my.id/settings?billing=failed
SUBSCRIPTION_PAYMENT_MODE=auto

# Abuse protection
AUTH_RATE_LIMIT_WINDOW_MS=900000
AUTH_LOGIN_RATE_LIMIT_MAX=10
AUTH_EMAIL_RATE_LIMIT_MAX=5
AUTH_VERIFY_RATE_LIMIT_MAX=20
PAYMENT_CREATE_RATE_LIMIT_MAX=12

# MIDTRANS_SERVER_KEY stays backend-only. Never expose it as VITE_*.

# Optional for /api/ai-insight. Leave empty if AI insight is not used yet.
GEMINI_API_KEY=
SENTRY_DSN=
Expand All @@ -71,15 +57,25 @@ SENTRY_TRACES_SAMPLE_RATE=0
# Comma-separated. Leave empty to use sane defaults.
CORS_ORIGIN=http://localhost:5173,http://127.0.0.1:5173,http://localhost:4173,http://127.0.0.1:4173,https://kaffepos.my.id,https://www.kaffepos.my.id,https://api.kaffepos.my.id,capacitor://localhost,https://localhost,http://localhost

# Payment provider abstraction (Mayar Headless API v2 — https://docs.mayar.id)
# ── Payment gateway: Mayar Headless API v2 (https://docs.mayar.id) ─────────
# Panduan lengkap: docs/engineering/MAYAR_INTEGRATION_GUIDE.md
# Semua MAYAR_* bersifat backend-only. Jangan pernah dibuat sebagai VITE_*.
PAYMENT_GATEWAY_PROVIDER=mayar
PAYMENT_INTEGRATION_ENABLED=true
# sandbox → key dari https://web.mayar.io/api-keys (API https://api.mayar.io/hl/v2)
# production → key dari https://web.mayar.id/api-keys (API https://api.mayar.id/hl/v2)
MAYAR_ENVIRONMENT=sandbox
# 1) API key (Bearer) untuk create payment & cek status.
MAYAR_API_KEY=change-me
# 2) Web Token dari dashboard Mayar. Mayar mengirimnya di header X-Callback-Token.
# (Akun tanpa Web Token: pakai token sendiri dan tambahkan ?token=... di URL webhook.)
MAYAR_WEBHOOK_TOKEN=change-me
MAYAR_SANDBOX_BASE_URL=https://api.mayar.club
MAYAR_SANDBOX_BASE_URL=https://api.mayar.io
MAYAR_PRODUCTION_BASE_URL=https://api.mayar.id
MAYAR_REDIRECT_URL=https://kaffepos.my.id/settings?billing=mayar-return
# 3) URL webhook yang didaftarkan di Mayar → Integrasi → Webhook.
MAYAR_CALLBACK_URL=https://api.kaffepos.my.id/api/webhooks/mayar
SUBSCRIPTION_PAYMENT_MODE=mayar_sandbox
MAYAR_REDIRECT_URL=https://kaffepos.my.id/settings?billing=mayar-return
MAYAR_PAYMENT_DUE_MINUTES=60
# auto = sandbox/production mengikuti MAYAR_ENVIRONMENT
SUBSCRIPTION_PAYMENT_MODE=auto
PII_ENCRYPTION_KEY=change-me-in-production
28 changes: 12 additions & 16 deletions backend/.env.staging.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ R2_STORAGE_ENABLED=false
ANALYTICS_SERVER_ENABLED=false

# B. Full staging required (production-candidate external provider verification)
# Required only when STAGING_PROFILE=full/unset.
MIDTRANS_IS_PRODUCTION=false
MIDTRANS_ENVIRONMENT=sandbox
MIDTRANS_SNAP_ENABLED=true
MIDTRANS_SERVER_KEY=SB-Mid-server-change-me
MIDTRANS_CLIENT_KEY=SB-Mid-client-change-me

# Required only when STAGING_PROFILE=full/unset. Payment keys: see the Mayar block below.
RESEND_API_KEY=re_change_me
RESEND_FROM_EMAIL=KaffePOS Staging <[email protected]>
[email protected]
Expand All @@ -48,19 +42,21 @@ ADMIN_COMMISSION_ENABLED=false
REFERRAL_COMMISSION_CREATION_ENABLED=false

# C. Optional integrations skipped in minimal mode
# Midtrans, Resend, Cloudflare/R2, GA4, and server analytics may remain placeholders in minimal staging.
# Mayar, Resend, Cloudflare/R2, GA4, and server analytics may remain placeholders in minimal staging.

# Mayar sandbox staging — Mayar is the ACTIVE payment gateway.
# Mayar sandbox staging — Mayar is the only payment gateway.
# The backend env schema (backend/src/core/env.ts) accepts:
# PAYMENT_GATEWAY_PROVIDER = mayar | doku | disabled
# SUBSCRIPTION_PAYMENT_MODE = auto | manual | disabled | mayar_sandbox | mayar_production | doku_sandbox | doku_production
# PAYMENT_GATEWAY_PROVIDER = mayar | disabled
# SUBSCRIPTION_PAYMENT_MODE = auto | manual | disabled | mayar_sandbox | mayar_production
# Guide: docs/engineering/MAYAR_INTEGRATION_GUIDE.md
PAYMENT_GATEWAY_PROVIDER=mayar
PAYMENT_INTEGRATION_ENABLED=true
MAYAR_ENVIRONMENT=sandbox
MAYAR_API_KEY=change-me
MAYAR_WEBHOOK_TOKEN=change-me
MAYAR_CALLBACK_URL=https://api.kaffepos.my.id/api/webhooks/mayar
MAYAR_REDIRECT_URL=https://kaffepos.my.id/settings?billing=mayar-return
MAYAR_SANDBOX_BASE_URL=https://api.mayar.io
MAYAR_CALLBACK_URL=https://staging-api.example.com/api/webhooks/mayar
MAYAR_REDIRECT_URL=https://staging.example.com/settings?billing=mayar-return
SUBSCRIPTION_PAYMENT_MODE=mayar_sandbox

# Payment staging profile (Mayar sandbox)
Expand All @@ -69,9 +65,9 @@ SUBSCRIPTION_PAYMENT_MODE=mayar_sandbox
# PAYMENT_INTEGRATION_ENABLED=true
# MAYAR_ENVIRONMENT=sandbox
# MAYAR_API_KEY=ISI_DARI_MAYAR
# MAYAR_WEBHOOK_TOKEN=ISI_DARI_MAYAR
# MAYAR_CALLBACK_URL=https://api.kaffepos.my.id/api/webhooks/mayar
# MAYAR_WEBHOOK_TOKEN=ISI_DENGAN_WEB_TOKEN_DARI_MAYAR
# MAYAR_CALLBACK_URL=https://staging-api.example.com/api/webhooks/mayar
# SUBSCRIPTION_PAYMENT_MODE=mayar_sandbox
#
# For production: MAYAR_ENVIRONMENT=production and SUBSCRIPTION_PAYMENT_MODE=mayar_production.
# Legacy Midtrans/Duitku keys are NOT read by the code and may be omitted.
# Legacy DOKU/Midtrans/Duitku keys are NOT read by the code and may be removed.
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"start:coolify": "node scripts/run-migrations.mjs && node dist/index.js",
"check": "npm run typecheck && npm run build",
"migrate": "node scripts/run-migrations.mjs",
"mayar:connect": "node scripts/mayar-connect.mjs",
"backup:critical": "node scripts/backup-critical-data.mjs",
"deploy:kds": "cd .. && bash scripts/deploy-kds-one-command.sh"
},
Expand Down
Loading
Loading