node-paytmpg 7.5.16 → 7.5.17
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/package.json +1 -1
- package/dist/app/controllers/adapters/open_money.d.ts +0 -23
- package/dist/app/controllers/adapters/open_money.js +0 -399
- package/dist/app/controllers/adapters/paytm.d.ts +0 -2
- package/dist/app/controllers/adapters/paytm.js +0 -34
- package/dist/app/controllers/adapters/payu.d.ts +0 -50
- package/dist/app/controllers/adapters/payu.js +0 -238
- package/dist/app/controllers/checksum/PaytmChecksum.d.ts +0 -13
- package/dist/app/controllers/checksum/PaytmChecksum.js +0 -118
- package/dist/app/controllers/checksum/checksum.d.ts +0 -15
- package/dist/app/controllers/checksum/checksum.js +0 -158
- package/dist/app/controllers/checksum/crypt.d.ts +0 -15
- package/dist/app/controllers/checksum/crypt.js +0 -117
- package/dist/app/controllers/checksum/server.d.ts +0 -1
- package/dist/app/controllers/checksum/server.js +0 -132
- package/dist/app/controllers/htmlhelper.d.ts +0 -9
- package/dist/app/controllers/htmlhelper.js +0 -95
- package/dist/app/controllers/payment.controller.d.ts +0 -33
- package/dist/app/controllers/payment.controller.js +0 -1128
- package/dist/app/controllers/static/loadingsvg.d.ts +0 -1
- package/dist/app/controllers/static/loadingsvg.js +0 -54
- package/dist/app/controllers/user.controller.d.ts +0 -9
- package/dist/app/controllers/user.controller.js +0 -53
- package/dist/app/models/index.d.ts +0 -103
- package/dist/app/models/index.js +0 -2
- package/dist/app/routes/payment_route.d.ts +0 -2
- package/dist/app/routes/payment_route.js +0 -46
- package/dist/app/utils/buildConfig.d.ts +0 -4
- package/dist/app/utils/buildConfig.js +0 -224
- package/dist/app/utils/utils.d.ts +0 -5
- package/dist/app/utils/utils.js +0 -20
- package/dist/app/views/home.hbs +0 -22
- package/dist/app/views/init.hbs +0 -104
- package/dist/app/views/layouts/index.hbs +0 -53
- package/dist/app/views/result.hbs +0 -33
- package/dist/index.d.ts +0 -10
- package/dist/index.js +0 -120
- package/dist/package.json +0 -68
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const buildConfig_1 = require("../../utils/buildConfig");
|
|
9
|
-
class PayU {
|
|
10
|
-
constructor(npconfig) {
|
|
11
|
-
this.initParams(npconfig);
|
|
12
|
-
}
|
|
13
|
-
initParams(npconfig) {
|
|
14
|
-
this.baseConfig = npconfig;
|
|
15
|
-
const baseUrl = (npconfig.payu_url || '').replace(/\/$/, '');
|
|
16
|
-
const isSandbox = baseUrl.indexOf('test.payu.in') > -1;
|
|
17
|
-
const verifyUrl = npconfig.payu_verify_url || (isSandbox
|
|
18
|
-
? 'https://test.payu.in/merchant/postservice.php?form=2'
|
|
19
|
-
: 'https://info.payu.in/merchant/postservice.php?form=2');
|
|
20
|
-
this.config = {
|
|
21
|
-
key: npconfig.KEY,
|
|
22
|
-
salt: npconfig.SECRET,
|
|
23
|
-
baseUrl,
|
|
24
|
-
paymentUrl: npconfig.payu_payment_url || (baseUrl ? `${baseUrl}/_payment` : ''),
|
|
25
|
-
verifyUrl,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
normalizeAmount(amount) {
|
|
29
|
-
const value = parseFloat(amount || 0);
|
|
30
|
-
return value.toFixed(2);
|
|
31
|
-
}
|
|
32
|
-
buildRequestHash(payload) {
|
|
33
|
-
const parts = [
|
|
34
|
-
payload.key,
|
|
35
|
-
payload.txnid,
|
|
36
|
-
this.normalizeAmount(payload.amount),
|
|
37
|
-
payload.productinfo,
|
|
38
|
-
payload.firstname,
|
|
39
|
-
payload.email,
|
|
40
|
-
payload.udf1 || '',
|
|
41
|
-
payload.udf2 || '',
|
|
42
|
-
payload.udf3 || '',
|
|
43
|
-
payload.udf4 || '',
|
|
44
|
-
payload.udf5 || '',
|
|
45
|
-
payload.udf6 || '',
|
|
46
|
-
payload.udf7 || '',
|
|
47
|
-
payload.udf8 || '',
|
|
48
|
-
payload.udf9 || '',
|
|
49
|
-
payload.udf10 || '',
|
|
50
|
-
this.config.salt,
|
|
51
|
-
];
|
|
52
|
-
return crypto_1.default.createHash('sha512').update(parts.join('|')).digest('hex');
|
|
53
|
-
}
|
|
54
|
-
buildResponseHash(data) {
|
|
55
|
-
const amount = this.normalizeAmount(data.amount);
|
|
56
|
-
const sequence = [
|
|
57
|
-
data.additionalCharges || null,
|
|
58
|
-
this.config.salt,
|
|
59
|
-
data.status || '',
|
|
60
|
-
'', '', '', '', '', '', '', '', '', '',
|
|
61
|
-
data.udf5 || '',
|
|
62
|
-
data.udf4 || '',
|
|
63
|
-
data.udf3 || '',
|
|
64
|
-
data.udf2 || '',
|
|
65
|
-
data.udf1 || '',
|
|
66
|
-
data.email || '',
|
|
67
|
-
data.firstname || '',
|
|
68
|
-
data.productinfo || '',
|
|
69
|
-
amount,
|
|
70
|
-
data.txnid || '',
|
|
71
|
-
data.key || '',
|
|
72
|
-
];
|
|
73
|
-
const filtered = sequence.filter((value) => value !== null);
|
|
74
|
-
return crypto_1.default.createHash('sha512').update(filtered.join('|')).digest('hex');
|
|
75
|
-
}
|
|
76
|
-
generatePaymentRequest(params) {
|
|
77
|
-
const payload = {
|
|
78
|
-
key: this.config.key,
|
|
79
|
-
txnid: params.ORDER_ID,
|
|
80
|
-
amount: this.normalizeAmount(params.TXN_AMOUNT),
|
|
81
|
-
productinfo: params.PRODUCT_NAME,
|
|
82
|
-
firstname: params.NAME,
|
|
83
|
-
email: params.EMAIL,
|
|
84
|
-
phone: params.MOBILE_NO,
|
|
85
|
-
surl: params.CALLBACK_URL,
|
|
86
|
-
furl: params.CALLBACK_URL,
|
|
87
|
-
udf1: params.CUST_ID || '',
|
|
88
|
-
udf2: params.ORDER_ID || '',
|
|
89
|
-
service_provider: 'payu_paisa',
|
|
90
|
-
};
|
|
91
|
-
payload.hash = this.buildRequestHash(payload);
|
|
92
|
-
const formFields = Object.keys(payload)
|
|
93
|
-
.map((key) => `<input type='hidden' name='${key}' value='${payload[key]}' />`)
|
|
94
|
-
.join('');
|
|
95
|
-
const html = `<form action='${this.config.paymentUrl}' method='post' id='payu_payment_form' style='display:none'>${formFields}</form><script>document.getElementById('payu_payment_form').submit();</script>`;
|
|
96
|
-
return { html, payload };
|
|
97
|
-
}
|
|
98
|
-
decodeTransactionResponse(txnDataBase64FromPayu) {
|
|
99
|
-
const txnDataJson = Buffer.from(txnDataBase64FromPayu, 'base64').toString('utf-8');
|
|
100
|
-
return JSON.parse(txnDataJson);
|
|
101
|
-
}
|
|
102
|
-
async verifyResult(req, _orderId) {
|
|
103
|
-
var _a, _b, _c;
|
|
104
|
-
const originalBody = req.body || {};
|
|
105
|
-
const lookupId = (originalBody === null || originalBody === void 0 ? void 0 : originalBody.txnid) || ((_a = req.query) === null || _a === void 0 ? void 0 : _a.order_id) || _orderId;
|
|
106
|
-
const statusResp = await this.checkBqrTxnStatus(lookupId);
|
|
107
|
-
let resData = null;
|
|
108
|
-
if (!resData && statusResp && statusResp.transaction_details) {
|
|
109
|
-
const td = statusResp.transaction_details;
|
|
110
|
-
if (td[lookupId]) {
|
|
111
|
-
resData = td[lookupId];
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
for (const key of Object.keys(td)) {
|
|
115
|
-
const txn = td[key];
|
|
116
|
-
if (!txn)
|
|
117
|
-
continue;
|
|
118
|
-
if ((txn.txnid && txn.txnid.toString() === lookupId) || key.toString().endsWith(lookupId)) {
|
|
119
|
-
resData = txn;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const source = resData || statusResp || originalBody;
|
|
126
|
-
const msg = ((statusResp === null || statusResp === void 0 ? void 0 : statusResp.msg) || '').toString();
|
|
127
|
-
const statusText = (source.status || source.unmappedstatus || msg || '').toString().toLowerCase();
|
|
128
|
-
let status = 'TXN_FAILURE';
|
|
129
|
-
if (statusText.includes('success') || statusText.includes('completed') || statusText.includes('captured')) {
|
|
130
|
-
status = 'TXN_SUCCESS';
|
|
131
|
-
}
|
|
132
|
-
else if (statusText.includes('pending')) {
|
|
133
|
-
status = 'TXN_PENDING';
|
|
134
|
-
}
|
|
135
|
-
const orderId = (source.udf2 || source.order_id || source.txnid || lookupId).toString();
|
|
136
|
-
const txnId = source.mihpayid || source.txnid || null;
|
|
137
|
-
return {
|
|
138
|
-
STATUS: status,
|
|
139
|
-
ORDERID: orderId,
|
|
140
|
-
TXNID: txnId,
|
|
141
|
-
data: resData || statusResp || originalBody,
|
|
142
|
-
cancelled: ((_c = (_b = source.unmappedstatus) === null || _b === void 0 ? void 0 : _b.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(_b).includes('cancelled')) || false,
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
async getPaymentStatus(txnId) {
|
|
146
|
-
const verifyPayload = new URLSearchParams();
|
|
147
|
-
verifyPayload.append('key', this.config.key || '');
|
|
148
|
-
verifyPayload.append('command', 'verify_payment');
|
|
149
|
-
verifyPayload.append('var1', txnId || '');
|
|
150
|
-
const hashString = [this.config.key, 'verify_payment', txnId, this.config.salt].join('|');
|
|
151
|
-
verifyPayload.append('hash', crypto_1.default.createHash('sha512').update(hashString).digest('hex'));
|
|
152
|
-
try {
|
|
153
|
-
const response = await axios_1.default.post(this.config.verifyUrl, verifyPayload.toString(), {
|
|
154
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
155
|
-
});
|
|
156
|
-
return response.data;
|
|
157
|
-
}
|
|
158
|
-
catch (error) {
|
|
159
|
-
return { error: error.message };
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
async postCommand(command, transactionId) {
|
|
163
|
-
const payload = new URLSearchParams();
|
|
164
|
-
payload.append('key', this.config.key || '');
|
|
165
|
-
payload.append('command', command || '');
|
|
166
|
-
payload.append('var1', transactionId || '');
|
|
167
|
-
const hashString = [this.config.key, command, transactionId, this.config.salt].join('|');
|
|
168
|
-
payload.append('hash', crypto_1.default.createHash('sha512').update(hashString).digest('hex'));
|
|
169
|
-
try {
|
|
170
|
-
const response = await axios_1.default.post(this.config.verifyUrl, payload.toString(), {
|
|
171
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
172
|
-
});
|
|
173
|
-
return response.data;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
return { error: error.message };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
async checkBqrTxnStatus(transactionId) {
|
|
180
|
-
return this.postCommand('verify_payment', transactionId);
|
|
181
|
-
}
|
|
182
|
-
renderProcessingPage(params, paymentReq, res, loadingSVG) {
|
|
183
|
-
// delegate HTML construction to htmlhelper's builder (keeps behavior identical)
|
|
184
|
-
const html = require('../htmlhelper').buildProcessingPageHtml(paymentReq.html, loadingSVG);
|
|
185
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
186
|
-
res.write(html);
|
|
187
|
-
res.end();
|
|
188
|
-
}
|
|
189
|
-
renderError(params, error, res) {
|
|
190
|
-
console.log('ERROR:::', error, '\n');
|
|
191
|
-
res.status(500);
|
|
192
|
-
const errorResp = {
|
|
193
|
-
TXNID: 'na',
|
|
194
|
-
STATUS: 'TXN_FAILURE',
|
|
195
|
-
CANCELLED: 'cancelled',
|
|
196
|
-
ORDERID: params.ORDER_ID,
|
|
197
|
-
CHECKSUMHASH: params.CHECKSUM || ''
|
|
198
|
-
};
|
|
199
|
-
const html = require('../htmlhelper').buildAutoPostFormHtml(params.CALLBACK_URL, errorResp);
|
|
200
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
201
|
-
res.write(html);
|
|
202
|
-
res.end();
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
*
|
|
206
|
-
* @param req.body {"amount":"10.00","paymentMode":"UPICC","udf5":"","udf3":"","split_info":"","udf4":"","udf1":"user_SGnPOmzPxi","udf2":"payu_b2ThO9ra4e","customerName":"test","productInfo":"TEST","customerPhone":"","additionalCharges":"","paymentId":"27778865835","customerEmail":"test@gmail.com","merchantTransactionId":"payu_b2ThO9ra4e","error_Message":"No Error","notificationId":"12345","bankRefNum":"161058882264","hash":"12345","key":"2ETh7I","status":"Success","field4":""}
|
|
207
|
-
* @param res
|
|
208
|
-
* @param updateTransaction
|
|
209
|
-
*/
|
|
210
|
-
async processWebhook(req, res, updateTransaction, getOrder) {
|
|
211
|
-
var _a;
|
|
212
|
-
let body = ((_a = req.body) === null || _a === void 0 ? void 0 : _a.event_payload) || req.body;
|
|
213
|
-
let orderId = (body === null || body === void 0 ? void 0 : body.merchantTransactionId) || (body === null || body === void 0 ? void 0 : body.udf2);
|
|
214
|
-
if (!orderId) {
|
|
215
|
-
console.log('PayU Webhook: Missing order identifier in payload', body);
|
|
216
|
-
res.status(200).send({ error: 'Missing order identifier' });
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
let originalOrder = await getOrder(req, orderId);
|
|
220
|
-
if (!originalOrder) {
|
|
221
|
-
console.log('PayU Webhook: Original order not found for orderId', orderId);
|
|
222
|
-
res.status(200).send({ error: 'Original order not found' });
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
let updatedConfig = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, originalOrder);
|
|
226
|
-
this.initParams(updatedConfig);
|
|
227
|
-
const payuRest = await this.verifyResult(req);
|
|
228
|
-
let result = !!payuRest.STATUS;
|
|
229
|
-
req.body.STATUS = payuRest.STATUS;
|
|
230
|
-
req.body.TXNID = payuRest.TXNID;
|
|
231
|
-
req.body.ORDERID = payuRest.ORDERID || req.query.order_id;
|
|
232
|
-
req.body.extras = payuRest.data;
|
|
233
|
-
let isCancelled = !!payuRest.cancelled;
|
|
234
|
-
updateTransaction(req, res, true);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
exports.default = PayU;
|
|
238
|
-
module.exports = PayU;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export default class PaytmChecksum {
|
|
2
|
-
static iv: string;
|
|
3
|
-
static encrypt(input: string, key: string): string;
|
|
4
|
-
static decrypt(encrypted: string, key: string): string;
|
|
5
|
-
static generateSignature(params: Record<string, any> | string, key: string): Promise<string> | Promise<never>;
|
|
6
|
-
static verifySignature(params: Record<string, any> | string, key: string, checksum: string): boolean | Promise<never>;
|
|
7
|
-
static generateSignatureByString(params: string, key: string): Promise<string>;
|
|
8
|
-
static verifySignatureByString(params: string, key: string, checksum: string): boolean;
|
|
9
|
-
static generateRandomString(length: number): Promise<string>;
|
|
10
|
-
static getStringByParams(params: Record<string, any>): string;
|
|
11
|
-
static calculateHash(params: string, salt: string): string;
|
|
12
|
-
static calculateChecksum(params: string, key: string, salt: string): string;
|
|
13
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const crypto = __importStar(require("crypto"));
|
|
37
|
-
class PaytmChecksum {
|
|
38
|
-
static encrypt(input, key) {
|
|
39
|
-
const cipher = crypto.createCipheriv('AES-128-CBC', key, PaytmChecksum.iv);
|
|
40
|
-
let encrypted = cipher.update(input, 'binary', 'base64');
|
|
41
|
-
encrypted += cipher.final('base64');
|
|
42
|
-
return encrypted;
|
|
43
|
-
}
|
|
44
|
-
static decrypt(encrypted, key) {
|
|
45
|
-
const decipher = crypto.createDecipheriv('AES-128-CBC', key, PaytmChecksum.iv);
|
|
46
|
-
let decrypted = decipher.update(encrypted, 'base64', 'binary');
|
|
47
|
-
try {
|
|
48
|
-
decrypted += decipher.final('binary');
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
console.log(e);
|
|
52
|
-
}
|
|
53
|
-
return decrypted;
|
|
54
|
-
}
|
|
55
|
-
static generateSignature(params, key) {
|
|
56
|
-
if (typeof params !== 'object' && typeof params !== 'string') {
|
|
57
|
-
const error = 'string or object expected, ' + (typeof params) + ' given.';
|
|
58
|
-
return Promise.reject(error);
|
|
59
|
-
}
|
|
60
|
-
if (typeof params !== 'string') {
|
|
61
|
-
params = PaytmChecksum.getStringByParams(params);
|
|
62
|
-
}
|
|
63
|
-
return PaytmChecksum.generateSignatureByString(params, key);
|
|
64
|
-
}
|
|
65
|
-
static verifySignature(params, key, checksum) {
|
|
66
|
-
if (typeof params !== 'object' && typeof params !== 'string') {
|
|
67
|
-
const error = 'string or object expected, ' + (typeof params) + ' given.';
|
|
68
|
-
return Promise.reject(error);
|
|
69
|
-
}
|
|
70
|
-
if (typeof params !== 'string') {
|
|
71
|
-
if (params.hasOwnProperty('CHECKSUMHASH')) {
|
|
72
|
-
delete params.CHECKSUMHASH;
|
|
73
|
-
}
|
|
74
|
-
params = PaytmChecksum.getStringByParams(params);
|
|
75
|
-
}
|
|
76
|
-
return PaytmChecksum.verifySignatureByString(params, key, checksum);
|
|
77
|
-
}
|
|
78
|
-
static async generateSignatureByString(params, key) {
|
|
79
|
-
const salt = await PaytmChecksum.generateRandomString(4);
|
|
80
|
-
return PaytmChecksum.calculateChecksum(params, key, salt);
|
|
81
|
-
}
|
|
82
|
-
static verifySignatureByString(params, key, checksum) {
|
|
83
|
-
const paytm_hash = PaytmChecksum.decrypt(checksum, key);
|
|
84
|
-
const salt = paytm_hash.substr(paytm_hash.length - 4);
|
|
85
|
-
return (paytm_hash === PaytmChecksum.calculateHash(params, salt));
|
|
86
|
-
}
|
|
87
|
-
static generateRandomString(length) {
|
|
88
|
-
return new Promise(function (resolve, reject) {
|
|
89
|
-
crypto.randomBytes((length * 3.0) / 4.0, function (err, buf) {
|
|
90
|
-
if (!err) {
|
|
91
|
-
const salt = buf.toString('base64');
|
|
92
|
-
resolve(salt);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
console.log('error occurred in generateRandomString: ' + err);
|
|
96
|
-
reject(err);
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
static getStringByParams(params) {
|
|
102
|
-
const data = {};
|
|
103
|
-
Object.keys(params).sort().forEach(function (key) {
|
|
104
|
-
data[key] = (params[key] !== null && String(params[key]).toLowerCase() !== 'null') ? params[key] : '';
|
|
105
|
-
});
|
|
106
|
-
return Object.values(data).join('|');
|
|
107
|
-
}
|
|
108
|
-
static calculateHash(params, salt) {
|
|
109
|
-
const finalString = params + '|' + salt;
|
|
110
|
-
return crypto.createHash('sha256').update(finalString).digest('hex') + salt;
|
|
111
|
-
}
|
|
112
|
-
static calculateChecksum(params, key, salt) {
|
|
113
|
-
const hashString = PaytmChecksum.calculateHash(params, salt);
|
|
114
|
-
return PaytmChecksum.encrypt(hashString, key);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
PaytmChecksum.iv = '@@@@&&&&####$$$$';
|
|
118
|
-
exports.default = PaytmChecksum;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare function genchecksum(params: Record<string, any>, key: string, cb: (err: any, checksum?: string) => void): Promise<void>;
|
|
2
|
-
export declare function genchecksumbystring(params: string, key: string, cb: (err: any, checksum?: string) => void): void;
|
|
3
|
-
export declare function verifychecksum(params: Record<string, any>, key: string, checksumhash?: string): boolean | Promise<never>;
|
|
4
|
-
export declare function verifychecksumbystring(params: string, key: string, checksumhash: string): boolean;
|
|
5
|
-
export declare function genchecksumforrefund(params: Record<string, any>, key: string, cb: (err: any, result?: any) => void): void;
|
|
6
|
-
export declare function checkRazorSignature(razorpayOrderId: string, razorpayPaymentId: string, secret: string, razorpay_signature: string): boolean;
|
|
7
|
-
declare const _default: {
|
|
8
|
-
genchecksum: typeof genchecksum;
|
|
9
|
-
verifychecksum: typeof verifychecksum;
|
|
10
|
-
verifychecksumbystring: typeof verifychecksumbystring;
|
|
11
|
-
genchecksumbystring: typeof genchecksumbystring;
|
|
12
|
-
genchecksumforrefund: typeof genchecksumforrefund;
|
|
13
|
-
checkRazorSignature: typeof checkRazorSignature;
|
|
14
|
-
};
|
|
15
|
-
export default _default;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.genchecksum = genchecksum;
|
|
40
|
-
exports.genchecksumbystring = genchecksumbystring;
|
|
41
|
-
exports.verifychecksum = verifychecksum;
|
|
42
|
-
exports.verifychecksumbystring = verifychecksumbystring;
|
|
43
|
-
exports.genchecksumforrefund = genchecksumforrefund;
|
|
44
|
-
exports.checkRazorSignature = checkRazorSignature;
|
|
45
|
-
const crypto = __importStar(require("crypto"));
|
|
46
|
-
const crypt = __importStar(require("./crypt"));
|
|
47
|
-
const PaytmChecksum_1 = __importDefault(require("./PaytmChecksum"));
|
|
48
|
-
// Note: some code referenced a `mandatoryParams` variable in the original JS. If your app
|
|
49
|
-
// defines it globally, this will pick it up; otherwise default to empty array.
|
|
50
|
-
const mandatoryParams = global.mandatoryParams || [];
|
|
51
|
-
function paramsToString(params, mandatoryflag) {
|
|
52
|
-
let data = '';
|
|
53
|
-
const tempKeys = Object.keys(params);
|
|
54
|
-
tempKeys.sort();
|
|
55
|
-
tempKeys.forEach(function (key) {
|
|
56
|
-
if (!params[key]) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
try {
|
|
60
|
-
const n = String(params[key]).includes('REFUND');
|
|
61
|
-
const m = String(params[key]).includes('|');
|
|
62
|
-
if (n === true) {
|
|
63
|
-
params[key] = '';
|
|
64
|
-
}
|
|
65
|
-
if (m === true) {
|
|
66
|
-
params[key] = '';
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
params[key] = '';
|
|
71
|
-
console.log(e);
|
|
72
|
-
}
|
|
73
|
-
if (key !== 'CHECKSUMHASH') {
|
|
74
|
-
if (params[key] === 'null')
|
|
75
|
-
params[key] = '';
|
|
76
|
-
if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
|
|
77
|
-
data += (params[key] + '|');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
function genchecksum(params, key, cb) {
|
|
84
|
-
const checksumPromise = PaytmChecksum_1.default.generateSignature(params, key).then(checksum => {
|
|
85
|
-
cb(undefined, checksum);
|
|
86
|
-
}).catch(err => cb(err));
|
|
87
|
-
return checksumPromise;
|
|
88
|
-
}
|
|
89
|
-
function genchecksumbystring(params, key, cb) {
|
|
90
|
-
crypt.gen_salt(4).then(salt => {
|
|
91
|
-
const sha256 = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
|
|
92
|
-
const check_sum = sha256 + salt;
|
|
93
|
-
const encrypted = crypt.encrypt(check_sum, key);
|
|
94
|
-
const CHECKSUMHASH = encrypted;
|
|
95
|
-
cb(undefined, CHECKSUMHASH);
|
|
96
|
-
}).catch(err => cb(err));
|
|
97
|
-
}
|
|
98
|
-
function verifychecksum(params, key, checksumhash) {
|
|
99
|
-
return PaytmChecksum_1.default.verifySignature(params, key, checksumhash);
|
|
100
|
-
}
|
|
101
|
-
function verifychecksumbystring(params, key, checksumhash) {
|
|
102
|
-
const checksum = crypt.decrypt(checksumhash, key);
|
|
103
|
-
const salt = checksum.substr(checksum.length - 4);
|
|
104
|
-
const sha256 = checksum.substr(0, checksum.length - 4);
|
|
105
|
-
const hash = crypto.createHash('sha256').update(params + '|' + salt).digest('hex');
|
|
106
|
-
if (hash === sha256) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
console.log('checksum is wrong');
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function genchecksumforrefund(params, key, cb) {
|
|
115
|
-
const data = paramsToStringrefund(params);
|
|
116
|
-
crypt.gen_salt(4).then(salt => {
|
|
117
|
-
const sha256 = crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
118
|
-
const check_sum = sha256 + salt;
|
|
119
|
-
const encrypted = crypt.encrypt(check_sum, key);
|
|
120
|
-
params.CHECKSUM = encodeURIComponent(encrypted);
|
|
121
|
-
cb(undefined, params);
|
|
122
|
-
}).catch(err => cb(err));
|
|
123
|
-
}
|
|
124
|
-
function paramsToStringrefund(params, mandatoryflag) {
|
|
125
|
-
let data = '';
|
|
126
|
-
const tempKeys = Object.keys(params);
|
|
127
|
-
tempKeys.sort();
|
|
128
|
-
tempKeys.forEach(function (key) {
|
|
129
|
-
const m = String(params[key]).includes('|');
|
|
130
|
-
if (m == true) {
|
|
131
|
-
params[key] = '';
|
|
132
|
-
}
|
|
133
|
-
if (key !== 'CHECKSUMHASH') {
|
|
134
|
-
if (params[key] === 'null')
|
|
135
|
-
params[key] = '';
|
|
136
|
-
if (!mandatoryflag || mandatoryParams.indexOf(key) !== -1) {
|
|
137
|
-
data += (params[key] + '|');
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
return data;
|
|
142
|
-
}
|
|
143
|
-
function checkRazorSignature(razorpayOrderId, razorpayPaymentId, secret, razorpay_signature) {
|
|
144
|
-
const hmac = crypto.createHmac('sha256', secret);
|
|
145
|
-
hmac.update(razorpayOrderId + '|' + razorpayPaymentId);
|
|
146
|
-
const generatedSignature = hmac.digest('hex');
|
|
147
|
-
const isSignatureValid = generatedSignature == razorpay_signature;
|
|
148
|
-
return isSignatureValid;
|
|
149
|
-
}
|
|
150
|
-
// CommonJS compatibility
|
|
151
|
-
exports.default = {
|
|
152
|
-
genchecksum,
|
|
153
|
-
verifychecksum,
|
|
154
|
-
verifychecksumbystring,
|
|
155
|
-
genchecksumbystring,
|
|
156
|
-
genchecksumforrefund,
|
|
157
|
-
checkRazorSignature,
|
|
158
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const iv = "@@@@&&&&####$$$$";
|
|
2
|
-
export declare function encrypt(data: string, custom_key: string): string;
|
|
3
|
-
export declare function decrypt(data: string, custom_key: string): string;
|
|
4
|
-
export declare function gen_salt(length: number): Promise<string>;
|
|
5
|
-
export declare function md5sum(salt: string, data: string): string;
|
|
6
|
-
export declare function sha256sum(salt: string, data: string): string;
|
|
7
|
-
declare const _default: {
|
|
8
|
-
iv: string;
|
|
9
|
-
encrypt: typeof encrypt;
|
|
10
|
-
decrypt: typeof decrypt;
|
|
11
|
-
gen_salt: typeof gen_salt;
|
|
12
|
-
md5sum: typeof md5sum;
|
|
13
|
-
sha256sum: typeof sha256sum;
|
|
14
|
-
};
|
|
15
|
-
export default _default;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.iv = void 0;
|
|
40
|
-
exports.encrypt = encrypt;
|
|
41
|
-
exports.decrypt = decrypt;
|
|
42
|
-
exports.gen_salt = gen_salt;
|
|
43
|
-
exports.md5sum = md5sum;
|
|
44
|
-
exports.sha256sum = sha256sum;
|
|
45
|
-
const crypto = __importStar(require("crypto"));
|
|
46
|
-
const util_1 = __importDefault(require("util"));
|
|
47
|
-
exports.iv = '@@@@&&&&####$$$$';
|
|
48
|
-
function encrypt(data, custom_key) {
|
|
49
|
-
const key = custom_key;
|
|
50
|
-
let algo = '256';
|
|
51
|
-
switch (key.length) {
|
|
52
|
-
case 16:
|
|
53
|
-
algo = '128';
|
|
54
|
-
break;
|
|
55
|
-
case 24:
|
|
56
|
-
algo = '192';
|
|
57
|
-
break;
|
|
58
|
-
case 32:
|
|
59
|
-
algo = '256';
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
const cipher = crypto.createCipheriv('AES-' + algo + '-CBC', key, exports.iv);
|
|
63
|
-
let encrypted = cipher.update(data, 'binary', 'base64');
|
|
64
|
-
encrypted += cipher.final('base64');
|
|
65
|
-
return encrypted;
|
|
66
|
-
}
|
|
67
|
-
function decrypt(data, custom_key) {
|
|
68
|
-
const key = custom_key;
|
|
69
|
-
let algo = '256';
|
|
70
|
-
switch (key.length) {
|
|
71
|
-
case 16:
|
|
72
|
-
algo = '128';
|
|
73
|
-
break;
|
|
74
|
-
case 24:
|
|
75
|
-
algo = '192';
|
|
76
|
-
break;
|
|
77
|
-
case 32:
|
|
78
|
-
algo = '256';
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
const decipher = crypto.createDecipheriv('AES-' + algo + '-CBC', key, exports.iv);
|
|
82
|
-
let decrypted = decipher.update(data, 'base64', 'binary');
|
|
83
|
-
try {
|
|
84
|
-
decrypted += decipher.final('binary');
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
console.log(util_1.default.inspect(e));
|
|
88
|
-
}
|
|
89
|
-
return decrypted;
|
|
90
|
-
}
|
|
91
|
-
function gen_salt(length) {
|
|
92
|
-
return new Promise((resolve, reject) => {
|
|
93
|
-
crypto.randomBytes((length * 3.0) / 4.0, function (err, buf) {
|
|
94
|
-
if (!err) {
|
|
95
|
-
resolve(buf.toString('base64'));
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
reject(err);
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
function md5sum(salt, data) {
|
|
104
|
-
return crypto.createHash('md5').update(salt + data).digest('hex');
|
|
105
|
-
}
|
|
106
|
-
function sha256sum(salt, data) {
|
|
107
|
-
return crypto.createHash('sha256').update(data + salt).digest('hex');
|
|
108
|
-
}
|
|
109
|
-
// CommonJS compatibility
|
|
110
|
-
exports.default = {
|
|
111
|
-
iv: exports.iv,
|
|
112
|
-
encrypt,
|
|
113
|
-
decrypt,
|
|
114
|
-
gen_salt,
|
|
115
|
-
md5sum,
|
|
116
|
-
sha256sum,
|
|
117
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|