This commit is contained in:
DIGIDEV\corer committed 2026-10-20 13:16:38 +09:00
commit 3e4a056b14
67 files changed
+13926

No files matched your search

+43
View File
@@ -0,0 +1,43 @@
<?php
declare(strict_types=1);
// Calculation endpoint for the public calculator: GET ?n=<nominal>&t=<tenor>&c=perorangan|badan
// Visitors receive the customer-facing result only; a logged-in admin also gets
// the internal breakdown shown in "Rincian perhitungan".
require __DIR__ . '/includes/auth.php';
require __DIR__ . '/includes/engine.php';
try {
$admin = viewing_admin();
} catch (Throwable $ex) {
$admin = null;
}
send_security_headers($admin !== null);
header('Content-Type: application/json; charset=utf-8');
header('X-Robots-Tag: noindex');
function calc_reply(int $status, array $body): void
{
http_response_code($status);
echo json_encode($body, JSON_UNESCAPED_UNICODE | JSON_PRESERVE_ZERO_FRACTION);
exit;
}
$nominal = parse_idr($_GET['n'] ?? '');
$tenor = (int)input_str($_GET['t'] ?? '');
$cust = input_str($_GET['c'] ?? '') === 'badan' ? 'badan' : 'perorangan';
try {
$params = load_params();
} catch (Throwable $ex) {
error_log('[serubi] calc: ' . $ex->getMessage());
calc_reply(503, ['error' => 'Parameter tidak dapat dimuat.']);
}
if ($nominal === null || $nominal <= 0 || $nominal > 1e15) {
calc_reply(400, ['error' => 'Nominal tidak valid.']);
}
if (!in_array($tenor, $params['tenors'], true)) {
calc_reply(400, ['error' => 'Jangka waktu tidak valid.']);
}
$result = engine_calculate($params, $nominal, $tenor, $cust);
calc_reply(200, $admin ? $result : engine_public_result($result, $params));