Skip to content

Commit f6b9c6b

Browse files
committed
chore(mercadopago): Early return on webhook with unexpected body
1 parent a020869 commit f6b9c6b

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

packages/apps/mercadopago/src/mp-webhook.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ export const mercadopago = {
1717
const { method, body: notification } = req;
1818
if (method === 'POST' && notification) {
1919
logger.info('Webhook body', { notification });
20+
if (notification.type !== 'payment' || !notification.data?.id) {
21+
res.sendStatus(400);
22+
return;
23+
}
24+
logger.info(`MP Notification for Payment #${notification.data.id}`);
25+
2026
try {
2127
const app = (await api.get(
2228
`applications?app_id=${config.get().apps.mercadoPago.appId}&fields=hidden_data`,
@@ -31,15 +37,8 @@ export const mercadopago = {
3137
return;
3238
}
3339

34-
if (notification.type !== 'payment' || !notification.data?.id) {
35-
res.sendStatus(400);
36-
return;
37-
}
38-
logger.info(`MP Notification for Payment #${notification.data.id}`);
39-
4040
const docRef = getFirestore().collection('mercadopagoPayments')
4141
.doc(String(notification.data.id));
42-
4342
docRef.get()
4443
.then(async (doc) => {
4544
if (doc.exists) {

0 commit comments

Comments
 (0)