feat: webhook MP (IPN) com polling como fallback
build-image / build-push (push) Successful in 1m39s

This commit is contained in:
jfeng committed 2026-10-21 18:13:15 -03:00
1 parent 286e9bd9d6
commit aec109e654
3 files changed
+20 -1

No files matched your search

+18
View File
@@ -87,6 +87,24 @@ app.post('/api/checkout', async (req, res) => {
} }
}); });
// ===== Webhook MP (IPN): confirma pagamento na hora =====
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.query?.['data.id'];
if (!mpId) return;
const payment = getDb().payments.find((p) => String(p.mpId) === String(mpId));
if (!payment) {
console.log(`[WEBHOOK] pagamento MP ${mpId} nao localizado`);
return;
}
await checkPayment(payment);
console.log(`[WEBHOOK] ${mpId} -> ${payment.status}`);
} catch (e) {
console.error('[WEBHOOK]', e.message);
}
});
app.get('/api/status/:id', async (req, res) => { app.get('/api/status/:id', async (req, res) => {
const payment = getDb().payments.find((p) => p.id === req.params.id); const payment = getDb().payments.find((p) => p.id === req.params.id);
if (!payment) return res.status(404).json({ error: 'nao encontrado' }); if (!payment) return res.status(404).json({ error: 'nao encontrado' });
+1
View File
@@ -20,6 +20,7 @@ export async function createPixPayment(amount, reference, description) {
payment_method_id: 'pix', payment_method_id: 'pix',
external_reference: reference, external_reference: reference,
description, description,
notification_url: config.baseUrl + '/api/mp/webhook',
payer: { email: '[email protected]' }, payer: { email: '[email protected]' },
}, },
}); });
+1 -1
View File
@@ -23,7 +23,7 @@ services:
# ===== MikroTik ===== # ===== MikroTik =====
MIKROTIK_HOST: "192.168.3.81" # IP do hAP lite na sua rede MIKROTIK_HOST: "192.168.3.81" # IP do hAP lite na sua rede
MIKROTIK_PORT: "8728" MIKROTIK_PORT: "8728"
MIKROTIK_USER: "admin" MIKROTIK_USER: "api-pix"
MIKROTIK_PASSWORD: "" MIKROTIK_PASSWORD: ""
MIKROTIK_SERVER: "guest-hotspot" # nome do servidor hotspot MIKROTIK_SERVER: "guest-hotspot" # nome do servidor hotspot