1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
function sortObject(o) {
var sorted = {},
key,
a = [];
for (key in o) {
if (o.hasOwnProperty(key)) {
a.push(key);
}
}
a.sort();
for (key = 0; key < a.length; key++) {
sorted[a[key]] = o[a[key]];
}
return sorted;
}
function create_payment_link(return_url, checkout_url, money, note) {
/*var ipAddr = req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;*/
//var config = require('config');
var dateFormat = require('dateformat');
/*var tmnCode = config.get('vnp_TmnCode');
var secretKey = config.get('vnp_HashSecret');
var vnpUrl = config.get('vnp_Url');
var returnUrl = config.get('vnp_ReturnUrl');*/
var tmnCode = 'ICTLIFE1';
var secretKey = 'ISDFGWJZVJFABUMZYKDFOSYWHHYNAPFS';
var vnpUrl = 'http://sandbox.vnpayment.vn/paymentv2/vpcpay.html';
var returnUrl = return_url;
var date = new Date();
var createDate = dateFormat(date, 'yyyymmddHHmmss');
var orderId = dateFormat(date, 'HHmmss');
//var amount = req.body.amount;
var amount = money;
//var bankCode = req.body.bankCode;
var bankCode = '';
/*var orderInfo = req.body.orderDescription;
var orderType = req.body.orderType;
var locale = req.body.language;*/
var orderInfo = note;
var orderType = '150000';
var locale = '';
if (locale === null || locale === '') {
locale = 'vn';
}
var currCode = 'VND';
var vnp_Params = {};
vnp_Params['vnp_Version'] = '2';
vnp_Params['vnp_Command'] = 'pay';
vnp_Params['vnp_TmnCode'] = tmnCode;
// vnp_Params['vnp_Merchant'] = ''
vnp_Params['vnp_Locale'] = locale;
vnp_Params['vnp_CurrCode'] = currCode;
vnp_Params['vnp_TxnRef'] = orderId;
vnp_Params['vnp_OrderInfo'] = orderInfo;
vnp_Params['vnp_OrderType'] = orderType;
vnp_Params['vnp_Amount'] = amount * 100;
vnp_Params['vnp_ReturnUrl'] = returnUrl;
//vnp_Params['vnp_IpAddr'] = ipAddr;
vnp_Params['vnp_CreateDate'] = createDate;
if (bankCode !== null && bankCode !== '') {
vnp_Params['vnp_BankCode'] = bankCode;
}
vnp_Params = sortObject(vnp_Params);
var querystring = require('qs');
var signData = secretKey + querystring.stringify(vnp_Params, {encode: false});
var sha256 = require('sha256');
var secureHash = sha256(signData);
vnp_Params['vnp_SecureHashType'] = 'SHA256';
vnp_Params['vnp_SecureHash'] = secureHash;
vnpUrl += '?' + querystring.stringify(vnp_Params, {encode: true});
return vnpUrl;
}
export default create_payment_link;