From 9d2b0f6164e1b407026dd3d12f24463843765793 Mon Sep 17 00:00:00 2001 From: Wisley Alves Date: Tue, 12 Sep 2023 14:21:14 -0300 Subject: [PATCH] fix(galaxpay-webhook): prevent error in case of undefined plan --- functions/routes/galaxpay/webhooks.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/functions/routes/galaxpay/webhooks.js b/functions/routes/galaxpay/webhooks.js index 06a7183..8ea940e 100644 --- a/functions/routes/galaxpay/webhooks.js +++ b/functions/routes/galaxpay/webhooks.js @@ -169,9 +169,11 @@ exports.post = async ({ appSdk, admin }, req, res) => { ? plan.discount.type === 'percentage' || plan.discount.percentage : null let notes = `Parcela #${quantity} desconto de ${planPergentage ? '' : 'R$'}` - notes += ` ${plan.discount.value} ${planPergentage ? '%' : ''}` - notes += ` sobre ${plan.discount.apply_at}` - notes += ` referente à ${subscriptionLabel} ${periodicity}` + if (planPergentage) { + notes += ` ${plan?.discount?.value || ''} ${planPergentage ? '%' : ''}` + notes += ` sobre ${plan?.discount?.apply_at || ''}` + notes += ` referente à ${subscriptionLabel} ${periodicity}` + } body = { opened_at: new Date().toISOString(),