Last active
February 13, 2017 12:44
-
-
Save michaelO93/9587aceaad6f8d273f7ee35885a6b8e9 to your computer and use it in GitHub Desktop.
Back-end service that communicates with the flutterwave endpoints Raw
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
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