Created
May 15, 2020 11:57
-
-
Save Joe8Bit/e8700288de925255f3ae68a9b0e0958e 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 functions = require('firebase-functions'); | |
function createBankedPaymentRequest(req, res) { | |
const cors = require('cors')({ | |
origin: true, | |
}); | |
return cors(req, res, () => { | |
const payerName = req.body.payerName; | |
const payerEmail = req.body.payerEmail; | |
const amount = parseInt(req.body.amount, 10); | |
const recordPayment = require('../shared/recordPayment'); | |
const Banked = require('@banked/node'); | |
const banked = new Banked({ | |
api_key: functions.config().banked.key, | |
secret_key: functions.config().banked.secret, | |
}); | |
return banked.payments.create({ | |
line_items: [{ | |
amount_cents: amount, | |
currency: 'GBP', | |
name: 'Heroes Donation', | |
quantity: 1, | |
}], | |
payer: { | |
name: payerName, | |
email: payerEmail, | |
}, | |
payee: { | |
name: 'Heroes Fund', | |
account_number: functions.config().heroes.account_number, | |
sort_code: functions.config().heroes.sort_code, | |
}, | |
success_url: functions.config().heroes.success_url, | |
error_url: functions.config().heroes.error_url, | |
}) | |
.then(({ data }) => { | |
url = data.url; | |
return recordPayment({ provider: 'banked', id: data.id, payerName, payerEmail, amount }) | |
}) | |
.then((responseData) => { | |
return res.json({ url }); | |
}) | |
}) | |
} | |
module.exports = createBankedPaymentRequest; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment