Files
smeta-web/static/payment_result.html
T

135 lines
7.1 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; max-width: calc(100vw - 32px); 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); }
.hint { color: var(--muted); font-size: .85rem; margin: -.6rem 0 1.2rem; line-height: 1.4; }
.btns { display: flex; flex-direction: column; gap: .5rem; }
.btns .ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btns .ghost:hover { background: var(--bg); }
.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>
<p class="hint" id="hint" hidden></p>
<div class="btns">
<button id="retry" class="ghost" hidden onclick="window.location.href='/?topup=1'">Попробовать снова</button>
<button onclick="window.location.href='/'">Вернуться в чат</button>
</div>
</div>
<script>
// Страница — только показ: деньги зачисляют уведомление платёжки и сверка на сервере,
// даже если эту страницу закрыть. Опрос своего платежа раз в 3 с до 2 минут.
const params = new URLSearchParams(window.location.search);
let topupId = params.get('t') || '';
try { if (!topupId) topupId = localStorage.getItem('last_topup_id') || ''; } catch (e) {}
// Старые платежи (до пополнения): payment_id → прежняя ручка статуса.
let legacyId = params.get('payment_id') || '';
try { if (!topupId && !legacyId) legacyId = localStorage.getItem('last_payment_id') || ''; } catch (e) {}
let token = '';
try { token = localStorage.getItem('token') || ''; } catch (e) {}
const statusEl = document.getElementById('status');
const hintEl = document.getElementById('hint');
const spinnerEl = document.getElementById('spinner');
const UNKNOWN = 'Не удалось проверить платёж. Если деньги списались — они появятся на счёте ' +
'в течение часа; если нет — напишите на info@infosmeta.ru.';
const WAITING = 'Банк ещё подтверждает платёж. Деньги появятся на счёте сами, страницу можно закрыть.';
let tries = 0;
function rub(v) {
return Number(v).toLocaleString('ru-RU', {minimumFractionDigits: 0, maximumFractionDigits: 2}) + ' ₽';
}
function show(text, cls, hint) {
statusEl.textContent = text;
statusEl.className = 'status' + (cls ? ' ' + cls : '');
if (cls !== undefined) spinnerEl.style.display = 'none';
hintEl.hidden = !hint;
hintEl.textContent = hint || '';
}
async function pollTopup() {
if (!token) { show(UNKNOWN, 'fail', 'Войдите на сайт — состояние платежа обновится.'); return; }
try {
const r = await fetch('/api/topups/' + encodeURIComponent(topupId),
{headers: {'Authorization': 'Bearer ' + token}, cache: 'no-store'});
if (r.status === 401 || r.status === 404 || r.status === 400) { show(UNKNOWN, 'fail'); return; }
if (r.ok) {
const d = await r.json();
if (d.status === 'succeeded') {
try { localStorage.removeItem('last_topup_id'); } catch (e) {}
show('Зачислено ' + rub(d.amount_rub) + '.', 'ok',
d.balance_rub === null || d.balance_rub === undefined ? '' : 'На счёте ' + rub(d.balance_rub));
return;
}
if (d.status === 'canceled') {
document.getElementById('retry').hidden = false;
show('Оплата не прошла, деньги не списаны.', 'fail');
return;
}
if (d.status === 'refunded') { show('По этому платежу оформлен возврат.', 'fail'); return; }
if (d.status === 'failed') { show(UNKNOWN, 'fail'); return; }
show(WAITING);
}
} catch (e) { /* сеть моргнула — следующая попытка */ }
tries++;
if (tries >= 40) { show(WAITING, ''); return; }
setTimeout(pollTopup, 3000);
}
async function pollLegacy() {
if (!token) { show(UNKNOWN, 'fail'); return; }
try {
const r = await fetch('/api/payments/status?payment_id=' + encodeURIComponent(legacyId),
{headers: {'Authorization': 'Bearer ' + token}});
if (!r.ok) { show(UNKNOWN, '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) { show(WAITING, ''); return; }
setTimeout(pollLegacy, 3000);
}
if (topupId) pollTopup();
else if (legacyId) pollLegacy();
else show(UNKNOWN, 'fail');
</script>
</body>
</html>