feat: implement secure OTP-based payout workflow with dynamic fee calculation and improved authentication checks
This commit is contained in:
@@ -10,13 +10,20 @@ error_reporting(E_ALL);
|
||||
ini_set('display_errors', '1');
|
||||
|
||||
// ── Load .env ──
|
||||
$loadedFiles = [];
|
||||
function loadEnvFile(string $path): void {
|
||||
if (!file_exists($path)) return;
|
||||
global $loadedFiles;
|
||||
if (!file_exists($path)) {
|
||||
$loadedFiles[] = "NOT_FOUND: $path";
|
||||
return;
|
||||
}
|
||||
$loadedFiles[] = "LOADED: $path";
|
||||
foreach (file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
||||
$line = trim($line);
|
||||
if (empty($line) || $line[0] === '#' || strpos($line, '=') === false) continue;
|
||||
[$name, $value] = explode('=', $line, 2);
|
||||
putenv(trim($name) . '=' . trim($value, "\"'"));
|
||||
$_ENV[trim($name)] = trim($value, "\"'");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,10 +39,10 @@ function getJwtSecret(): string {
|
||||
return trim(file_get_contents($keyPath));
|
||||
}
|
||||
// Priority 2: JWT_SECRET_KEY env var
|
||||
$key = getenv('JWT_SECRET_KEY');
|
||||
$key = getenv('JWT_SECRET_KEY') ?: ($_ENV['JWT_SECRET_KEY'] ?? '');
|
||||
if ($key) return $key;
|
||||
// Priority 3: JWT_SECRET env var (backend .env uses this)
|
||||
$key = getenv('JWT_SECRET');
|
||||
$key = getenv('JWT_SECRET') ?: ($_ENV['JWT_SECRET'] ?? '');
|
||||
if ($key) return $key;
|
||||
return '';
|
||||
}
|
||||
@@ -55,8 +62,9 @@ function generate_jwt(string $secret, array $payload): string {
|
||||
// ── Main ──
|
||||
$secret = getJwtSecret();
|
||||
if (empty($secret)) {
|
||||
echo json_encode(['error' => 'JWT secret not found in any .env', 'jwt' => '']);
|
||||
exit(1);
|
||||
echo json_encode(['error' => 'JWT secret not found in any .env', 'files_checked' => $loadedFiles, 'jwt' => '']);
|
||||
// Do not exit with 1 so Node.js can print the JSON error
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$driverId = $argv[1] ?? '999999';
|
||||
|
||||
Reference in New Issue
Block a user