Skip to content

Instantly share code, notes, and snippets.

@MarceloPrado
Last active January 15, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarceloPrado/25d0046defa8cbaad77e8336bc8ade49 to your computer and use it in GitHub Desktop.
Save MarceloPrado/25d0046defa8cbaad77e8336bc8ade49 to your computer and use it in GitHub Desktop.
postback test
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