107 lines
6.3 KiB
HTML
107 lines
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Оплата — Сметный ИИ-ассистент</title>
|
|
<style>
|
|
:root { --bg: #f5f0eb; --card: #fff; --text: #3a3a3a; --muted: #6b6b6b; --accent: #c4463a; --border: #d4c5b2; --radius: 10px; --green: #2d8a56; }
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; display: flex; align-items: center; justify-content: center; }
|
|
.card { background: var(--card); border-radius: var(--radius); padding: 2rem; width: 380px; box-shadow: 0 2px 12px rgba(0,0,0,.08); text-align: center; }
|
|
h1 { font-size: 1.2rem; margin-bottom: .3rem; }
|
|
.subtitle { color: var(--muted); font-size: .85rem; margin-bottom: 1.5rem; }
|
|
.status { font-size: .95rem; margin-bottom: 1.2rem; line-height: 1.45; }
|
|
.status.ok { color: var(--green); font-weight: 600; }
|
|
.status.fail { color: var(--accent); }
|
|
.spinner { width: 28px; height: 28px; margin: 0 auto 1rem; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
button { width: 100%; padding: .7rem; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: .95rem; font-weight: 600; cursor: pointer; }
|
|
button:hover { background: #a83830; }
|
|
|
|
/* ===== Тёмная тема (общая с чатом; выбор в localStorage['theme']) ===== */
|
|
html { color-scheme: light; }
|
|
:root[data-theme="dark"] {
|
|
color-scheme: dark;
|
|
--bg: #16140f; --card: #211d17; --text: #ece4d7; --muted: #a89c8a;
|
|
--accent: #d9695c; --border: #3a332a; --green: #3fa066;
|
|
}
|
|
:root[data-theme="dark"] .card { box-shadow: 0 2px 16px rgba(0,0,0,.5); }
|
|
:root[data-theme="dark"] button:hover { background: #c2564a; }
|
|
</style>
|
|
<script>
|
|
(function(){try{var t=localStorage.getItem('theme');if(t!=='dark'&&t!=='light'){t=(window.matchMedia&&matchMedia('(prefers-color-scheme: dark)').matches)?'dark':'light';}document.documentElement.setAttribute('data-theme',t);}catch(e){}})();
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<div class="card">
|
|
<h1>Оплата</h1>
|
|
<p class="subtitle">Сметный ИИ-ассистент</p>
|
|
<div class="spinner" id="spinner"></div>
|
|
<div class="status" id="status">Проверяем оплату…</div>
|
|
<button onclick="window.location.href='/'">Вернуться в чат</button>
|
|
</div>
|
|
|
|
<script>
|
|
// Страница — ТОЛЬКО UX: поллинг статуса СВОЕГО платежа. Доступ выдаёт сервер
|
|
// (вебхук/сверка), даже если эту страницу закрыть — оплата не потеряется.
|
|
const params = new URLSearchParams(window.location.search);
|
|
// payment_id: из query (если положили в return_url вручную) или из localStorage —
|
|
// кнопка «Оплатить» сохраняет его перед редиректом на ЮKassa.
|
|
const paymentId = params.get('payment_id') || localStorage.getItem('last_payment_id') || '';
|
|
const token = localStorage.getItem('token') || '';
|
|
const statusEl = document.getElementById('status');
|
|
const spinnerEl = document.getElementById('spinner');
|
|
let tries = 0;
|
|
|
|
function show(text, cls) {
|
|
statusEl.textContent = text;
|
|
statusEl.className = 'status' + (cls ? ' ' + cls : '');
|
|
if (cls) spinnerEl.style.display = 'none';
|
|
}
|
|
|
|
async function poll() {
|
|
if (!paymentId) { show('Платёж не найден. Если вы оплатили — доступ включится автоматически в течение нескольких минут.', 'fail'); return; }
|
|
if (!token) { show('Вы не вошли в систему. Войдите — статус оплаты обновится автоматически.', 'fail'); return; }
|
|
try {
|
|
const r = await fetch('/api/payments/status?payment_id=' + encodeURIComponent(paymentId),
|
|
{headers: {'Authorization': 'Bearer ' + token}});
|
|
if (r.status === 401) { show('Сессия истекла. Войдите заново — оплата не потеряется.', 'fail'); return; }
|
|
if (!r.ok) { show('Платёж не найден. Если деньги списались — доступ включится автоматически.', 'fail'); return; }
|
|
const d = await r.json();
|
|
if (d.status === 'succeeded') { show('Оплата прошла! Агентные функции активированы.', 'ok'); return; }
|
|
if (d.status === 'canceled') { show('Оплата не завершена (отменена или отклонена). Деньги не списаны.', 'fail'); return; }
|
|
if (d.status === 'refunded') { show('По этому платежу оформлен возврат.', 'fail'); return; }
|
|
} catch (e) { /* сеть моргнула — следующая попытка */ }
|
|
tries++;
|
|
if (tries >= 40) { // ~2 минуты: вебхук мог задержаться — доберёт фоновая сверка
|
|
show('Оплата ещё обрабатывается. Доступ включится автоматически — можно вернуться в чат.', '');
|
|
return;
|
|
}
|
|
setTimeout(poll, 3000);
|
|
}
|
|
poll();
|
|
</script>
|
|
<!-- Переключатель темы — тот же на всех страницах (сказал Хозяин 18.11) -->
|
|
<style>
|
|
#theme-fab { position: fixed; top: .8rem; right: .8rem; width: 38px; height: 38px; border-radius: 50%;
|
|
border: 1.5px solid var(--border, #ddd0bf); background: var(--card, var(--bg-card, #fff));
|
|
color: var(--text, #2b2926); cursor: pointer; font-size: 1rem; line-height: 1; z-index: 50; }
|
|
</style>
|
|
<button id="theme-fab" onclick="toggleTheme()" title="Светлая / тёмная тема" aria-label="Переключить тему">☾</button>
|
|
<script>
|
|
function toggleTheme() {
|
|
var n = document.documentElement.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';
|
|
document.documentElement.setAttribute('data-theme', n);
|
|
try { localStorage.setItem('theme', n); } catch (e) {}
|
|
applyThemeIcon();
|
|
}
|
|
function applyThemeIcon() {
|
|
var b = document.getElementById('theme-fab');
|
|
if (b) b.textContent = document.documentElement.getAttribute('data-theme') === 'dark' ? '☀' : '☾';
|
|
}
|
|
applyThemeIcon();
|
|
</script>
|
|
</body>
|
|
</html>
|