-
-
Save devjaime/eccfec3dc48573cb8c25bab1476bdcfc to your computer and use it in GitHub Desktop.
Cree otra función de nube HTTP para manejar webhooks.
This file contains hidden or 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
| 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