node-paytmpg 6.4.6 → 7.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +132 -182
- package/app/views/layouts/index.hbs +7 -7
- package/app/views/result.hbs +1 -1
- package/dist/app/controllers/adapters/open_money.js +400 -0
- package/dist/app/controllers/adapters/paytm.js +34 -0
- package/{app → dist/app}/controllers/adapters/payu.js +208 -239
- package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
- package/dist/app/controllers/checksum/checksum.js +158 -0
- package/dist/app/controllers/checksum/crypt.js +117 -0
- package/dist/app/controllers/checksum/server.js +130 -0
- package/dist/app/controllers/payment.controller.js +985 -0
- package/dist/app/controllers/static/loadingsvg.js +54 -0
- package/dist/app/controllers/user.controller.js +53 -0
- package/dist/app/models/index.js +2 -0
- package/dist/app/routes/payment_route.js +46 -0
- package/dist/app/utils/buildConfig.js +210 -0
- package/dist/app/utils/utils.js +20 -0
- package/dist/app/views/home.hbs +22 -0
- package/dist/app/views/init.hbs +98 -0
- package/dist/app/views/layouts/index.hbs +53 -0
- package/dist/app/views/result.hbs +33 -0
- package/dist/index.js +119 -0
- package/dist/package.json +67 -0
- package/dist/public/css/style.css +455 -0
- package/dist/public/js/index.js +283 -0
- package/dist/public/layer_checkout.js +38 -0
- package/dist/public/pay.png +0 -0
- package/dist/public/start.png +0 -0
- package/dist/public/start2.png +0 -0
- package/dist/public/stat.png +0 -0
- package/dist/public/test.html +24 -0
- package/dist/public/test.html~ +24 -0
- package/package.json +29 -6
- package/public/test.html~ +24 -0
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.github/workflows/nodejs.yml +0 -24
- package/.github/workflows/npm-publish.yml +0 -23
- package/Dockerfile +0 -9
- package/app/controllers/adapters/open_money.js +0 -515
- package/app/controllers/checksum/PaytmChecksum.js +0 -94
- package/app/controllers/checksum/checksum.js +0 -154
- package/app/controllers/checksum/crypt.js +0 -98
- package/app/controllers/checksum/server.js +0 -132
- package/app/controllers/np_user.controller.js +0 -89
- package/app/controllers/payment_controller.js +0 -1204
- package/app/models/np_multidbplugin.js +0 -111
- package/app/models/np_transaction.model.js +0 -16
- package/app/models/np_user.model.js +0 -12
- package/app/routes/payment_route.js +0 -73
- package/app.yaml +0 -18
- package/example.js +0 -34
- package/index.js +0 -86
- package/lib/config/buildConfig.js +0 -113
- package/lib/config/defaults.js +0 -37
- package/lib/config/validator.js +0 -103
- package/lib/services/database.service.js +0 -153
- package/lib/utils/id-generator.js +0 -30
- package/lib/utils/sanitizer.js +0 -25
|
@@ -1,1204 +0,0 @@
|
|
|
1
|
-
var packageInfo = require('../../package.json')
|
|
2
|
-
const checksum_lib = require('./checksum/checksum.js');
|
|
3
|
-
var request = require('request')
|
|
4
|
-
var Transaction;
|
|
5
|
-
var IDLEN = 10;
|
|
6
|
-
var nodeBase64 = require('nodejs-base64-converter');
|
|
7
|
-
var RazorPay = require('razorpay');
|
|
8
|
-
var OpenMoney = require('./adapters/open_money')
|
|
9
|
-
var PayU = require('./adapters/payu')
|
|
10
|
-
const PaytmChecksum = require('./checksum/PaytmChecksum.js');
|
|
11
|
-
const { stat } = require('fs');
|
|
12
|
-
const { config } = require('process');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
|
|
15
|
-
let loadingSVG = ` <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin:auto;background:#fff;display:block;" width="200px" height="200px" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid">
|
|
16
|
-
<g transform="rotate(0 50 50)">
|
|
17
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
18
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.9166666666666666s" repeatCount="indefinite"></animate>
|
|
19
|
-
</rect>
|
|
20
|
-
</g><g transform="rotate(30 50 50)">
|
|
21
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
22
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.8333333333333334s" repeatCount="indefinite"></animate>
|
|
23
|
-
</rect>
|
|
24
|
-
</g><g transform="rotate(60 50 50)">
|
|
25
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
26
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.75s" repeatCount="indefinite"></animate>
|
|
27
|
-
</rect>
|
|
28
|
-
</g><g transform="rotate(90 50 50)">
|
|
29
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
30
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.6666666666666666s" repeatCount="indefinite"></animate>
|
|
31
|
-
</rect>
|
|
32
|
-
</g><g transform="rotate(120 50 50)">
|
|
33
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
34
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5833333333333334s" repeatCount="indefinite"></animate>
|
|
35
|
-
</rect>
|
|
36
|
-
</g><g transform="rotate(150 50 50)">
|
|
37
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
38
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5s" repeatCount="indefinite"></animate>
|
|
39
|
-
</rect>
|
|
40
|
-
</g><g transform="rotate(180 50 50)">
|
|
41
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
42
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.4166666666666667s" repeatCount="indefinite"></animate>
|
|
43
|
-
</rect>
|
|
44
|
-
</g><g transform="rotate(210 50 50)">
|
|
45
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
46
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.3333333333333333s" repeatCount="indefinite"></animate>
|
|
47
|
-
</rect>
|
|
48
|
-
</g><g transform="rotate(240 50 50)">
|
|
49
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
50
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.25s" repeatCount="indefinite"></animate>
|
|
51
|
-
</rect>
|
|
52
|
-
</g><g transform="rotate(270 50 50)">
|
|
53
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
54
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.16666666666666666s" repeatCount="indefinite"></animate>
|
|
55
|
-
</rect>
|
|
56
|
-
</g><g transform="rotate(300 50 50)">
|
|
57
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
58
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.08333333333333333s" repeatCount="indefinite"></animate>
|
|
59
|
-
</rect>
|
|
60
|
-
</g><g transform="rotate(330 50 50)">
|
|
61
|
-
<rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
|
|
62
|
-
<animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animate>
|
|
63
|
-
</rect>
|
|
64
|
-
</g>
|
|
65
|
-
</svg>`
|
|
66
|
-
|
|
67
|
-
function sanitizeRequest(body) {
|
|
68
|
-
|
|
69
|
-
if (body.amount)
|
|
70
|
-
body.amount = parseFloat(body.amount);
|
|
71
|
-
if (body.TXN_AMOUNT)
|
|
72
|
-
body.amount = parseFloat(body.TXN_AMOUNT);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
module.exports = function (app, callbacks) {
|
|
76
|
-
var config = (app.get('np_config'))
|
|
77
|
-
var useController = require('./np_user.controller.js')(app, callbacks);
|
|
78
|
-
|
|
79
|
-
var razorPayInstance;
|
|
80
|
-
var openMoneyInstance = new OpenMoney(config);
|
|
81
|
-
var payuInstance = new PayU(config)
|
|
82
|
-
|
|
83
|
-
if (config.razor_url) {
|
|
84
|
-
razorPayInstance = new RazorPay({ key_id: config.KEY, key_secret: config.SECRET })
|
|
85
|
-
}
|
|
86
|
-
if (config.open_money_url) {
|
|
87
|
-
openMoneyInstance = new OpenMoney(config);
|
|
88
|
-
}
|
|
89
|
-
if (config.payu_url) {
|
|
90
|
-
payuInstance = new PayU(config);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
let usingMultiDbOrm = false;
|
|
94
|
-
if (config.db_url) {
|
|
95
|
-
Transaction = require('../models/np_transaction.model.js');
|
|
96
|
-
usingMultiDbOrm = false;
|
|
97
|
-
|
|
98
|
-
} else if (app.multidborm) {
|
|
99
|
-
const sample = {
|
|
100
|
-
orderId: "string",
|
|
101
|
-
cusId: "string",
|
|
102
|
-
time: 1770051201752,
|
|
103
|
-
timeStamp: 1770051201752,
|
|
104
|
-
status: "string",
|
|
105
|
-
name: "string",
|
|
106
|
-
email: "string",
|
|
107
|
-
phone: "string",
|
|
108
|
-
amount: 1,
|
|
109
|
-
pname: "string",
|
|
110
|
-
extra: "stringlarge",
|
|
111
|
-
TXNID: "27118670199",
|
|
112
|
-
returnUrl: "string"
|
|
113
|
-
}
|
|
114
|
-
Transaction = require('../models/np_multidbplugin.js')('nptransactions', app.multidborm, sample);
|
|
115
|
-
Transaction.db = app.multidborm;
|
|
116
|
-
Transaction.modelname = 'nptransactions'
|
|
117
|
-
Transaction.idFieldName = 'orderId'
|
|
118
|
-
app.NPTransaction = Transaction;
|
|
119
|
-
usingMultiDbOrm = true;
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
var module = {};
|
|
124
|
-
|
|
125
|
-
var config = (app.get('np_config'))
|
|
126
|
-
function makeid(length) {
|
|
127
|
-
var text = "";
|
|
128
|
-
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
129
|
-
|
|
130
|
-
for (var i = 0; i < length; i++)
|
|
131
|
-
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
132
|
-
|
|
133
|
-
return text;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const viewRoot = config.templateDir
|
|
137
|
-
? config.templateDir
|
|
138
|
-
: path.join(__dirname, '..', 'views');
|
|
139
|
-
var vp = config.resolved_view_path || (viewRoot.endsWith(path.sep) ? viewRoot : viewRoot + path.sep)
|
|
140
|
-
|
|
141
|
-
module.home = (req, res) => {
|
|
142
|
-
|
|
143
|
-
packageInfo.repository.url = packageInfo.repository.url.replace('git+', '')
|
|
144
|
-
res.render(vp + "home.hbs", packageInfo)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
module.init = async function (req, res) {
|
|
150
|
-
|
|
151
|
-
if (!req.body.ORDER_ID && !req.body.EMAIL && req.query?.to) {
|
|
152
|
-
let toData = JSON.parse(nodeBase64.decode(req.query.to));
|
|
153
|
-
req.body.NAME = toData.NAME
|
|
154
|
-
req.body.EMAIL = toData.EMAIL
|
|
155
|
-
req.body.TXN_AMOUNT = toData.TXN_AMOUNT
|
|
156
|
-
req.body.MOBILE_NO = toData.MOBILE_NO
|
|
157
|
-
req.body.ORDER_ID = toData.ORDER_ID || toData.ORDERID
|
|
158
|
-
req.body.PRODUCT_NAME = toData.PRODUCT_NAME
|
|
159
|
-
req.body.RETURN_URL = toData.RETURN_URL
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
sanitizeRequest(req.body);
|
|
163
|
-
let gotAllParams = true;
|
|
164
|
-
let checkedFields = ['TXN_AMOUNT', 'PRODUCT_NAME', 'MOBILE_NO', 'NAME', 'EMAIL']
|
|
165
|
-
if (req.body !== undefined) {
|
|
166
|
-
|
|
167
|
-
for (var i = 0; i < checkedFields.length; i++) {
|
|
168
|
-
|
|
169
|
-
if (req.body[checkedFields[i]] === undefined) {
|
|
170
|
-
gotAllParams = false;
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
gotAllParams = false;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// console.log(req.body)
|
|
181
|
-
|
|
182
|
-
if ((req.body.ORDER_ID !== undefined && req.body.ORDER_ID.length > 2)
|
|
183
|
-
&&
|
|
184
|
-
(req.body.CUST_ID !== undefined && req.body.CUST_ID.length > 2)) {
|
|
185
|
-
// console.log('redirect')
|
|
186
|
-
// console.log(req.body)
|
|
187
|
-
var params = {};
|
|
188
|
-
|
|
189
|
-
params['MID'] = req.body.MID;
|
|
190
|
-
params['WEBSITE'] = req.body.WEBSITE;
|
|
191
|
-
params['CHANNEL_ID'] = req.body.CHANNEL_ID;
|
|
192
|
-
params['INDUSTRY_TYPE_ID'] = req.body.INDUSTRY_TYPE_ID;
|
|
193
|
-
params['ORDER_ID'] = req.body.ORDER_ID || req.body.ORDERID;
|
|
194
|
-
params['CUST_ID'] = req.body.CUST_ID;
|
|
195
|
-
params['TXN_AMOUNT'] = req.body.TXN_AMOUNT;
|
|
196
|
-
params['CALLBACK_URL'] = req.body.CALLBACK_URL + "?order_id=" + req.body.ORDER_ID;
|
|
197
|
-
params['EMAIL'] = req.body.EMAIL;
|
|
198
|
-
params['MOBILE_NO'] = req.body.MOBILE_NO;
|
|
199
|
-
params['PRODUCT_NAME'] = req.body.PRODUCT_NAME;
|
|
200
|
-
params['NAME'] = req.body.NAME;
|
|
201
|
-
|
|
202
|
-
if (config.paytm_url) {
|
|
203
|
-
|
|
204
|
-
let initTxnbody = {
|
|
205
|
-
"requestType": "Payment",
|
|
206
|
-
"mid": params['MID'],
|
|
207
|
-
"websiteName": params['WEBSITE'],
|
|
208
|
-
"orderId": params['ORDER_ID'],
|
|
209
|
-
"callbackUrl": params['CALLBACK_URL'],
|
|
210
|
-
"txnAmount": {
|
|
211
|
-
"value": params['TXN_AMOUNT'],
|
|
212
|
-
"currency": params['CURRENCY'] || "INR",
|
|
213
|
-
},
|
|
214
|
-
"userInfo": {
|
|
215
|
-
"custId": params['CUST_ID'],
|
|
216
|
-
"mobile": params['MOBILE_NO'],
|
|
217
|
-
"firstName": params['NAME'],
|
|
218
|
-
"email": params['EMAIL']
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
if (config.mode) {
|
|
222
|
-
initTxnbody["enablePaymentMode"] = JSON.parse(config.mode)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
let checksum = await PaytmChecksum.generateSignature(JSON.stringify(initTxnbody), config.KEY)
|
|
226
|
-
let initTxnUrl = config.paytm_url + `/theia/api/v1/initiateTransaction?mid=${params['MID']}&orderId=${params['ORDER_ID']}`;
|
|
227
|
-
|
|
228
|
-
request.post(
|
|
229
|
-
initTxnUrl,
|
|
230
|
-
{
|
|
231
|
-
json: {
|
|
232
|
-
"body": initTxnbody,
|
|
233
|
-
"head": {
|
|
234
|
-
"signature": checksum,
|
|
235
|
-
"channelId": params['CHANNEL_ID']
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
},
|
|
239
|
-
function (error, response, body) {
|
|
240
|
-
|
|
241
|
-
if (!error && response.statusCode != undefined
|
|
242
|
-
&& response.statusCode != NaN &&
|
|
243
|
-
response.statusCode == 200 &&
|
|
244
|
-
body.body &&
|
|
245
|
-
body.body.resultInfo &&
|
|
246
|
-
body.body.resultInfo.resultStatus == "S") {
|
|
247
|
-
|
|
248
|
-
let paytmJsToken = {}
|
|
249
|
-
paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
|
|
250
|
-
paytmJsToken.ORDERID = params['ORDER_ID']
|
|
251
|
-
paytmJsToken.ORDER_ID = params['ORDER_ID']
|
|
252
|
-
paytmJsToken.CANCELLED = "cancelled"
|
|
253
|
-
paytmJsToken.TOKEN = body.body.txnToken
|
|
254
|
-
paytmJsToken.TXN_AMOUNT = params['TXN_AMOUNT']
|
|
255
|
-
paytmJsToken.MID = params['MID']
|
|
256
|
-
paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
|
|
257
|
-
paytmJsToken.CALLBACK_URL = params['CALLBACK_URL']
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
let paytmJsCheckouHtml = `<html>
|
|
262
|
-
<head>
|
|
263
|
-
<title>Merchant Checkout</title>
|
|
264
|
-
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0"/>
|
|
265
|
-
|
|
266
|
-
</head>
|
|
267
|
-
<body>
|
|
268
|
-
<center>
|
|
269
|
-
<h1>Please donot close this page or press the back button. Processing...</h1>
|
|
270
|
-
${loadingSVG}
|
|
271
|
-
</center>
|
|
272
|
-
<form id="cancelform" action="${params['CALLBACK_URL']}" method="post">
|
|
273
|
-
<input type="hidden" name="TXNID" value="na"/>
|
|
274
|
-
<input type="hidden" name="STATUS" value="TXN_FAILURE"/>
|
|
275
|
-
<input type="hidden" name="CANCELLED" value="cancelled"/>
|
|
276
|
-
<input id="RESPMSG" type="hidden" name="RESPMSG" value=""/>
|
|
277
|
-
<input type="hidden" name="ORDERID" value="${params["ORDER_ID"]}"/>
|
|
278
|
-
</form>
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
<script>
|
|
282
|
-
|
|
283
|
-
function getBodyColor(color){
|
|
284
|
-
const hex = color.replace('#', '');
|
|
285
|
-
const c_r = parseInt(hex.substr(0, 2), 16);
|
|
286
|
-
const c_g = parseInt(hex.substr(2, 2), 16);
|
|
287
|
-
const c_b = parseInt(hex.substr(4, 2), 16);
|
|
288
|
-
const brightness = ((c_r * 299) + (c_g * 587) + (c_b * 114)) / 1000;
|
|
289
|
-
// console.log(brightness , brightness > 155 ? "#fff" : "#1a1a1c")
|
|
290
|
-
return brightness > 155 ? "#1a1a1c" : "#ffffff";
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
function shadeColor(color, percent) {
|
|
294
|
-
|
|
295
|
-
var R = parseInt(color.substring(1,3),16);
|
|
296
|
-
var G = parseInt(color.substring(3,5),16);
|
|
297
|
-
var B = parseInt(color.substring(5,7),16);
|
|
298
|
-
|
|
299
|
-
R = parseInt(R * (100 + percent) / 100);
|
|
300
|
-
G = parseInt(G * (100 + percent) / 100);
|
|
301
|
-
B = parseInt(B * (100 + percent) / 100);
|
|
302
|
-
|
|
303
|
-
R = (R<255)?R:255;
|
|
304
|
-
G = (G<255)?G:255;
|
|
305
|
-
B = (B<255)?B:255;
|
|
306
|
-
|
|
307
|
-
var RR = ((R.toString(16).length==1)?"0"+R.toString(16):R.toString(16));
|
|
308
|
-
var GG = ((G.toString(16).length==1)?"0"+G.toString(16):G.toString(16));
|
|
309
|
-
var BB = ((B.toString(16).length==1)?"0"+B.toString(16):B.toString(16));
|
|
310
|
-
|
|
311
|
-
return "#"+RR+GG+BB;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
function failTxn(reason) {
|
|
315
|
-
var form = document.getElementById("cancelform");
|
|
316
|
-
var element2 = document.getElementById("RESPMSG");
|
|
317
|
-
element2.value=reason;
|
|
318
|
-
form.submit();
|
|
319
|
-
}
|
|
320
|
-
function onScriptLoad(){
|
|
321
|
-
var config = {
|
|
322
|
-
"root": "",
|
|
323
|
-
"flow": "DEFAULT",
|
|
324
|
-
"style": {
|
|
325
|
-
// "bodyColor": shadeColor("${config.theme_color}",+40),
|
|
326
|
-
"themeBackgroundColor": "${config.theme_color}",
|
|
327
|
-
"themeColor": getBodyColor("${config.theme_color}"),
|
|
328
|
-
"headerBackgroundColor": "${config.theme_color}",
|
|
329
|
-
"headerColor": getBodyColor("${config.theme_color}")
|
|
330
|
-
},
|
|
331
|
-
"data": {
|
|
332
|
-
"orderId": "${params['ORDER_ID']}", /* update order id */
|
|
333
|
-
"token": "${body.body.txnToken}", /* update token value */
|
|
334
|
-
"tokenType": "TXN_TOKEN",
|
|
335
|
-
"amount": "${params['TXN_AMOUNT']}" /* update amount */
|
|
336
|
-
},
|
|
337
|
-
"handler": {
|
|
338
|
-
"notifyMerchant": function(eventName,data){
|
|
339
|
-
// console.log("notifyMerchant handler function called");
|
|
340
|
-
// console.log("eventName => ",eventName);
|
|
341
|
-
// console.log("data => ",data);
|
|
342
|
-
if(eventName == "APP_CLOSED"){
|
|
343
|
-
failTxn(eventName)
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
if(window.Paytm && window.Paytm.CheckoutJS){
|
|
350
|
-
window.Paytm.CheckoutJS.onLoad(function excecuteAfterCompleteLoad() {
|
|
351
|
-
// initialze configuration using init method
|
|
352
|
-
window.Paytm.CheckoutJS.init(config).then(function onSuccess() {
|
|
353
|
-
// after successfully updating configuration, invoke JS Checkout
|
|
354
|
-
window.Paytm.CheckoutJS.invoke();
|
|
355
|
-
}).catch(function onError(error){
|
|
356
|
-
// console.log("error => ",error);
|
|
357
|
-
failTxn(error.message)
|
|
358
|
-
});
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
</script>
|
|
363
|
-
<script type="application/javascript" crossorigin="anonymous" src="${config.paytm_url}/merchantpgpui/checkoutjs/merchants/${params['MID']}.js" onload="onScriptLoad();" crossorigin="anonymous"></script>
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
</body>
|
|
367
|
-
</html>`
|
|
368
|
-
if (res.token) {
|
|
369
|
-
res.token(paytmJsToken)
|
|
370
|
-
}
|
|
371
|
-
return res.send(paytmJsCheckouHtml)
|
|
372
|
-
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
375
|
-
console.log('ERROR:::', error, '\n', body);
|
|
376
|
-
res.status(500)
|
|
377
|
-
var form_fields = "";
|
|
378
|
-
let errorResp = {
|
|
379
|
-
TXNID: "na",
|
|
380
|
-
STATUS: "TXN_FAILURE",
|
|
381
|
-
CANCELLED: "cancelled",
|
|
382
|
-
ORDERID: params["ORDER_ID"]
|
|
383
|
-
}
|
|
384
|
-
for (var x in errorResp) {
|
|
385
|
-
form_fields += "<input type='hidden' name='" + x + "' value='" + errorResp[x] + "' >";
|
|
386
|
-
}
|
|
387
|
-
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "' >";
|
|
388
|
-
if (res.token) {
|
|
389
|
-
res.token(undefined)
|
|
390
|
-
}
|
|
391
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
392
|
-
res.write(`<html>
|
|
393
|
-
|
|
394
|
-
<head>
|
|
395
|
-
<title>Merchant Checkout Error</title>
|
|
396
|
-
</head>
|
|
397
|
-
|
|
398
|
-
<body>
|
|
399
|
-
<center>
|
|
400
|
-
<h1>Something went wrong. Please wait you will be redirected automatically...</h1>
|
|
401
|
-
</center>
|
|
402
|
-
<form method="post" action="${params['CALLBACK_URL']}" name="f1">${form_fields}</form>
|
|
403
|
-
<script type="text/javascript">document.f1.submit();</script>
|
|
404
|
-
</body>
|
|
405
|
-
|
|
406
|
-
</html>`);
|
|
407
|
-
res.end();
|
|
408
|
-
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
|
|
413
|
-
}
|
|
414
|
-
else if (config.razor_url) {
|
|
415
|
-
|
|
416
|
-
let fail = `<div style="display:none">
|
|
417
|
-
|
|
418
|
-
<form method="post" action="${params['CALLBACK_URL']}" id="fail">
|
|
419
|
-
<input name="razorpay_order_id" value="${params['ORDER_ID']}" hidden="true"/>
|
|
420
|
-
</form>
|
|
421
|
-
</div>`;
|
|
422
|
-
let html = `
|
|
423
|
-
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
|
|
424
|
-
<script>
|
|
425
|
-
var options = {
|
|
426
|
-
"key": "${config.KEY}",
|
|
427
|
-
"amount": "${parseFloat(params['TXN_AMOUNT']) * 100}",
|
|
428
|
-
"currency": "INR",
|
|
429
|
-
"name": "${params['PRODUCT_NAME']}",
|
|
430
|
-
"description": "Order # ${params['ORDER_ID']}",
|
|
431
|
-
"image": "${config.logo}",
|
|
432
|
-
"order_id": "${params['ORDER_ID']}",
|
|
433
|
-
"callback_url": "${params['CALLBACK_URL']}",
|
|
434
|
-
"prefill": {
|
|
435
|
-
"name": "${params['NAME']}",
|
|
436
|
-
"email": "${params['EMAIL']}",
|
|
437
|
-
"contact": "${params['MOBILE_NO']}"
|
|
438
|
-
},
|
|
439
|
-
"theme": {
|
|
440
|
-
"color": "${config.theme_color}"
|
|
441
|
-
},
|
|
442
|
-
"modal": {
|
|
443
|
-
"ondismiss": function(){
|
|
444
|
-
document.getElementById("fail").submit()
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
};
|
|
448
|
-
var rzp1 = new Razorpay(options);
|
|
449
|
-
|
|
450
|
-
rzp1.open();
|
|
451
|
-
</script>`;
|
|
452
|
-
|
|
453
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
454
|
-
res.write(`<html><head><title>Merchant Checkout Page</title></head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${html}<br>${fail}<br>${loadingSVG}</center></body></html>`);
|
|
455
|
-
res.end();
|
|
456
|
-
|
|
457
|
-
}
|
|
458
|
-
else if (config.payu_url) {
|
|
459
|
-
const payuRequest = payuInstance.generatePaymentRequest(params);
|
|
460
|
-
payuInstance.renderProcessingPage(params, payuRequest, res, loadingSVG);
|
|
461
|
-
}
|
|
462
|
-
else if (config.open_money_url) {
|
|
463
|
-
try {
|
|
464
|
-
let pmttoken = await openMoneyInstance.generatePaymentToken(params);
|
|
465
|
-
openMoneyInstance.renderProcessingPage(params, pmttoken, res, loadingSVG);
|
|
466
|
-
|
|
467
|
-
var myquery = { orderId: params['ORDER_ID'] };
|
|
468
|
-
Transaction.findOne(myquery, function (err, objForUpdate) {
|
|
469
|
-
|
|
470
|
-
objForUpdate.extra = JSON.stringify({
|
|
471
|
-
layer_pay_token_id: pmttoken.tokenid
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
var newvalues = { $set: objForUpdate };
|
|
475
|
-
Transaction.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
476
|
-
let status = 'Updated TXNID'
|
|
477
|
-
});
|
|
478
|
-
|
|
479
|
-
}, usingMultiDbOrm ? Transaction : undefined)
|
|
480
|
-
|
|
481
|
-
} catch (e) {
|
|
482
|
-
openMoneyInstance.renderError(params, e, res)
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
if (callbacks && typeof callbacks.onStart === 'function') {
|
|
486
|
-
callbacks.onStart(params['ORDER_ID'], params);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
else if ((req.body.ORDER_ID !== undefined && req.body.ORDER_ID.length > 2) || gotAllParams) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
useController.create({ name: req.body.NAME, email: req.body.EMAIL, phone: req.body.MOBILE_NO },
|
|
493
|
-
function (user) {
|
|
494
|
-
|
|
495
|
-
//console.log(user)
|
|
496
|
-
|
|
497
|
-
let onTxn = async function (txnData) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
//console.log(txnData)
|
|
501
|
-
|
|
502
|
-
var params = {};
|
|
503
|
-
params['MID'] = config.MID;
|
|
504
|
-
params['WEBSITE'] = config.WEBSITE;
|
|
505
|
-
params['CHANNEL_ID'] = config.CHANNEL_ID;
|
|
506
|
-
params['INDUSTRY_TYPE_ID'] = config.INDUSTRY_TYPE_ID;
|
|
507
|
-
params['ORDER_ID'] = txnData.orderId;
|
|
508
|
-
params['CUST_ID'] = txnData.cusId;
|
|
509
|
-
params['TXN_AMOUNT'] = JSON.stringify(txnData.amount);
|
|
510
|
-
params['CALLBACK_URL'] = config.host_url + '/' + config.path_prefix + '/callback'
|
|
511
|
-
params['EMAIL'] = txnData.email;
|
|
512
|
-
params['MOBILE_NO'] = txnData.phone;
|
|
513
|
-
params['NAME'] = txnData.name;
|
|
514
|
-
params['PRODUCT_NAME'] = txnData.pname;
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
let showConfirmation =
|
|
518
|
-
function (err, checksum) {
|
|
519
|
-
res.render(vp + "init.hbs", {
|
|
520
|
-
path_prefix: config.path_prefix,
|
|
521
|
-
action:"/"+ config.path_prefix+"/init",
|
|
522
|
-
readonly: 'readonly',
|
|
523
|
-
BUTTON: 'Pay',
|
|
524
|
-
NAME: params['NAME'],
|
|
525
|
-
EMAIL: params['EMAIL'],
|
|
526
|
-
MOBILE_NO: params['MOBILE_NO'],
|
|
527
|
-
PRODUCT_NAME: params['PRODUCT_NAME'],
|
|
528
|
-
TXN_AMOUNT: params['TXN_AMOUNT'],
|
|
529
|
-
MID: params['MID'],
|
|
530
|
-
WEBSITE: params['WEBSITE'],
|
|
531
|
-
ORDER_ID: params['ORDER_ID'],
|
|
532
|
-
CUST_ID: params['CUST_ID'],
|
|
533
|
-
INDUSTRY_TYPE_ID: params['INDUSTRY_TYPE_ID'],
|
|
534
|
-
CHANNEL_ID: params['CHANNEL_ID'],
|
|
535
|
-
CALLBACK_URL: params['CALLBACK_URL'],
|
|
536
|
-
CHECKSUMHASH: checksum
|
|
537
|
-
})
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (config.paytm_url)
|
|
542
|
-
checksum_lib.genchecksum(params, config.KEY, showConfirmation);
|
|
543
|
-
else if (config.razor_url) {
|
|
544
|
-
showConfirmation()
|
|
545
|
-
} else if (config.payu_url) {
|
|
546
|
-
showConfirmation()
|
|
547
|
-
} else if (config.open_money_url) {
|
|
548
|
-
showConfirmation()
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
function onOrder(orderId) {
|
|
557
|
-
|
|
558
|
-
var txnTask = new Transaction({
|
|
559
|
-
orderId: orderId,
|
|
560
|
-
cusId: user.id,
|
|
561
|
-
time: Date.now(),
|
|
562
|
-
timeStamp: Date.now(),
|
|
563
|
-
status: 'INITIATED',
|
|
564
|
-
name: user.name,
|
|
565
|
-
email: user.email,
|
|
566
|
-
phone: user.phone,
|
|
567
|
-
amount: req.body.TXN_AMOUNT,
|
|
568
|
-
pname: req.body.PRODUCT_NAME,
|
|
569
|
-
extra: '',
|
|
570
|
-
returnUrl: req.body.RETURN_URL || ''
|
|
571
|
-
});
|
|
572
|
-
|
|
573
|
-
return txnTask.save().then(onTxn)
|
|
574
|
-
.catch(err => {
|
|
575
|
-
|
|
576
|
-
console.log(err)
|
|
577
|
-
if (req.body.RETURN_URL) {
|
|
578
|
-
res.redirect(req.body.RETURN_URL + "?status=failed")
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
res.redirect('')
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
if ((req.body.ORDER_ID !== undefined && req.body.ORDER_ID.length > 2)) {
|
|
586
|
-
var myquery = { orderId: req.body.ORDER_ID };
|
|
587
|
-
Transaction.findOne(myquery, function (err, orderData) {
|
|
588
|
-
if (err || (!orderData)) {
|
|
589
|
-
if (gotAllParams) {
|
|
590
|
-
console.log("Creating new order for ", req.body.ORDER_ID)
|
|
591
|
-
onOrder(req.body.ORDER_ID)
|
|
592
|
-
}
|
|
593
|
-
else {
|
|
594
|
-
res.send({ message: "Order Not Found or missing required data: " + checkedFields.join(", "), ORDERID: req.body.ORDER_ID })
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
onTxn(orderData);
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
}, usingMultiDbOrm ? Transaction : undefined);
|
|
602
|
-
}
|
|
603
|
-
else {
|
|
604
|
-
let orderId;
|
|
605
|
-
if (config.paytm_url) {
|
|
606
|
-
orderId = "pay_" + makeid(config.id_length || IDLEN)
|
|
607
|
-
onOrder(orderId)
|
|
608
|
-
}
|
|
609
|
-
else if (config.razor_url) {
|
|
610
|
-
|
|
611
|
-
var options = {
|
|
612
|
-
amount: req.body.TXN_AMOUNT * 100,
|
|
613
|
-
currency: "INR",
|
|
614
|
-
receipt: user.id + '_' + Date.now()
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
razorPayInstance.orders.create(options, function (err, order) {
|
|
619
|
-
if (err) {
|
|
620
|
-
res.send({ message: "An error occurred ! " + err.description })
|
|
621
|
-
return;
|
|
622
|
-
}
|
|
623
|
-
orderId = order.id
|
|
624
|
-
onOrder(orderId)
|
|
625
|
-
})
|
|
626
|
-
}
|
|
627
|
-
else if (config.open_money_url) {
|
|
628
|
-
orderId = "pay_" + makeid(config.id_length || IDLEN)
|
|
629
|
-
onOrder(orderId)
|
|
630
|
-
} else if (config.payu_url) {
|
|
631
|
-
orderId = "payu_" + makeid(config.id_length || IDLEN)
|
|
632
|
-
onOrder(orderId)
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
});
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
else {
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
res.render(vp + "init.hbs", {
|
|
652
|
-
|
|
653
|
-
path_prefix: config.path_prefix,
|
|
654
|
-
action:"/"+ config.path_prefix+"/init",
|
|
655
|
-
readonly: '',
|
|
656
|
-
check: true,
|
|
657
|
-
BUTTON: 'Submit',
|
|
658
|
-
NAME: (req.body.NAME === undefined ? '' : req.body.NAME),
|
|
659
|
-
EMAIL: (req.body.EMAIL === undefined ? '' : req.body.EMAIL),
|
|
660
|
-
MOBILE_NO: (req.body.MOBILE_NO === undefined ? '' : req.body.MOBILE_NO),
|
|
661
|
-
PRODUCT_NAME: (req.body.PRODUCT_NAME === undefined ? '' : req.body.PRODUCT_NAME),
|
|
662
|
-
TXN_AMOUNT: (req.body.TXN_AMOUNT === undefined ? '' : req.body.TXN_AMOUNT),
|
|
663
|
-
MID: config.MID,
|
|
664
|
-
WEBSITE: config.WEBSITE,
|
|
665
|
-
ORDER_ID: '',
|
|
666
|
-
CUST_ID: '',
|
|
667
|
-
INDUSTRY_TYPE_ID: config.INDUSTRY_TYPE_ID,
|
|
668
|
-
CHANNEL_ID: config.CHANNEL_ID,
|
|
669
|
-
CALLBACK_URL: config.CALLBACK_URL,
|
|
670
|
-
CHECKSUMHASH: ''
|
|
671
|
-
|
|
672
|
-
})
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
async function updateTransaction(req, res) {
|
|
679
|
-
var orderToFind = req.body.ORDERID || req.body.ORDER_ID || req.body.ORDERId || (req.query && req.query.order_id) || req.body.ORDER_ID;
|
|
680
|
-
var myquery = { orderId: orderToFind };
|
|
681
|
-
|
|
682
|
-
let objForUpdate = null;
|
|
683
|
-
try {
|
|
684
|
-
// try default
|
|
685
|
-
objForUpdate = await Transaction.findOne(myquery).catch(() => null);
|
|
686
|
-
// try id
|
|
687
|
-
if (!objForUpdate) objForUpdate = await Transaction.findOne({ id: orderToFind }).catch(() => null);
|
|
688
|
-
// try uppercase key
|
|
689
|
-
if (!objForUpdate) objForUpdate = await Transaction.findOne({ ORDERID: orderToFind }).catch(() => null);
|
|
690
|
-
} catch (e) {
|
|
691
|
-
// ignore lookup errors
|
|
692
|
-
objForUpdate = objForUpdate || null;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
let returnUrl = objForUpdate ? objForUpdate.returnUrl : null;
|
|
696
|
-
if (returnUrl == 'undefined') returnUrl = undefined;
|
|
697
|
-
|
|
698
|
-
if (!objForUpdate) {
|
|
699
|
-
if (returnUrl) {
|
|
700
|
-
let separator = returnUrl.indexOf('?') > -1 ? '&' : '?';
|
|
701
|
-
returnUrl = returnUrl + separator + 'status=FAILED&message=txn_not_found&ORDERID=' + req.body.ORDERID;
|
|
702
|
-
return res.redirect(returnUrl);
|
|
703
|
-
}
|
|
704
|
-
return res.send({ message: "Transaction Not Found !", ORDERID: req.body.ORDERID, TXNID: req.body.TXNID });
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
if (objForUpdate.status != ("INITIATED") && objForUpdate.status != ("TXN_PENDING") && objForUpdate.status != ("PENDING")) {
|
|
708
|
-
objForUpdate.readonly = "readonly";
|
|
709
|
-
objForUpdate.action = config.homepage;
|
|
710
|
-
if (returnUrl) {
|
|
711
|
-
let separator = returnUrl.indexOf('?') > -1 ? '&' : '?';
|
|
712
|
-
returnUrl = returnUrl + separator + 'status=' + objForUpdate.status + '&ORDERID=' + objForUpdate.orderId + '&TXNID=' + objForUpdate.TXNID;
|
|
713
|
-
return res.redirect(returnUrl);
|
|
714
|
-
}
|
|
715
|
-
else {
|
|
716
|
-
return res.render(vp + "result.hbs", {
|
|
717
|
-
path_prefix: config.path_prefix,
|
|
718
|
-
...objForUpdate
|
|
719
|
-
});
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
if (req.body.status == "paid" && !req.body.STATUS) req.body.STATUS = "TXN_SUCCESS";
|
|
724
|
-
objForUpdate.status = req.body.STATUS;
|
|
725
|
-
objForUpdate.TXNID = req.body.TXNID;
|
|
726
|
-
objForUpdate.extra = JSON.stringify(req.body);
|
|
727
|
-
|
|
728
|
-
var newvalues = { $set: objForUpdate };
|
|
729
|
-
Transaction.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
730
|
-
if (err) {
|
|
731
|
-
if (returnUrl) {
|
|
732
|
-
let separator = returnUrl.indexOf('?') > -1 ? '&' : '?';
|
|
733
|
-
returnUrl = returnUrl + separator + 'status=FAILED&message=update_error&ORDERID=' + req.body.ORDERID;
|
|
734
|
-
return res.redirect(returnUrl);
|
|
735
|
-
}
|
|
736
|
-
return res.send({ message: "Error Occured !", ORDERID: req.body.ORDERID, TXNID: req.body.TXNID });
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
if (callbacks && typeof callbacks.onFinish === 'function') {
|
|
740
|
-
callbacks.onFinish(req.body.ORDERID, objForUpdate);
|
|
741
|
-
}
|
|
742
|
-
objForUpdate.readonly = "readonly";
|
|
743
|
-
objForUpdate.action = config.homepage;
|
|
744
|
-
if (returnUrl) {
|
|
745
|
-
let separator = returnUrl.indexOf('?') > -1 ? '&' : '?';
|
|
746
|
-
returnUrl = returnUrl + separator + 'status=' + objForUpdate.status + '&ORDERID=' + objForUpdate.orderId + '&TXNID=' + objForUpdate.TXNID;
|
|
747
|
-
return res.redirect(returnUrl);
|
|
748
|
-
}
|
|
749
|
-
res.render(vp + "result.hbs", {
|
|
750
|
-
path_prefix: config.path_prefix,
|
|
751
|
-
...objForUpdate
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
module.callback = async (req, res) => {
|
|
757
|
-
console.log("request_data ", req.originalUrl, JSON.stringify(req.body))
|
|
758
|
-
|
|
759
|
-
// Normalize common order id and txn id field names (support ORDER_ID, ORDERID, etc.)
|
|
760
|
-
try {
|
|
761
|
-
if ((!req.body.ORDERID || req.body.ORDERID === '') && req.body.ORDER_ID) {
|
|
762
|
-
req.body.ORDERID = req.body.ORDER_ID;
|
|
763
|
-
}
|
|
764
|
-
if ((!req.body.TXNID || req.body.TXNID === '') && req.body.TXN_ID) {
|
|
765
|
-
req.body.TXNID = req.body.TXN_ID;
|
|
766
|
-
}
|
|
767
|
-
if ((!req.body.ORDERID || req.body.ORDERID === '') && req.query && req.query.order_id) {
|
|
768
|
-
req.body.ORDERID = req.query.order_id;
|
|
769
|
-
}
|
|
770
|
-
} catch (e) {
|
|
771
|
-
// ignore
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
var result = false;
|
|
775
|
-
let isCancelled = false;
|
|
776
|
-
if (config.paytm_url) {
|
|
777
|
-
var checksumhash = req.body.CHECKSUMHASH;
|
|
778
|
-
if (checksumhash) {
|
|
779
|
-
result = checksum_lib.verifychecksum(req.body, config.KEY, checksumhash);
|
|
780
|
-
}
|
|
781
|
-
else {
|
|
782
|
-
let liveStatus = await new Promise((resolve, reject) => {
|
|
783
|
-
getStatusFromPaytm(req.body, req.body.ORDERID, (paytmResponse) => {
|
|
784
|
-
resolve(paytmResponse)
|
|
785
|
-
})
|
|
786
|
-
})
|
|
787
|
-
result = liveStatus.STATUS == req.body.STATUS;
|
|
788
|
-
}
|
|
789
|
-
if (req.body.STATUS == 'TXN_FAILURE' && req.body.CANCELLED == "cancelled" && req.body.TXNID) {
|
|
790
|
-
isCancelled = true;
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
}
|
|
794
|
-
else if (config.razor_url) {
|
|
795
|
-
|
|
796
|
-
if (req.body.razorpay_payment_id) {
|
|
797
|
-
result = checksum_lib.checkRazorSignature(req.body.razorpay_order_id,
|
|
798
|
-
req.body.razorpay_payment_id,
|
|
799
|
-
config.SECRET,
|
|
800
|
-
req.body.razorpay_signature)
|
|
801
|
-
if (result) {
|
|
802
|
-
req.body.STATUS = 'TXN_SUCCESS'
|
|
803
|
-
req.body.ORDERID = req.body.razorpay_order_id
|
|
804
|
-
req.body.TXNID = req.body.razorpay_payment_id
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
else {
|
|
808
|
-
if (req.body.error && req.body.error.metadata && JSON.parse(req.body.error.metadata)) {
|
|
809
|
-
let orderId = JSON.parse(req.body.error.metadata).order_id
|
|
810
|
-
req.body.razorpay_order_id = orderId
|
|
811
|
-
}
|
|
812
|
-
req.body.STATUS = 'TXN_FAILURE'
|
|
813
|
-
req.body.ORDERID = req.body.razorpay_order_id || req.query.order_id
|
|
814
|
-
isCancelled = true;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
else if (config.payu_url) {
|
|
818
|
-
const payuRest = await payuInstance.verifyResult(req);
|
|
819
|
-
result = payuRest.valid;
|
|
820
|
-
req.body.STATUS = payuRest.STATUS;
|
|
821
|
-
req.body.TXNID = payuRest.TXNID;
|
|
822
|
-
req.body.ORDERID = payuRest.ORDERID || req.query.order_id;
|
|
823
|
-
req.body.extras = payuRest.data;
|
|
824
|
-
result = true;
|
|
825
|
-
isCancelled = payuRest.cancelled;
|
|
826
|
-
}
|
|
827
|
-
else if (config.open_money_url) {
|
|
828
|
-
let openRest = await openMoneyInstance.verifyResult(req);
|
|
829
|
-
result = true;
|
|
830
|
-
req.body.STATUS = openRest.STATUS
|
|
831
|
-
req.body.TXNID = openRest.TXNID
|
|
832
|
-
req.body.ORDERID = openRest.ORDERID || req.query.order_id
|
|
833
|
-
req.body.extras = openRest.data
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
//console.log("Checksum Result => ", result, "\n");
|
|
838
|
-
console.log("NodePayTMPG::Transaction => ", req.body.ORDERID, req.body.STATUS);
|
|
839
|
-
//console.log(req.body)
|
|
840
|
-
|
|
841
|
-
if (result || isCancelled) {
|
|
842
|
-
|
|
843
|
-
updateTransaction(req, res);
|
|
844
|
-
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
|
|
848
|
-
res.send({ message: "Something went wrong ! Please try again later .", ORDERID: req.body.ORDERID, TXNID: req.body.TXNID })
|
|
849
|
-
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
module.webhook = (req, res) => {
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
console.log("request_data ", req.originalUrl, JSON.stringify(req.body))
|
|
859
|
-
|
|
860
|
-
if (config.paytm_url) {
|
|
861
|
-
module.callback(req, res)
|
|
862
|
-
}
|
|
863
|
-
else if (config.razor_url) {
|
|
864
|
-
let events = ["payment.captured", "payment.pending", "payment.failed"]
|
|
865
|
-
if (req.body.event && events.indexOf(req.body.event) > -1) {
|
|
866
|
-
if (req.body.payload &&
|
|
867
|
-
req.body.payload.payment &&
|
|
868
|
-
req.body.payload.payment.entity) {
|
|
869
|
-
|
|
870
|
-
let entity = req.body.payload.payment.entity;
|
|
871
|
-
let razorpay_order_id = entity.order_id;
|
|
872
|
-
let razorpay_payment_id = entity.id;
|
|
873
|
-
let status = entity.status;
|
|
874
|
-
let event = req.body.event;
|
|
875
|
-
console.log(`Razorpay webhook payment order=${razorpay_order_id} payid=${razorpay_payment_id} status=${status}`)
|
|
876
|
-
|
|
877
|
-
let reqBody = req.rawBody, signature = req.headers["x-razorpay-signature"];
|
|
878
|
-
|
|
879
|
-
result = RazorPay.validateWebhookSignature(reqBody, req.headers['x-razorpay-signature'], config.SECRET)
|
|
880
|
-
req.signatureVerified = result;
|
|
881
|
-
if (result) {
|
|
882
|
-
if (event == events[0]) {
|
|
883
|
-
req.body.STATUS = "TXN_SUCCESS";
|
|
884
|
-
}
|
|
885
|
-
else if (event == events[1]) { //pending
|
|
886
|
-
req.body.STATUS = "TXN_PENDING";
|
|
887
|
-
}
|
|
888
|
-
else { // failed
|
|
889
|
-
req.body.STATUS = "TXN_FAILURE";
|
|
890
|
-
}
|
|
891
|
-
req.body.ORDERID = razorpay_order_id;
|
|
892
|
-
req.body.TXNID = razorpay_payment_id;
|
|
893
|
-
setTimeout(() => {
|
|
894
|
-
updateTransaction(req, res)
|
|
895
|
-
}, 3000)
|
|
896
|
-
}
|
|
897
|
-
else {
|
|
898
|
-
res.status(401)
|
|
899
|
-
res.send({ message: "Invalid Rzpay signature" })
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
res.status(400)
|
|
904
|
-
res.send({ message: "Invalid Payload" })
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
else {
|
|
908
|
-
res.status(400)
|
|
909
|
-
res.send({ message: "Unsupported event : " + req.body.event })
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
else if (config.payu_url) {
|
|
913
|
-
payuInstance.processWebhook(req, res, updateTransaction)
|
|
914
|
-
}
|
|
915
|
-
else if (config.open_money_url) {
|
|
916
|
-
openMoneyInstance.processWebhook(req, res, updateTransaction)
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
module.createTxn = (req, res) => {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
useController.create({ name: req.body.NAME, email: req.body.EMAIL, phone: req.body.MOBILE_NO },
|
|
924
|
-
async function (user) {
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
let id;
|
|
928
|
-
if (config.paytm_url) {
|
|
929
|
-
id = "pay_" + makeid(config.id_length || IDLEN)
|
|
930
|
-
}
|
|
931
|
-
else if (config.razor_url) {
|
|
932
|
-
|
|
933
|
-
var options = {
|
|
934
|
-
amount: req.body.TXN_AMOUNT * 100,
|
|
935
|
-
currency: "INR",
|
|
936
|
-
receipt: user.id + '_' + Date.now()
|
|
937
|
-
};
|
|
938
|
-
let order = await razorPayInstance.orders.create(options);
|
|
939
|
-
id = order.id;
|
|
940
|
-
}
|
|
941
|
-
else if (config.payu_url) {
|
|
942
|
-
id = "payu_" + makeid(config.id_length || IDLEN)
|
|
943
|
-
}
|
|
944
|
-
else if (config.open_money_url) {
|
|
945
|
-
id = "pay_" + makeid(config.id_length || IDLEN)
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
var txnTask = new Transaction({
|
|
949
|
-
id: id,
|
|
950
|
-
orderId: id,
|
|
951
|
-
cusId: user.id,
|
|
952
|
-
time: Date.now(),
|
|
953
|
-
status: 'INITIATED',
|
|
954
|
-
name: user.name,
|
|
955
|
-
email: user.email,
|
|
956
|
-
phone: user.phone,
|
|
957
|
-
amount: req.body.TXN_AMOUNT,
|
|
958
|
-
pname: req.body.PRODUCT_NAME,
|
|
959
|
-
returnUrl: req.body.RETURN_URL || '',
|
|
960
|
-
extra: (req.body.EXTRA || '')
|
|
961
|
-
|
|
962
|
-
});
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
txnTask.save().then(function (txn) {
|
|
966
|
-
var urlData64 = nodeBase64.encode(JSON.stringify({
|
|
967
|
-
NAME: txn.name,
|
|
968
|
-
EMAIL: txn.email,
|
|
969
|
-
MOBILE_NO: txn.phone,
|
|
970
|
-
ORDER_ID: txn.orderId,
|
|
971
|
-
RETURN_URL: txn.returnUrl,
|
|
972
|
-
TXN_AMOUNT: txn.amount,
|
|
973
|
-
PRODUCT_NAME: txn.pname
|
|
974
|
-
}))
|
|
975
|
-
|
|
976
|
-
txn.payurl = config.host_url + '/' + config.path_prefix + '/init?to=' + urlData64;
|
|
977
|
-
res.send(txn)
|
|
978
|
-
})
|
|
979
|
-
.catch(err => {
|
|
980
|
-
|
|
981
|
-
console.log(err)
|
|
982
|
-
|
|
983
|
-
res.redirect('')
|
|
984
|
-
});
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
});
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
};
|
|
992
|
-
|
|
993
|
-
module.createTxnToken = (req, res) => {
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
module.createTxn(req, {
|
|
997
|
-
send: function (createTxnResult) {
|
|
998
|
-
|
|
999
|
-
// console.log(createTxnResult)
|
|
1000
|
-
|
|
1001
|
-
req.body.NAME = createTxnResult.name
|
|
1002
|
-
req.body.EMAIL = createTxnResult.email
|
|
1003
|
-
req.body.MOBILE_NO = createTxnResult.phone
|
|
1004
|
-
req.body.ORDER_ID = createTxnResult.orderId
|
|
1005
|
-
req.body.RETURN_URL = createTxnResult.returnUrl
|
|
1006
|
-
module.init(req, {
|
|
1007
|
-
render: (renderPath, initResultRender) => {
|
|
1008
|
-
// console.log(initResultRender)
|
|
1009
|
-
req.body = initResultRender
|
|
1010
|
-
|
|
1011
|
-
module.init(req, {
|
|
1012
|
-
send: (initResult) => {
|
|
1013
|
-
|
|
1014
|
-
},
|
|
1015
|
-
status: (status) => {
|
|
1016
|
-
console.log('status', status)
|
|
1017
|
-
|
|
1018
|
-
},
|
|
1019
|
-
token: (tokenData) => {
|
|
1020
|
-
if (!tokenData) {
|
|
1021
|
-
res.status(500)
|
|
1022
|
-
res.send('Something went wrong. Please try again later.')
|
|
1023
|
-
}
|
|
1024
|
-
else {
|
|
1025
|
-
tokenData.payurl = createTxnResult.payurl;
|
|
1026
|
-
res.send(tokenData)
|
|
1027
|
-
}
|
|
1028
|
-
},
|
|
1029
|
-
render: (renderPath2, init2ResultRender) => {
|
|
1030
|
-
console.log('init2ResultRender', init2ResultRender)
|
|
1031
|
-
},
|
|
1032
|
-
end: (initResultWrite) => {
|
|
1033
|
-
console.log('initResultWrite', initResultWrite)
|
|
1034
|
-
},
|
|
1035
|
-
write: (initResultWrite) => {
|
|
1036
|
-
console.log('initResultWrite', initResultWrite)
|
|
1037
|
-
},
|
|
1038
|
-
writeHead: (initResultWriteHead) => {
|
|
1039
|
-
console.log('initResultWriteHead', initResultWriteHead)
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
})
|
|
1043
|
-
|
|
1044
|
-
}
|
|
1045
|
-
})
|
|
1046
|
-
},
|
|
1047
|
-
redirect: res.redirect
|
|
1048
|
-
})
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
};
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
module.status = (req, res) => {
|
|
1055
|
-
|
|
1056
|
-
if (!req.body.ORDER_ID && req.query.ORDER_ID) {
|
|
1057
|
-
req.body.ORDER_ID = req.query.ORDER_ID
|
|
1058
|
-
}
|
|
1059
|
-
var myquery = { orderId: req.body.ORDER_ID };
|
|
1060
|
-
Transaction.findOne(myquery, async function (err, orderData) {
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
if (err) {
|
|
1064
|
-
res.send(err)
|
|
1065
|
-
return
|
|
1066
|
-
}
|
|
1067
|
-
if (orderData.status === "INITIATED") {
|
|
1068
|
-
|
|
1069
|
-
var params = {}
|
|
1070
|
-
params["MID"] = config.MID;
|
|
1071
|
-
params["ORDERID"] = req.body.ORDER_ID;
|
|
1072
|
-
|
|
1073
|
-
async function onStatusUpdate(paytmResponse) {
|
|
1074
|
-
if (paytmResponse.TXNID.length > 4) {
|
|
1075
|
-
orderData.status = paytmResponse.STATUS;
|
|
1076
|
-
orderData.extra = JSON.stringify(paytmResponse);
|
|
1077
|
-
|
|
1078
|
-
var newvalues = { $set: orderData };
|
|
1079
|
-
Transaction.updateOne(myquery, newvalues, function (err, saveRes) {
|
|
1080
|
-
|
|
1081
|
-
if (err) {
|
|
1082
|
-
res.send({ message: "Error Occured !", ORDERID: paytmResponse.ORDERID, TXNID: paytmResponse.TXNID })
|
|
1083
|
-
}
|
|
1084
|
-
else {
|
|
1085
|
-
if (callbacks && typeof callbacks.onFinish === 'function') {
|
|
1086
|
-
callbacks.onFinish(req.body.ORDER_ID, orderData);
|
|
1087
|
-
}
|
|
1088
|
-
res.send(paytmResponse)
|
|
1089
|
-
}
|
|
1090
|
-
});
|
|
1091
|
-
}
|
|
1092
|
-
else {
|
|
1093
|
-
res.send(orderData)
|
|
1094
|
-
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
if (config.paytm_url) {
|
|
1099
|
-
getStatusFromPaytm(params, req.body.ORDER_ID, onStatusUpdate)
|
|
1100
|
-
}
|
|
1101
|
-
else if (config.razor_url) {
|
|
1102
|
-
let result = await razorPayInstance.orders.fetch(req.body.ORDER_ID)
|
|
1103
|
-
result.ORDERID = req.body.ORDER_ID
|
|
1104
|
-
if (result.status == 'paid' && result.amount_due == 0) {
|
|
1105
|
-
result.STATUS = 'TXN_SUCCESS'
|
|
1106
|
-
let payments = await razorPayInstance.orders.fetchPayments(req.body.ORDER_ID)
|
|
1107
|
-
payments.items.forEach(item => {
|
|
1108
|
-
if (item.status == 'captured') {
|
|
1109
|
-
result.TXNID = item.id
|
|
1110
|
-
}
|
|
1111
|
-
});
|
|
1112
|
-
result.payments = payments;
|
|
1113
|
-
|
|
1114
|
-
onStatusUpdate(result)
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
res.send(orderData);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
else if (config.payu_url) {
|
|
1121
|
-
let result = await payuInstance.getPaymentStatus(req.body.ORDER_ID)
|
|
1122
|
-
if (result && result.transaction_details && result.transaction_details[req.body.ORDER_ID]) {
|
|
1123
|
-
let txn = result.transaction_details[req.body.ORDER_ID];
|
|
1124
|
-
let status = 'TXN_FAILURE'
|
|
1125
|
-
if (txn.status == 'success') {
|
|
1126
|
-
status = 'TXN_SUCCESS'
|
|
1127
|
-
}
|
|
1128
|
-
else if (txn.status == 'pending') {
|
|
1129
|
-
status = 'TXN_PENDING'
|
|
1130
|
-
}
|
|
1131
|
-
onStatusUpdate({
|
|
1132
|
-
STATUS: status,
|
|
1133
|
-
ORDERID: req.body.ORDER_ID,
|
|
1134
|
-
TXNID: txn.mihpayid || txn.txnid,
|
|
1135
|
-
payu: txn
|
|
1136
|
-
})
|
|
1137
|
-
}
|
|
1138
|
-
else {
|
|
1139
|
-
res.send(orderData);
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
else if (config.open_money_url) {
|
|
1143
|
-
let extras = JSON.parse(orderData.extra)
|
|
1144
|
-
if (!extras || !extras.layer_pay_token_id) {
|
|
1145
|
-
res.status(500)
|
|
1146
|
-
return res.send({ message: 'An unexpected error occured. No payment token exists' })
|
|
1147
|
-
}
|
|
1148
|
-
let result = await openMoneyInstance.getPaymentStatus(extras.layer_pay_token_id)
|
|
1149
|
-
result = JSON.parse(result)
|
|
1150
|
-
result.ORDERID = req.body.ORDER_ID
|
|
1151
|
-
if (result.status == 'paid' || result.status == 'captured') {
|
|
1152
|
-
result.STATUS = 'TXN_SUCCESS'
|
|
1153
|
-
result.TXNID = result.id
|
|
1154
|
-
onStatusUpdate(result)
|
|
1155
|
-
}
|
|
1156
|
-
else if (result.status == 'pending' || result.status == 'attempted') {
|
|
1157
|
-
result.STATUS = 'TXN_PENDING'
|
|
1158
|
-
result.TXNID = result.id
|
|
1159
|
-
onStatusUpdate(result)
|
|
1160
|
-
}
|
|
1161
|
-
// else if (result.status == 'failed' || result.status == 'cancelled') {
|
|
1162
|
-
// result.STATUS = 'TXN_FAILED'
|
|
1163
|
-
// result.TXNID = result.id
|
|
1164
|
-
// onStatusUpdate(result)
|
|
1165
|
-
// }
|
|
1166
|
-
else {
|
|
1167
|
-
res.send(orderData);
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
}
|
|
1172
|
-
else {
|
|
1173
|
-
res.send(orderData);
|
|
1174
|
-
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
}, usingMultiDbOrm ? Transaction : undefined);
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
function getStatusFromPaytm(params, orderId, cb) {
|
|
1183
|
-
checksum_lib.genchecksum(params, config.KEY, function (err, checksum) {
|
|
1184
|
-
|
|
1185
|
-
request.post(
|
|
1186
|
-
config.paytm_url + "/order/status",
|
|
1187
|
-
{ json: { MID: config.MID, ORDERID: orderId, CHECKSUMHASH: checksum, } },
|
|
1188
|
-
function (error, response, body) {
|
|
1189
|
-
|
|
1190
|
-
if (!error && response.statusCode == 200) {
|
|
1191
|
-
var paytmResponse = JSON.parse(JSON.stringify(body))
|
|
1192
|
-
cb(paytmResponse)
|
|
1193
|
-
}
|
|
1194
|
-
else {
|
|
1195
|
-
console.log('ERROR:::', error, '\n', response);
|
|
1196
|
-
cb({ message: "Error Occured !", ORDERID: orderId })
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
);
|
|
1200
|
-
});
|
|
1201
|
-
}
|
|
1202
|
-
|
|
1203
|
-
return module;
|
|
1204
|
-
}
|