From 63994df1e4b9f8d1eadbc6b650b55cf380431d2a Mon Sep 17 00:00:00 2001 From: oxpoe Date: Mon, 12 Oct 2026 22:20:48 +0700 Subject: [PATCH] feat: toggle fitur voucher (setting voucher_enabled) + gate route & sembunyikan link --- routes/adminPortal.js | 2 ++ routes/customerPortal.js | 6 ++++++ views/admin/settings.ejs | 13 +++++++++++++ views/login.ejs | 9 +++++---- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/routes/adminPortal.js b/routes/adminPortal.js index 12898b2..6bf0064 100644 --- a/routes/adminPortal.js +++ b/routes/adminPortal.js @@ -4732,6 +4732,8 @@ router.post('/settings', requireAdminSession, express.urlencoded({ extended: tru const newSettings = { ...req.body }; if (newSettings.whatsapp_enabled === 'true') newSettings.whatsapp_enabled = true; else if (newSettings.whatsapp_enabled === 'false') newSettings.whatsapp_enabled = false; + if (newSettings.voucher_enabled === 'true') newSettings.voucher_enabled = true; + else if (newSettings.voucher_enabled === 'false') newSettings.voucher_enabled = false; if (newSettings.qris_static_enabled === 'true') newSettings.qris_static_enabled = true; else if (newSettings.qris_static_enabled === 'false') newSettings.qris_static_enabled = false; diff --git a/routes/customerPortal.js b/routes/customerPortal.js index b6aef40..b988515 100644 --- a/routes/customerPortal.js +++ b/routes/customerPortal.js @@ -2,6 +2,7 @@ const express = require('express'); const router = express.Router(); const customerDevice = require('../services/customerDeviceService'); const { getSettingsWithCache, getNowLocal, getCurrentTimeInfo, getNowLocalISO, formatDateLocal, formatTimeLocal } = require('../config/settingsManager'); +function voucherFeatureOn() { try { const s = getSettingsWithCache() || {}; const v = s.voucher_enabled; return !(v === false || v === 'false' || v === '0' || v === 0); } catch (e) { return true; } } const noticeSvc = require('../services/serviceNoticeService'); const ssidChangeCooldown = new Map(); // key: customer id / loginId -> timestamp terakhir ubah SSID const registrationService = require('../services/registrationService'); @@ -890,6 +891,7 @@ router.get('/check-billing', async (req, res) => { let _voucherLastGoodProfiles = null; router.get('/voucher', async (req, res) => { + if (!voucherFeatureOn()) return res.redirect('/customer/login?err=' + encodeURIComponent('Fitur voucher sedang dinonaktifkan')); const settings = getSettingsWithCache(); const error = String(req.query.err || '').trim() || null; const info = String(req.query.info || '').trim() || null; @@ -1149,6 +1151,7 @@ router.get('/voucher', async (req, res) => { }); router.get('/voucher/qris/:orderId', async (req, res) => { + if (!voucherFeatureOn()) return res.redirect('/customer/login?err=' + encodeURIComponent('Fitur voucher sedang dinonaktifkan')); const settings = getSettingsWithCache(); const orderId = Number(req.params.orderId || 0); const secret = settings.session_secret || 'rahasia-portal-pelanggan-default-ganti-ini'; @@ -1196,6 +1199,7 @@ router.get('/voucher/qris/:orderId', async (req, res) => { }); // API endpoint untuk cek status voucher order (untuk auto-polling di halaman QRIS) router.get('/voucher/status/:orderId', async (req, res) => { + if (!voucherFeatureOn()) return res.json({ success: false, status: 'disabled', message: 'Fitur voucher dinonaktifkan' }); const settings = getSettingsWithCache(); const orderId = Number(req.params.orderId || 0); const secret = settings.session_secret || 'rahasia-portal-pelanggan-default-ganti-ini'; @@ -1224,6 +1228,7 @@ router.get('/voucher/status/:orderId', async (req, res) => { router.post('/public/voucher/create-payment', async (req, res) => { + if (!voucherFeatureOn()) return res.status(403).json({ success: false, message: 'Fitur voucher dinonaktifkan' }); const settings = getSettingsWithCache(); const buyerPhone = normalizeBuyerPhone(req.body.buyer_phone); @@ -3352,6 +3357,7 @@ router.post('/payment/proof/:invoiceId', uploadProof.single('proof'), async (req }); router.post('/voucher/proof/:orderId', uploadProof.single('proof'), async (req, res) => { + if (!voucherFeatureOn()) return res.redirect('/customer/login?err=' + encodeURIComponent('Fitur voucher sedang dinonaktifkan')); const settings = getSettingsWithCache(); const secret = settings.session_secret || 'rahasia-portal-pelanggan-default-ganti-ini'; const token = String(req.body && req.body.token ? req.body.token : '').trim(); diff --git a/views/admin/settings.ejs b/views/admin/settings.ejs index 9caa585..06c8a3e 100644 --- a/views/admin/settings.ejs +++ b/views/admin/settings.ejs @@ -432,6 +432,19 @@ + +
+
Fitur Opsional
+
+ + +
Nonaktifkan untuk menyembunyikan halaman Beli Voucher publik (mis. saat deploy).
+
+
+
Integrasi WhatsApp
diff --git a/views/login.ejs b/views/login.ejs index b988beb..5355da6 100644 --- a/views/login.ejs +++ b/views/login.ejs @@ -1,5 +1,6 @@ +<% const voucherOn = !(settings && (settings.voucher_enabled === false || settings.voucher_enabled === 'false' || settings.voucher_enabled === '0' || settings.voucher_enabled === 0)); %> @@ -41,7 +42,7 @@ Paket <%= t('landing.nav.features','Keunggulan') %> <%= t('landing.hero.check','Cek Tagihan') %> - <%= t('login.voucher_nav','Voucher') %> + <% if (voucherOn) { %><%= t('login.voucher_nav','Voucher') %><% } %> <% if (typeof settings !== 'undefined' && settings && settings.status_url) { %>Status<% } %> @@ -120,7 +121,7 @@