Skip to content

Instantly share code, notes, and snippets.

@devjaime
Created April 2, 2021 15:52
Show Gist options
  • Select an option

  • Save devjaime/eccfec3dc48573cb8c25bab1476bdcfc to your computer and use it in GitHub Desktop.

Select an option

Save devjaime/eccfec3dc48573cb8c25bab1476bdcfc to your computer and use it in GitHub Desktop.
Cree otra función de nube HTTP para manejar webhooks.
exports.webhookHandler = functions.https.onRequest(async (req, res) => {
const rawBody = req.rawBody;
const signature = req.headers['x-cc-webhook-signature'];
const webhookSecret = 'your webhook';
try {
const event = Webhook.verifyEventBody(rawBody, signature, webhookSecret);
if (event.type === 'charge:pending') {
// TODO
// El usuario pago pero la transacción aún no se ha confirmado en blockchain
}
if (event.type === 'charge:confirmed') {
// TODO
// Todo bien, se confirmo correctamente la transacción
}
if (event.type === 'charge:failed') {
// TODO
// A falllado o caducado
}
res.send(`success ${event.id}`);
} catch (error) {
functions.logger.error(error);
res.status(400).send('failure!');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment