Skip to content

Instantly share code, notes, and snippets.

@ghaffaru
Last active July 25, 2021 05:15
Show Gist options
  • Save ghaffaru/7e2e1f20269a3bd468c43c9e3b52799e to your computer and use it in GitHub Desktop.
Save ghaffaru/7e2e1f20269a3bd468c43c9e3b52799e to your computer and use it in GitHub Desktop.
const axios = require('axios')
const Payment = require('../models/Payment');
module.exports =
{
payInitialize : function (req, res, email, localId) {
axios
.post(
"https://api.paystack.co/transaction/initialize",
{
email: email,
amount: "1190",
currency: "GHS",
callback_url: "https://blustream.live/",
},
{
headers: {
Authorization: `Bearer ${process.env.PAYSTACK_SECRET_KEY}`,
},
}
)
.then((response3) => {
let payment = new Payment({
eventKey: req.body.eventKey,
amount: 11.9,
userKey: localId,
reference: response3.data.data.reference,
});
payment
.save()
.then(() => {
return res.status(200).json({ message: response3.data });
})
.catch((err3) => {
return res.status(500).json({ message: "Could not process payment" });
});
})
.catch((err2) => {
console.log(err2);
return res.status(500).json({ message: "Could not process payment" });
});
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment