Created
January 6, 2022 06:00
-
-
Save MacoChave/3e551c7aaa3e61db0bc54e494025e434 to your computer and use it in GitHub Desktop.
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 stripe = require('stripe')('STRIPE_KEY'); | |
exports.handler = async function(req,ctx,callback) { | |
const stripeToken = req.stripeToken | |
const cantidad = req.cantidad | |
const descripcion = req.descripcion | |
const cantidadInDollar = Math.round(cantidad) | |
const chargeObject = await stripe.charges.create({ | |
amount: cantidadInDollar, | |
currency: 'usd', | |
source: stripeToken, | |
capture: false, | |
description: descripcion, | |
receipt_email: 'ENCARGADO@EMPRESA.COM' | |
}) | |
// AGREGAR TRANSACCIÓN A BD | |
try { | |
await stripe.charges.capture(chargeObject.id) | |
callback({success: 'True', message: 'Pago realizado con éxito'}) | |
} catch (error) { | |
await stripe.charges.refunds.create({ charge: chargeObject.id }) | |
callback({success: 'False', message: 'Problemas con el pago, se le devolvió el monto'}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment