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
+33 -8

No files matched your search

+25 -6
View File
@@ -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);
}