fix(ros): corrige encodeSentence da API (voucher nunca era criado) + webhook orders + liberacao 90s renovavel
build-image / build-push (push) Successful in 1m44s
build-image / build-push (push) Successful in 1m44s
This commit is contained in:
1 parent
49f4bb92bd
commit
53cca4ecc8
4 files changed
+33
-8
No files matched your search
@@ -602,6 +602,8 @@
|
||||
let toastTimer = null;
|
||||
let selectedPlanId = null;
|
||||
let mpDevice = null;
|
||||
let freeTimer = null;
|
||||
let freeGrants = 0;
|
||||
|
||||
const $ = (id) => document.getElementById(id);
|
||||
|
||||
@@ -653,6 +655,8 @@
|
||||
$('view-pay').classList.toggle('hidden', view !== 'pay');
|
||||
$('view-voucher').classList.toggle('hidden', view !== 'voucher');
|
||||
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' });
|
||||
}
|
||||
|
||||
@@ -786,6 +790,8 @@
|
||||
// ===== Internet temporaria para pagar (abre o app do banco) =====
|
||||
async function startFreeAccess() {
|
||||
if (!mac) return;
|
||||
if (freeGrants >= 12) return;
|
||||
freeGrants++;
|
||||
try {
|
||||
const res = await fetch('/api/access/start', {
|
||||
method: 'POST',
|
||||
|
||||
+25
-6
@@ -151,15 +151,34 @@ app.post('/api/checkout', async (req, res) => {
|
||||
app.post('/api/mp/webhook', async (req, res) => {
|
||||
res.sendStatus(200); // responde rápido para o MP não reenviar
|
||||
try {
|
||||
const mpId = req.body?.data?.id || req.body?.id || req.query?.['data.id'] || req.query?.id;
|
||||
if (!mpId) return;
|
||||
const payment = getDb().payments.find((p) => String(p.mpId) === String(mpId));
|
||||
const d = req.body?.data || {};
|
||||
const mpId = d.id || req.body?.id || req.query?.['data.id'] || req.query?.id;
|
||||
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) {
|
||||
console.log(`[WEBHOOK] pagamento MP ${mpId} nao localizado`);
|
||||
console.log('[WEBHOOK] nao localizado', mpId, extRef);
|
||||
return;
|
||||
}
|
||||
await checkPayment(payment);
|
||||
console.log(`[WEBHOOK] ${mpId} -> ${payment.status}`);
|
||||
|
||||
if (paidHint && payment.status === 'pending') {
|
||||
await checkPayment(payment);
|
||||
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) {
|
||||
console.error('[WEBHOOK]', e.message);
|
||||
}
|
||||
|
||||
+1
-1
@@ -161,7 +161,7 @@ export async function getPaymentStatus(mpId) {
|
||||
const data = await new Order(getClient()).get({ id: mpId });
|
||||
const pay = data.transactions?.payments?.[0] || {};
|
||||
// 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', 'refunded'].includes(pay.status)) return pay.status;
|
||||
return 'pending';
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ function encodeSentence(words) {
|
||||
const parts = [];
|
||||
for (const w of words) {
|
||||
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]));
|
||||
return Buffer.concat(parts);
|
||||
|
||||
Reference in new issue
Block a user