Created
May 15, 2020 12:00
-
-
Save Joe8Bit/732045d33393f525797a25ea59231ab4 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
function createStripePaymentRequest(req, res) { | |
const cors = require('cors')({ | |
origin: true, | |
}); | |
return cors(req, res, () => { | |
const functions = require('firebase-functions'); | |
const stripe = require('stripe')(functions.config().stripe.secret_key); | |
const recordPayment = require('../shared/recordPayment'); | |
const payerName = req.body.payerName; | |
const payerEmail = req.body.payerEmail; | |
const amount = parseInt(req.body.amount, 10) | |
let sessionId | |
return stripe.checkout.sessions.create( | |
{ | |
success_url: functions.config().heroes.success_url, | |
cancel_url: functions.config().heroes.error_url, | |
payment_method_types: ['card'], | |
customer_email: payerEmail, | |
line_items: [ | |
{ | |
name: 'Heroes Donation', | |
amount: amount, | |
currency: 'gbp', | |
quantity: 1, | |
}, | |
], | |
} | |
) | |
.then((data) => { | |
sessionId = data.id; | |
return recordPayment({ provider: 'stripe', id: data.payment_intent, payerName, payerEmail, amount }) | |
}) | |
.then((id) => { | |
return res.json({ sessionId }); | |
}); | |
}) | |
} | |
module.exports = createStripePaymentRequest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment