Skip to content

Instantly share code, notes, and snippets.

@michaelO93
Last active February 13, 2017 12:39
Show Gist options
  • Save michaelO93/4a4a2ee02addd63f85aa2a91a7e67515 to your computer and use it in GitHub Desktop.
Save michaelO93/4a4a2ee02addd63f85aa2a91a7e67515 to your computer and use it in GitHub Desktop.
A Controller that sits between the view and the backend service.
var flutterwave = require("../chargeCardService.js");
//Note: The api key and merchant key are stored in the environmental variable '.env'
module.exports = {
cardChargeWithPin: function (req, res, next) {
var data = {
"merchantid": process.env.test_merchant_key, //[YOUR_MERCHANT_KEY]
"amount": flutterwave.encrypt(process.env.test_api_key, req.body.amount), //amount to charge encrypted
"cardno": flutterwave.encrypt(process.env.test_api_key, req.body.cardno), //card no. of the user encrypted
"cvv": flutterwave.encrypt(process.env.test_api_key, req.body.cvv), //card cvv encrypted
"authmodel": flutterwave.encrypt(process.env.test_api_key, req.body.authmethod), //authmodel here is PIN
"currency": flutterwave.encrypt(process.env.test_api_key, req.body.currency),//currency to charge in, encrypted
"country": flutterwave.encrypt(process.env.test_api_key, req.body.country), //route country encrypted
"custid": flutterwave.encrypt(process.env.test_api_key, req.body.custid), //uniqid encrypted
"expirymonth": flutterwave.encrypt(process.env.test_api_key, req.body.expirymonth), //card expiry month encrypted
"expiryyear": flutterwave.encrypt(process.env.test_api_key, req.body.expiryyear), //card expiry year encrypted
"narration": flutterwave.encrypt(process.env.test_api_key, req.body.narration),//short description about the transaction
"pin": flutterwave.encrypt(process.env.test_api_key, req.body.pin) //card pin encrypted
};
flutterwave.chargeCardWithPin(data).then(function (response) { //calling our chargeCardService.js
if (response) {
return res.json(response) //returns to the response as a json to our front view.
}
}).catch(function (error) {
return res.json(error);
})
},
validateCardWithPin: function (req, res) {
var data = {
"merchantid": process.env.test_merchant_key, ////[YOUR_MERCHANT_KEY]
"otp": flutterwave.encrypt(process.env.test_api_key, req.body.otp), //otp sent to the registered phone number of the user encrypted
"otptransactionidentifier": flutterwave.encrypt(process.env.test_api_key, req.body.oo) //the otp transaction identifier
};
flutterwave.validateCardWithPin(data).then(function (response) { //calling the validate service
return res.json(response);//returns to the response as a json to our front view.
}).catch(function (error) {
return res.json(error);
})
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment