<?php header('Content-Type: application/json'); $keysPath = '/var/www/private/payment_server_keys.php'; if (!file_exists($keysPath)) { http_response_code(500); exit(json_encode(['error' => 'Keys missing'])); } $keys = require $keysPath; try { $serverSecret = sodium_base642bin($keys['server_secret'], SODIUM_BASE64_VARIANT_ORIGINAL); $clientPublic = sodium_base642bin($keys['client_public'], SODIUM_BASE64_VARIANT_ORIGINAL); } catch (\Throwable $e) { http_response_code(500); exit(json_encode(['error' => 'Key decode error'])); } $input = json_decode(file_get_contents('php://input'), true); if (!isset($input['data'])) { http_response_code(400); exit(json_encode(['error' => 'No data'])); } $raw = sodium_base642bin($input['data'], SODIUM_BASE64_VARIANT_ORIGINAL); if (strlen($raw) < SODIUM_CRYPTO_BOX_NONCEBYTES) { http_response_code(400); exit(json_encode(['error' => 'Too short'])); } $nonce = substr($raw, 0, SODIUM_CRYPTO_BOX_NONCEBYTES); $cipher = substr($raw, SODIUM_CRYPTO_BOX_NONCEBYTES); $keypair = sodium_crypto_box_keypair_from_secretkey_and_publickey($serverSecret, $clientPublic); $decrypted = sodium_crypto_box_open($cipher, $nonce, $keypair); if ($decrypted === false) { http_response_code(403); exit(json_encode(['error' => 'Decrypt failed'])); } $request = json_decode($decrypted, true); $method = $request['method'] ?? ''; $payload = $request['payload'] ?? []; define('DASHBOARD_ROOT', '/var/www/dashboard'); require_once '/var/www/shared/db.php';