Skip to content

Instantly share code, notes, and snippets.

View michaelO93's full-sized avatar

michael prime michaelO93

  • Lagos, Nigeria
View GitHub Profile
@michaelO93
michaelO93 / responseOTP.json
Last active February 13, 2017 10:35
A sample response returned from the flutterwave server Raw
{
"data": {
  "responsecode": "02",
"responsemessage": "Kindly enter the OTP sent to 234803***9051 and  henry***********ture.com.",
  "otptransactionidentifier": "FLW00023179",
  "transactionreference": "FLW00023179",
  "responsetoken": null
},
"status": "success"
}
@michaelO93
michaelO93 / response.json
Created February 13, 2017 10:32
A sample response returned from the flutterwave server
//The response payload could look like this.
//The responsecode 00 indicates transaction success and there is nothing more to be done.
{
"data": {
  "responsecode": "00",
  "responsemessage": "Success: Approved by Financial Institution",
  "otptransactionidentifier": null,
  "transactionreference": "FLW00023169",
  "responsetoken": "abmHC2JbZU0PurI0236"
},
@michaelO93
michaelO93 / request.json
Created February 13, 2017 10:29
The Request to be sent to the requested endpoint
//All parameters except for merchantid should be
//encrypted with the API key using the TripleDES algorithm.
//The JSON Object should look like the sample below.
//This request requires a [POST] method
{
"amount": "Encrypted Amount",
"authmodel": "Encrypted Authmodel (PIN )",
"cardno": "Encrypted Card Number",
"currency": "Encrypted Currency", //NGN
"custid": "Encrypted CustID",
@michaelO93
michaelO93 / cardController.js
Last active February 13, 2017 12:39
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
@michaelO93
michaelO93 / cardService.js
Last active February 13, 2017 12:44
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 = {
@michaelO93
michaelO93 / encrypt3DES.js
Created February 12, 2017 16:04
Triple3DES Algorithm implemented with Node.js
var CryptoJS = require('crypto-js');
var forge = require('node-forge');
var utf8 = require("utf8");
module.exports = {
encrypt: function (key, text) {
text = (text) ? text.toString() : '';
key = CryptoJS.MD5(utf8.encode(key)).toString(CryptoJS.enc.Latin1);
key = key + key.substring(0, 8);
@michaelO93
michaelO93 / cardCharge.js
Last active February 11, 2017 23:39
Code implementation of charging cards with PIN on Flutterwave using Node.js
//A front-end Javascript that sends the our data to the back-end service.
//... for code brevity
$('#cardpayment').on('submit', function (e) {
e.preventDefault();
var ccnumber = $("input[name='ccnumber']").val().replace(/ /g, ''),
ccmonth = $("input[name='ccmonth']").val(),
ccyear = $("input[name='ccyear']").val(),
@michaelO93
michaelO93 / paywithpin.json
Last active February 8, 2017 15:00
JSON request to be sent to the required endpoint
//All parameters except for merchantid should be
//encrypted with the API key using the TripleDES algorithm.
//The JSON Object should look like the sample below.
{
"amount": "Encrypted Amount",
"authmodel": "Encrypted Authmodel (PIN )",
"cardno": "Encrypted Card Number",
"currency": "Encrypted Currency",
"custid": "Encrypted CustID",
"country": "(Optional: Default is NG, see below for other options) Encrypted Country",