-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (62 loc) · 2.81 KB
/
index.js
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
const express = require("express");
const checksum_lib = require('./routes/paytm/checksum/checksum');
var querystring = require('querystring');
const port = 2000;
var app = express();
app.get('/payment',(req,res)=>{
let params ={}
params['MID'] = 'merchant_id',
params['WEBSITE'] = 'WEBSTAGING',
params['CHANNEL_ID'] = 'WEB',
params['INDUSTRY_TYPE_ID'] = 'Retail',
params['ORDER_ID'] = 'ORD0004',
params['CUST_ID'] = 'CUST0044',
params['TXN_AMOUNT'] = '100',
params['CALLBACK_URL'] = 'http://localhost:'+port+'/callback',
params['EMAIL'] = 'xyz@gmail.com',
params['MOBILE_NO'] = '9999999999'
checksum_lib.genchecksum(params,'merchant key',function(err,checksum){
let txn_url = "https://securegw-stage.paytm.in/order/process";
let form_fields = "";
for(x in params)
{
form_fields += "<input type='hidden' name='"+x+"' value='"+params[x]+"'/>"
}
form_fields+="<input type='hidden' name='CHECKSUMHASH' value='"+checksum+"' />"
var html = '<html><body><center><h1>Please wait! Do not refresh the page</h1></center><form method="post" action="'+txn_url+'" name="f1">'+form_fields +'</form><script type="text/javascript">document.f1.submit()</script></body></html>'
res.writeHead(200,{'Content-Type' : 'text/html'})
res.write(html)
res.end()
})
})
app.post("/callback",(request,response)=>{
if(request.method == 'POST'){
var fullBody = '';
request.on('data', function(chunk) {
fullBody += chunk.toString();
});
request.on('end', function() {
var decodedBody = querystring.parse(fullBody);
console.log(decodedBody);
// get received checksum
var checksum = decodedBody.CHECKSUMHASH;
// remove this from body, will be passed to function as separate argument
delete decodedBody.CHECKSUMHASH;
response.writeHead(200, {'Content-type' : 'text/html','Cache-Control': 'no-cache'});
if(checksum_lib.verifychecksum(decodedBody,'merchant_key', checksum)) {
console.log("Checksum Verification => true");
response.write("Checksum Verification => true");
}else{
console.log("Checksum Verification => false");
response.write("Checksum Verification => false");
}
// if checksum is validated Kindly verify the amount and status
// if transaction is successful
// kindly call Paytm Transaction Status API and verify the transaction amount and status.
// If everything is fine then mark that transaction as successful into your DB.
response.end();
});
}
});
app.listen(2000);
console.log("Server running on 3000");