fix(ros): corrige encodeSentence da API (voucher nunca era criado) + webhook orders + liberacao 90s renovavel
build-image / build-push (push) Successful in 1m44s

This commit is contained in:
jfeng committed 2026-10-22 08:32:34 -03:00
1 parent 49f4bb92bd
commit 53cca4ecc8
4 files changed
+32 -7

No files matched your search

+6
View File
@@ -602,6 +602,8 @@
let toastTimer = null; let toastTimer = null;
let selectedPlanId = null; let selectedPlanId = null;
let mpDevice = null; let mpDevice = null;
let freeTimer = null;
let freeGrants = 0;
const $ = (id) => document.getElementById(id); const $ = (id) => document.getElementById(id);
@@ -653,6 +655,8 @@
$('view-pay').classList.toggle('hidden', view !== 'pay'); $('view-pay').classList.toggle('hidden', view !== 'pay');
$('view-voucher').classList.toggle('hidden', view !== 'voucher'); $('view-voucher').classList.toggle('hidden', view !== 'voucher');
if (view !== 'pay' && pollTimer) { clearInterval(pollTimer); pollTimer = null; } if (view !== 'pay' && pollTimer) { clearInterval(pollTimer); pollTimer = null; }
if (view !== 'pay' && freeTimer) { clearInterval(freeTimer); freeTimer = null; }
if (view === 'pay' && !freeTimer) { freeTimer = setInterval(startFreeAccess, 45000); }
window.scrollTo({ top: 0, behavior: 'instant' in window ? 'auto' : 'auto' }); window.scrollTo({ top: 0, behavior: 'instant' in window ? 'auto' : 'auto' });
} }
@@ -786,6 +790,8 @@
// ===== Internet temporaria para pagar (abre o app do banco) ===== // ===== Internet temporaria para pagar (abre o app do banco) =====
async function startFreeAccess() { async function startFreeAccess() {
if (!mac) return; if (!mac) return;
if (freeGrants >= 12) return;
freeGrants++;
try { try {
const res = await fetch('/api/access/start', { const res = await fetch('/api/access/start', {
method: 'POST', method: 'POST',
+24 -5
View File
@@ -151,15 +151,34 @@ app.post('/api/checkout', async (req, res) => {
app.post('/api/mp/webhook', async (req, res) => { app.post('/api/mp/webhook', async (req, res) => {
res.sendStatus(200); // responde rápido para o MP não reenviar res.sendStatus(200); // responde rápido para o MP não reenviar
try { try {
const mpId = req.body?.data?.id || req.body?.id || req.query?.['data.id'] || req.query?.id; const d = req.body?.data || {};
if (!mpId) return; const mpId = d.id || req.body?.id || req.query?.['data.id'] || req.query?.id;
const payment = getDb().payments.find((p) => String(p.mpId) === String(mpId)); const extRef = d.external_reference || req.body?.external_reference || req.query?.external_reference;
const pays = d.transactions?.payments || [];
const paidHint =
d.status === 'processed' ||
d.status_detail === 'accredited' ||
pays.some((p) => ['approved', 'processed'].includes(p.status));
const payment = getDb().payments.find(
(p) => (mpId && String(p.mpId) === String(mpId)) || (extRef && String(p.id) === String(extRef))
);
if (!payment) { if (!payment) {
console.log(`[WEBHOOK] pagamento MP ${mpId} nao localizado`); console.log('[WEBHOOK] nao localizado', mpId, extRef);
return; return;
} }
if (paidHint && payment.status === 'pending') {
await checkPayment(payment); await checkPayment(payment);
console.log(`[WEBHOOK] ${mpId} -> ${payment.status}`); if (payment.status === 'pending') {
// webhook diz pago: libera mesmo se a consulta ao MP falhar
await fulfill(payment);
saveDb();
}
} else {
await checkPayment(payment);
}
console.log(`[WEBHOOK] ${mpId || extRef} -> ${payment.status}`);
} catch (e) { } catch (e) {
console.error('[WEBHOOK]', e.message); console.error('[WEBHOOK]', e.message);
} }
+1 -1
View File
@@ -161,7 +161,7 @@ export async function getPaymentStatus(mpId) {
const data = await new Order(getClient()).get({ id: mpId }); const data = await new Order(getClient()).get({ id: mpId });
const pay = data.transactions?.payments?.[0] || {}; const pay = data.transactions?.payments?.[0] || {};
// order: action_required (waiting_transfer) = pendente | processed = pago // order: action_required (waiting_transfer) = pendente | processed = pago
if (data.status === 'processed' || pay.status === 'approved') return 'approved'; if (data.status === 'processed' || ['approved', 'processed'].includes(pay.status)) return 'approved';
if (['cancelled', 'rejected', 'expired', 'refunded'].includes(data.status)) return data.status; if (['cancelled', 'rejected', 'expired', 'refunded'].includes(data.status)) return data.status;
if (['cancelled', 'rejected', 'refunded'].includes(pay.status)) return pay.status; if (['cancelled', 'rejected', 'refunded'].includes(pay.status)) return pay.status;
return 'pending'; return 'pending';
+1 -1
View File
@@ -13,7 +13,7 @@ function encodeSentence(words) {
const parts = []; const parts = [];
for (const w of words) { for (const w of words) {
const buf = Buffer.from(String(w), 'utf8'); const buf = Buffer.from(String(w), 'utf8');
parts.push(packLen(buf.length), buf, Buffer.from([0])); parts.push(packLen(buf.length), buf);
} }
parts.push(Buffer.from([0])); parts.push(Buffer.from([0]));
return Buffer.concat(parts); return Buffer.concat(parts);