aaa-report-sender.js 895 Bytes
var request = require('request');
var moment = require('moment');

var config;
var monitorUtil;

function init(options) {
    config = options.config;
    monitorUtil = options.monitorUtil;
}

function _resend(requestId, cb) {
    monitorUtil.getTrx(requestId, function(err, trx) {

        if (err) {
            cb(err);
            return;
        }

        var options = {
            url: config.aaa_url + '/topup',
            qs: {
                trans_id: requestId,
                trans_date: moment().format('YYYYMMDDHHmmss'),
                resp_code: trx.rc,
                ussd_msg: trx.supplier + '$' + trx.lastResponse.parsed.MESSAGE
            }
        };

        cb(null);
    });
}

function resend(req, res, next) {
    _resend(req.params.id, function(err) {
        res.redirect("/trx/view/" + req.params.id);
    });
}

exports.init = init;
exports.resend = resend;