Last active
January 15, 2019 13:56
-
-
Save MarceloPrado/25d0046defa8cbaad77e8336bc8ade49 to your computer and use it in GitHub Desktop.
postback test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const boletoTransactionSchema = { | |
body: Joi.object() | |
.keys({ | |
model: Joi.string().valid('transaction'), | |
model_id: Joi.string().required(), | |
payload: Joi.string().required() | |
}) | |
.unknown(true) // permite outros campos além dos definidos acima | |
} | |
router.post( | |
'/boleto/status', | |
celebrateSchema(boletoTransactionSchema), | |
asyncMiddleware.wrapAsync(async (req, res, next) => { | |
try { | |
const { model_id: modelId, payload } = req.body | |
const boletoStatus = querystring.parse(payload).current_status | |
// Ações internas nossas ocultadas para diminuir código | |
if (boletoStatus === 'paid') { | |
// Boleto pago | |
} else if (boletoStatus === 'refused') { | |
// Boleto expirado | |
} else { | |
// outro status do Boleto | |
} | |
res.status(200).json({ success: true }) | |
} catch (e) { | |
res.status(500).json({ success: false }) | |
} | |
}) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment