解决错误' mandatoryParams'没有定义no-undef'在反应中

时间:2017-02-26 14:58:16

标签: javascript node.js reactjs payment-gateway paytm

我收到错误:

18:35  error    'mandatoryParams' is not defined               no-undef

我的checksum.js文件:

"use strict";

var crypt = require('./crypt');
var util = require('util');
var crypto = require('crypto');

//mandatory flag: when it set, only mandatory parameters are added to checksum

function paramsToString(params, mandatoryflag) {
    var data = '';
    var flag = params.refund ? true : false;
    delete params.refund;
    var tempKeys = Object.keys(params);
    if (!flag) tempKeys.sort();
    tempKeys.forEach(function (key) {
        if (key !== 'CHECKSUMHASH') {
            if (params[key] === 'null') params[key] = '';
            if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
                data += (params[key] + '|');
            }
        }
    });
    return data;
}


function genchecksum(params, key, cb) {
    var flag = params.refund ? true : false;
    var data = paramsToString(params);
    crypt.gen_salt(4, function (err, salt) {
        var sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
        var check_sum = sha256 + salt;
        var encrypted = crypt.encrypt(check_sum, key);
        if (flag) {
            params.CHECKSUM = (encrypted);
            params.CHECKSUM = encrypted;
        } else {
            params.CHECKSUMHASH = (encrypted);
            params.payt_STATUS = '1';
        }
        cb(undefined, params);
    });
}
function genchecksumbystring(params, key, cb) {

    crypt.gen_salt(4, function (err, salt) {
        var sha256 = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
        var check_sum = sha256 + salt;
        var encrypted = crypt.encrypt(check_sum, key);

        var CHECKSUMHASH = encodeURIComponent(encrypted);
        CHECKSUMHASH = encrypted;
        cb(undefined, CHECKSUMHASH);
    });
}


function verifychecksum(params, key) {

    if (!params) console.log("params are null");

    var data = paramsToString(params, false);
    //TODO: after PG fix on thier side remove below two lines
    if (params.CHECKSUMHASH) {
        params.CHECKSUMHASH = params.CHECKSUMHASH.replace('\n', '');
        params.CHECKSUMHASH = params.CHECKSUMHASH.replace('\r', '');

        var temp = decodeURIComponent(params.CHECKSUMHASH);
        var checksum = crypt.decrypt(temp, key);
        var salt = checksum.substr(checksum.length - 4);
        var sha256 = checksum.substr(0, checksum.length - 4);
        var hash = crypto.createHash('sha256').update(data + salt).digest('hex');
        if (hash === sha256) {
            return true;
        } else {
            util.log("checksum is wrong");
            return false;
        }
    } else {
        util.log("checksum not found");
        return false;
    }
}

function verifychecksumbystring(params, key, checksumhash) {

    var checksum = crypt.decrypt(checksumhash, key);
    var salt = checksum.substr(checksum.length - 4);
    var sha256 = checksum.substr(0, checksum.length - 4);
    var hash = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
    if (hash === sha256) {
        return true;
    } else {
        util.log("checksum is wrong");
        return false;
    }
}

module.exports.genchecksum = genchecksum;
module.exports.verifychecksum = verifychecksum;
module.exports.verifychecksumbystring = verifychecksumbystring;
module.exports.genchecksumbystring = genchecksumbystring;

电话cheksum.getchecksum是由我做的:

 buttonCLick()
{
    console.log("I'm clicked");
    var some;
    let paramarray = [];
    paramarray['ORDER_ID'] = 'sadasda';
    paramarray['CUST_ID'] = 'sadasdasddffa';
    paramarray['INDUSTRY_TYPE_ID'] = config.INDUSTRY_TYPE_ID;
    paramarray['CHANNEL_ID'] = config.CHANNEL_ID;
    paramarray['TXN_AMOUNT'] = '1';
    paramarray['MID'] = config.MID;
    paramarray['WEBSITE'] = config.WEBSITE;

    paramarray['CALLBACK_URL'] = 'http://localhost:3000/response';
    console.log("Paramarray---"+paramarray['ORDER_ID']);

    checksum.genchecksumbystring(paramarray, config.PAYTM_MERCHANT_KEY, function (err, result)
    {
        console.log(result);
        some =result;
    });

}

我能理解' mandatoryParams'未定义的是问题,但同一项目使用ejs和表达项目链接:Paytm Github

0 个答案:

没有答案