Skip to content

Instantly share code, notes, and snippets.

@michaelO93
Last active February 13, 2017 12:44
Show Gist options
  • Save michaelO93/9587aceaad6f8d273f7ee35885a6b8e9 to your computer and use it in GitHub Desktop.
Save michaelO93/9587aceaad6f8d273f7ee35885a6b8e9 to your computer and use it in GitHub Desktop.
Back-end service that communicates with the flutterwave endpoints Raw
var q = require('q'); //promise library
var unirest = require('unirest'); //for handling http requests and response
var dotenv = require('dotenv');
dotenv.load({path: '.env'}); //environmental variable use to store sensitive data.
var baseUrl = process.env.apiUrl; // http://staging1flutterwave.co:8080/pwc/rest/
module.exports = {
chargeCardWithPin: function (data) {
var deferred = q.defer();
console.log(data);
unirest.post(baseUrl + '/card/mvva/pay') //flutterwave endpoint for card charge
.headers({
'Content-Type': 'application/json'
})
.send(data)
.end(function (response) {
if (response.body.status == 'success') {
deferred.resolve(response.body);
}
deferred.reject(response.body);
});
return deferred.promise;
},
validateCardWithPin: function (data) {
var deferred = q.defer();
console.log(data);
unirest.post(baseUrl + '/card/mvva/pay/validate') //flutterwave endpoint to validate the otp
.headers({
'Content-Type': 'application/json'
})
.send(data)
.end(function (response) {
if (response.body.status == 'success') {
deferred.resolve(response.body);
}
deferred.reject(response.body);
});
return deferred.promise;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment