node-paytmpg 7.5.17 → 7.5.19
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/dist/app/controllers/adapters/open_money.d.ts +23 -0
- package/dist/app/controllers/adapters/open_money.js +399 -0
- package/dist/app/controllers/adapters/paytm.d.ts +2 -0
- package/dist/app/controllers/adapters/paytm.js +34 -0
- package/dist/app/controllers/adapters/payu.d.ts +50 -0
- package/dist/app/controllers/adapters/payu.js +238 -0
- package/dist/app/controllers/checksum/PaytmChecksum.d.ts +13 -0
- package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
- package/dist/app/controllers/checksum/checksum.d.ts +15 -0
- package/dist/app/controllers/checksum/checksum.js +158 -0
- package/dist/app/controllers/checksum/crypt.d.ts +15 -0
- package/dist/app/controllers/checksum/crypt.js +117 -0
- package/dist/app/controllers/checksum/server.d.ts +1 -0
- package/dist/app/controllers/checksum/server.js +132 -0
- package/dist/app/controllers/htmlhelper.d.ts +9 -0
- package/dist/app/controllers/htmlhelper.js +95 -0
- package/dist/app/controllers/payment.controller.d.ts +33 -0
- package/dist/app/controllers/payment.controller.js +1128 -0
- package/dist/app/controllers/static/loadingsvg.d.ts +1 -0
- package/dist/app/controllers/static/loadingsvg.js +54 -0
- package/dist/app/controllers/user.controller.d.ts +9 -0
- package/dist/app/controllers/user.controller.js +53 -0
- package/dist/app/models/index.d.ts +103 -0
- package/dist/app/models/index.js +2 -0
- package/dist/app/routes/payment_route.d.ts +2 -0
- package/dist/app/routes/payment_route.js +46 -0
- package/dist/app/utils/buildConfig.d.ts +4 -0
- package/dist/app/utils/buildConfig.js +224 -0
- package/dist/app/utils/utils.d.ts +5 -0
- package/dist/app/utils/utils.js +20 -0
- package/dist/app/views/home.hbs +22 -0
- package/dist/app/views/init.hbs +104 -0
- package/dist/app/views/layouts/index.hbs +53 -0
- package/dist/app/views/result.hbs +33 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +120 -0
- package/dist/package.json +68 -0
- package/package.json +1 -1
|
@@ -0,0 +1,132 @@
|
|
|
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 http = __importStar(require("http"));
|
|
37
|
+
const https = __importStar(require("https"));
|
|
38
|
+
const qs = __importStar(require("querystring"));
|
|
39
|
+
const checksum_1 = require("./checksum");
|
|
40
|
+
const port = 8080;
|
|
41
|
+
const PaytmConfig = {
|
|
42
|
+
mid: 'XXXXXXXXXXXXXXXXXXXX',
|
|
43
|
+
key: 'XXXXXXXXXXXXXXXX',
|
|
44
|
+
website: 'XXXXXXXXXX',
|
|
45
|
+
};
|
|
46
|
+
http.createServer(function (req, res) {
|
|
47
|
+
switch (req.url) {
|
|
48
|
+
case '/': {
|
|
49
|
+
const params = {};
|
|
50
|
+
params['MID'] = PaytmConfig.mid;
|
|
51
|
+
params['WEBSITE'] = PaytmConfig.website;
|
|
52
|
+
params['CHANNEL_ID'] = 'WEB';
|
|
53
|
+
params['INDUSTRY_TYPE_ID'] = 'Retail';
|
|
54
|
+
params['ORDER_ID'] = 'TEST_' + new Date().getTime();
|
|
55
|
+
params['CUST_ID'] = 'Customer001';
|
|
56
|
+
params['TXN_AMOUNT'] = '1.00';
|
|
57
|
+
params['CALLBACK_URL'] = 'http://localhost:' + port + '/callback';
|
|
58
|
+
params['EMAIL'] = 'abc@mailinator.com';
|
|
59
|
+
params['MOBILE_NO'] = '7777777777';
|
|
60
|
+
(0, checksum_1.genchecksum)(params, PaytmConfig.key, function (err, checksum) {
|
|
61
|
+
const txn_url = 'https://securegw-stage.paytm.in/theia/processTransaction';
|
|
62
|
+
let form_fields = '';
|
|
63
|
+
for (const x in params) {
|
|
64
|
+
form_fields += "<input type='hidden' name='" + x + "' value='" + params[x] + "' >";
|
|
65
|
+
}
|
|
66
|
+
form_fields += "<input type='hidden' name='CHECKSUMHASH' value='" + checksum + "' >";
|
|
67
|
+
const html = require('../htmlhelper').buildAutoPostFormHtml(txn_url, Object.assign({}, params, { CHECKSUMHASH: checksum }), 'Merchant Checkout Page');
|
|
68
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
69
|
+
res.write(html);
|
|
70
|
+
res.end();
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case '/callback': {
|
|
75
|
+
let body = '';
|
|
76
|
+
req.on('data', function (data) {
|
|
77
|
+
body += data;
|
|
78
|
+
});
|
|
79
|
+
req.on('end', function () {
|
|
80
|
+
let html = '';
|
|
81
|
+
const post_data = qs.parse(body);
|
|
82
|
+
console.log('Callback Response: ', post_data, '\n');
|
|
83
|
+
html += '<b>Callback Response</b><br>';
|
|
84
|
+
for (const x in post_data) {
|
|
85
|
+
html += x + ' => ' + post_data[x] + '<br/>';
|
|
86
|
+
}
|
|
87
|
+
html += '<br/><br/>';
|
|
88
|
+
const checksumhash = post_data.CHECKSUMHASH;
|
|
89
|
+
const result = (0, checksum_1.verifychecksum)(post_data, PaytmConfig.key, checksumhash);
|
|
90
|
+
console.log('Checksum Result => ', result, '\n');
|
|
91
|
+
html += '<b>Checksum Result</b> => ' + (result ? 'True' : 'False');
|
|
92
|
+
html += '<br/><br/>';
|
|
93
|
+
const params = { MID: PaytmConfig.mid, ORDERID: post_data.ORDERID };
|
|
94
|
+
(0, checksum_1.genchecksum)(params, PaytmConfig.key, function (err, checksum) {
|
|
95
|
+
params.CHECKSUMHASH = checksum;
|
|
96
|
+
const postData = 'JsonData=' + JSON.stringify(params);
|
|
97
|
+
const options = {
|
|
98
|
+
hostname: 'securegw-stage.paytm.in',
|
|
99
|
+
port: 443,
|
|
100
|
+
path: '/merchant-status/getTxnStatus',
|
|
101
|
+
method: 'POST',
|
|
102
|
+
headers: {
|
|
103
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
104
|
+
'Content-Length': Buffer.byteLength(postData),
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
let response = '';
|
|
108
|
+
const post_req = https.request(options, function (post_res) {
|
|
109
|
+
post_res.on('data', function (chunk) {
|
|
110
|
+
response += chunk;
|
|
111
|
+
});
|
|
112
|
+
post_res.on('end', function () {
|
|
113
|
+
console.log('S2S Response: ', response, '\n');
|
|
114
|
+
const _result = JSON.parse(response);
|
|
115
|
+
html += '<b>Status Check Response</b><br>';
|
|
116
|
+
for (const x in _result) {
|
|
117
|
+
html += x + ' => ' + _result[x] + '<br/>';
|
|
118
|
+
}
|
|
119
|
+
const out = require('../htmlhelper').buildProcessingPageHtml(html, '', 'Callback Response');
|
|
120
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
121
|
+
res.write(out);
|
|
122
|
+
res.end();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
post_req.write(postData);
|
|
126
|
+
post_req.end();
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}).listen(port);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { NPConfig } from '../models';
|
|
3
|
+
export declare function renderView(req: Request, res: Response, viewFile: string, data: any): void | Response<any, Record<string, any>>;
|
|
4
|
+
export declare function buildAutoPostFormHtml(action: string, fields: Record<string, any>, title?: string): string;
|
|
5
|
+
export declare function sendAutoPostForm(req: Request, res: Response, action: string, fields: Record<string, any>): Response<any, Record<string, any>>;
|
|
6
|
+
export declare function buildProcessingPageHtml(innerHtml: string, loadingSVG?: string, title?: string, headScripts?: string, bodyScripts?: string): string;
|
|
7
|
+
export declare function renderProcessingPage(req: Request, res: Response, innerHtml: string, loadingSVG?: string, headScripts?: string, bodyScripts?: string): Response<any, Record<string, any>>;
|
|
8
|
+
export declare function renderPaytmJsCheckout(req: Request, res: Response, paytmJsToken: any, config: NPConfig): Response<any, Record<string, any>>;
|
|
9
|
+
export declare function renderRazorpayCheckout(req: Request, res: Response, params: Record<string, any>, config: NPConfig, loadingSVG: string): Response<any, Record<string, any>>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderView = renderView;
|
|
4
|
+
exports.buildAutoPostFormHtml = buildAutoPostFormHtml;
|
|
5
|
+
exports.sendAutoPostForm = sendAutoPostForm;
|
|
6
|
+
exports.buildProcessingPageHtml = buildProcessingPageHtml;
|
|
7
|
+
exports.renderProcessingPage = renderProcessingPage;
|
|
8
|
+
exports.renderPaytmJsCheckout = renderPaytmJsCheckout;
|
|
9
|
+
exports.renderRazorpayCheckout = renderRazorpayCheckout;
|
|
10
|
+
const paytm_1 = require("./adapters/paytm");
|
|
11
|
+
function wantsJson(req) {
|
|
12
|
+
// Return true only when the caller EXPLICITLY sets Accept to only `application/json`.
|
|
13
|
+
// Examples that return true: "application/json" or "application/json; q=1"
|
|
14
|
+
// Examples that return false: "application/json, */*", "text/html", missing header, etc.
|
|
15
|
+
const hdr = String((req && req.headers && req.headers.accept) || '').trim().toLowerCase();
|
|
16
|
+
if (!hdr)
|
|
17
|
+
return false;
|
|
18
|
+
const types = hdr.split(',').map(t => t.split(';')[0].trim()).filter(Boolean);
|
|
19
|
+
return types.length > 0 && types.every(t => t === 'application/json');
|
|
20
|
+
}
|
|
21
|
+
function renderView(req, res, viewFile, data) {
|
|
22
|
+
if (wantsJson(req)) {
|
|
23
|
+
return res.json(data);
|
|
24
|
+
}
|
|
25
|
+
return res.render(viewFile, data);
|
|
26
|
+
}
|
|
27
|
+
function buildAutoPostFormHtml(action, fields, title = 'Merchant Checkout Error') {
|
|
28
|
+
const inputs = Object.keys(fields || {}).map((k) => {
|
|
29
|
+
const v = fields[k] === undefined || fields[k] === null ? '' : String(fields[k]);
|
|
30
|
+
return `<input type='hidden' name='${k}' value='${v}' >`;
|
|
31
|
+
}).join('');
|
|
32
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head><body><center><h1>Something went wrong. Please wait you will be redirected automatically...</h1></center><form method="post" action="${action}" name="f1">${inputs}</form><script type="text/javascript">document.f1.submit();</script></body></html>`;
|
|
33
|
+
}
|
|
34
|
+
function sendAutoPostForm(req, res, action, fields) {
|
|
35
|
+
if (wantsJson(req)) {
|
|
36
|
+
// send dynamic content as JSON instead of embedding in an HTML form
|
|
37
|
+
return res.status(res.statusCode || 200).json({ action, fields });
|
|
38
|
+
}
|
|
39
|
+
const html = buildAutoPostFormHtml(action, fields);
|
|
40
|
+
return res.status(200).contentType('text/html').send(html);
|
|
41
|
+
}
|
|
42
|
+
function buildProcessingPageHtml(innerHtml, loadingSVG = '', title = 'Merchant Checkout Page', headScripts = '', bodyScripts = '') {
|
|
43
|
+
return `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title>${headScripts}</head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${innerHtml}<br><br>${loadingSVG}</center>${bodyScripts}</body></html>`;
|
|
44
|
+
}
|
|
45
|
+
function renderProcessingPage(req, res, innerHtml, loadingSVG = '', headScripts = '', bodyScripts = '') {
|
|
46
|
+
if (wantsJson(req)) {
|
|
47
|
+
return res.json({ provider: 'processing', html: innerHtml, loadingSVG, headScripts, bodyScripts });
|
|
48
|
+
}
|
|
49
|
+
const html = buildProcessingPageHtml(innerHtml, loadingSVG, 'Merchant Checkout Page', headScripts, bodyScripts);
|
|
50
|
+
return res.status(200).contentType('text/html').send(html);
|
|
51
|
+
}
|
|
52
|
+
function renderPaytmJsCheckout(req, res, paytmJsToken, config) {
|
|
53
|
+
if (wantsJson(req)) {
|
|
54
|
+
// return the dynamic payload which would otherwise be embedded into the generated HTML
|
|
55
|
+
return res.json({ provider: 'paytm', token: paytmJsToken });
|
|
56
|
+
}
|
|
57
|
+
const html = (0, paytm_1.createPaytmJsCheckoutHtml)(paytmJsToken, config);
|
|
58
|
+
return res.send(html);
|
|
59
|
+
}
|
|
60
|
+
function renderRazorpayCheckout(req, res, params, config, loadingSVG) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const options = {
|
|
63
|
+
key: String(config.KEY),
|
|
64
|
+
amount: Number(params['TXN_AMOUNT']) * 100,
|
|
65
|
+
currency: 'INR',
|
|
66
|
+
name: params['PRODUCT_NAME'],
|
|
67
|
+
description: `Order # ${params['ORDER_ID']}`,
|
|
68
|
+
image: ((_a = config.theme) === null || _a === void 0 ? void 0 : _a.logo) || '',
|
|
69
|
+
order_id: params['ORDER_ID'],
|
|
70
|
+
callback_url: params['CALLBACK_URL'],
|
|
71
|
+
prefill: {
|
|
72
|
+
name: params['NAME'],
|
|
73
|
+
email: params['EMAIL'],
|
|
74
|
+
contact: params['MOBILE_NO']
|
|
75
|
+
},
|
|
76
|
+
theme: {
|
|
77
|
+
color: ((_b = config.theme) === null || _b === void 0 ? void 0 : _b.accent) || '#086cfe'
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
if (wantsJson(req)) {
|
|
81
|
+
return res.json({ provider: 'razorpay', options, failForm: { action: params['CALLBACK_URL'], fields: { razorpay_order_id: params['ORDER_ID'] } }, loadingSVG });
|
|
82
|
+
}
|
|
83
|
+
const fail = `<div style="display:none"><form method="post" action="${params['CALLBACK_URL']}" id="fail"><input name="razorpay_order_id" value="${params['ORDER_ID']}" hidden="true"/></form></div>`;
|
|
84
|
+
const scriptOptions = `
|
|
85
|
+
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
|
|
86
|
+
<script>
|
|
87
|
+
var options = ${JSON.stringify(options, null, 4)};
|
|
88
|
+
options.modal = options.modal || {};
|
|
89
|
+
options.modal.ondismiss = function(){ document.getElementById('fail').submit(); };
|
|
90
|
+
var rzp1 = new Razorpay(options);
|
|
91
|
+
rzp1.open();
|
|
92
|
+
</script>`;
|
|
93
|
+
const html = `<!doctype html><html><head><title>Merchant Checkout Page</title></head><body><center><h1>Processing ! Please do not refresh this page...</h1><br>${scriptOptions}<br>${fail}<br>${loadingSVG}</center></body></html>`;
|
|
94
|
+
return res.status(200).contentType('text/html').send(html);
|
|
95
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { MultiDbORM } from 'multi-db-orm';
|
|
2
|
+
import RazorPay from 'razorpay';
|
|
3
|
+
import OpenMoney from './adapters/open_money';
|
|
4
|
+
import PayU from './adapters/payu';
|
|
5
|
+
import { Request, Response } from 'express';
|
|
6
|
+
import { NPConfig, NPTableNames } from '../models';
|
|
7
|
+
export declare class PaymentController {
|
|
8
|
+
private baseConfig;
|
|
9
|
+
private callbacks;
|
|
10
|
+
private db;
|
|
11
|
+
private tableNames;
|
|
12
|
+
private useController;
|
|
13
|
+
private viewPath;
|
|
14
|
+
constructor(baseConfig: NPConfig, db: MultiDbORM, callbacks?: any, tableNames?: NPTableNames);
|
|
15
|
+
encodeTxnDataForUrl(txnDataJson: any, req: Request): string;
|
|
16
|
+
decodeTxnDataFromUrl(encodedStr: string, req?: Request): any;
|
|
17
|
+
getProviderInstance(providerName: string, config: NPConfig): PayU | OpenMoney | typeof RazorPay | null;
|
|
18
|
+
private configure;
|
|
19
|
+
private insertTransactionInDb;
|
|
20
|
+
private generateChecksum;
|
|
21
|
+
home(req: Request, res: Response): void | Response<any, Record<string, any>>;
|
|
22
|
+
init(req: Request, res: Response): Promise<void | Response<any, Record<string, any>>>;
|
|
23
|
+
updateTransaction(req: Request, res: Response, fromWebhook?: boolean): Promise<void>;
|
|
24
|
+
private getOrder;
|
|
25
|
+
callback(req: Request, res: Response): Promise<void>;
|
|
26
|
+
getServiceUsed(req: Request, baseConfig: NPConfig): string;
|
|
27
|
+
webhook(req: Request, res: Response): Promise<void>;
|
|
28
|
+
createTxn(req: Request, res: Response): Promise<void>;
|
|
29
|
+
createTxnToken(req: Request, res: Response): Promise<void>;
|
|
30
|
+
getTransactions(req: Request, res: Response): Promise<void>;
|
|
31
|
+
status(req: Request, res: Response): Promise<void>;
|
|
32
|
+
private getStatusFromPaytm;
|
|
33
|
+
}
|