node-paytmpg 7.5.17 → 7.5.18

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.
Files changed (38) hide show
  1. package/dist/app/controllers/adapters/open_money.d.ts +23 -0
  2. package/dist/app/controllers/adapters/open_money.js +399 -0
  3. package/dist/app/controllers/adapters/paytm.d.ts +2 -0
  4. package/dist/app/controllers/adapters/paytm.js +34 -0
  5. package/dist/app/controllers/adapters/payu.d.ts +50 -0
  6. package/dist/app/controllers/adapters/payu.js +238 -0
  7. package/dist/app/controllers/checksum/PaytmChecksum.d.ts +13 -0
  8. package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
  9. package/dist/app/controllers/checksum/checksum.d.ts +15 -0
  10. package/dist/app/controllers/checksum/checksum.js +158 -0
  11. package/dist/app/controllers/checksum/crypt.d.ts +15 -0
  12. package/dist/app/controllers/checksum/crypt.js +117 -0
  13. package/dist/app/controllers/checksum/server.d.ts +1 -0
  14. package/dist/app/controllers/checksum/server.js +132 -0
  15. package/dist/app/controllers/htmlhelper.d.ts +9 -0
  16. package/dist/app/controllers/htmlhelper.js +95 -0
  17. package/dist/app/controllers/payment.controller.d.ts +33 -0
  18. package/dist/app/controllers/payment.controller.js +1128 -0
  19. package/dist/app/controllers/static/loadingsvg.d.ts +1 -0
  20. package/dist/app/controllers/static/loadingsvg.js +54 -0
  21. package/dist/app/controllers/user.controller.d.ts +9 -0
  22. package/dist/app/controllers/user.controller.js +53 -0
  23. package/dist/app/models/index.d.ts +103 -0
  24. package/dist/app/models/index.js +2 -0
  25. package/dist/app/routes/payment_route.d.ts +2 -0
  26. package/dist/app/routes/payment_route.js +46 -0
  27. package/dist/app/utils/buildConfig.d.ts +4 -0
  28. package/dist/app/utils/buildConfig.js +224 -0
  29. package/dist/app/utils/utils.d.ts +5 -0
  30. package/dist/app/utils/utils.js +20 -0
  31. package/dist/app/views/home.hbs +22 -0
  32. package/dist/app/views/init.hbs +104 -0
  33. package/dist/app/views/layouts/index.hbs +53 -0
  34. package/dist/app/views/result.hbs +33 -0
  35. package/dist/index.d.ts +10 -0
  36. package/dist/index.js +120 -0
  37. package/dist/package.json +68 -0
  38. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export declare const 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\">\n<g transform=\"rotate(0 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.9166666666666666s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(30 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.8333333333333334s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(60 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.75s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(90 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.6666666666666666s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(120 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.5833333333333334s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(150 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.5s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(180 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.4166666666666667s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(210 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.3333333333333333s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(240 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.25s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(270 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.16666666666666666s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(300 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"-0.08333333333333333s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g><g transform=\"rotate(330 50 50)\">\n<rect x=\"47\" y=\"24\" rx=\"3\" ry=\"6\" width=\"6\" height=\"12\" fill=\"#0097a7\">\n <animate attributeName=\"opacity\" values=\"1;0\" keyTimes=\"0;1\" dur=\"1s\" begin=\"0s\" repeatCount=\"indefinite\"></animate>\n</rect>\n</g>\n</svg>";
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoadingSVG = void 0;
4
+ exports.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">
5
+ <g transform="rotate(0 50 50)">
6
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
7
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.9166666666666666s" repeatCount="indefinite"></animate>
8
+ </rect>
9
+ </g><g transform="rotate(30 50 50)">
10
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
11
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.8333333333333334s" repeatCount="indefinite"></animate>
12
+ </rect>
13
+ </g><g transform="rotate(60 50 50)">
14
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
15
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.75s" repeatCount="indefinite"></animate>
16
+ </rect>
17
+ </g><g transform="rotate(90 50 50)">
18
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
19
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.6666666666666666s" repeatCount="indefinite"></animate>
20
+ </rect>
21
+ </g><g transform="rotate(120 50 50)">
22
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
23
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5833333333333334s" repeatCount="indefinite"></animate>
24
+ </rect>
25
+ </g><g transform="rotate(150 50 50)">
26
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
27
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.5s" repeatCount="indefinite"></animate>
28
+ </rect>
29
+ </g><g transform="rotate(180 50 50)">
30
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
31
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.4166666666666667s" repeatCount="indefinite"></animate>
32
+ </rect>
33
+ </g><g transform="rotate(210 50 50)">
34
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
35
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.3333333333333333s" repeatCount="indefinite"></animate>
36
+ </rect>
37
+ </g><g transform="rotate(240 50 50)">
38
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
39
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.25s" repeatCount="indefinite"></animate>
40
+ </rect>
41
+ </g><g transform="rotate(270 50 50)">
42
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
43
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.16666666666666666s" repeatCount="indefinite"></animate>
44
+ </rect>
45
+ </g><g transform="rotate(300 50 50)">
46
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
47
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="-0.08333333333333333s" repeatCount="indefinite"></animate>
48
+ </rect>
49
+ </g><g transform="rotate(330 50 50)">
50
+ <rect x="47" y="24" rx="3" ry="6" width="6" height="12" fill="#0097a7">
51
+ <animate attributeName="opacity" values="1;0" keyTimes="0;1" dur="1s" begin="0s" repeatCount="indefinite"></animate>
52
+ </rect>
53
+ </g>
54
+ </svg>`;
@@ -0,0 +1,9 @@
1
+ import { MultiDbORM } from "multi-db-orm";
2
+ import { NPUser } from "../models";
3
+ export declare class NPUserController {
4
+ db: MultiDbORM;
5
+ tableName: string;
6
+ constructor(db: MultiDbORM, tableName?: string);
7
+ init(): Promise<void>;
8
+ create(userData: NPUser): Promise<NPUser>;
9
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NPUserController = void 0;
4
+ const utils_1 = require("../utils/utils");
5
+ class NPUserController {
6
+ constructor(db, tableName = 'npusers') {
7
+ this.db = db;
8
+ this.tableName = tableName;
9
+ }
10
+ async init() {
11
+ const sample = {
12
+ id: "user_aB3dE9xY1Z",
13
+ name: "tset",
14
+ email: "testgmailcom",
15
+ phone: "12345678",
16
+ };
17
+ this.db.create(this.tableName, sample);
18
+ }
19
+ async create(userData) {
20
+ try {
21
+ let user = await this.db.getOne(this.tableName, { email: userData.email });
22
+ if (user) {
23
+ const myquery = { email: userData.email };
24
+ const objForUpdate = Object.assign({}, user);
25
+ if (userData.email && userData.email.indexOf("@") !== -1)
26
+ objForUpdate.email = userData.email;
27
+ if (userData.phone && userData.phone.length > 2)
28
+ objForUpdate.phone = userData.phone;
29
+ if (userData.name && userData.name.length > 2)
30
+ objForUpdate.name = userData.name;
31
+ const newvalues = objForUpdate;
32
+ try {
33
+ await this.db.update(this.tableName, myquery, newvalues);
34
+ return objForUpdate;
35
+ }
36
+ catch (uErr) {
37
+ throw new Error(uErr.message || 'Some error occurred while updating users.');
38
+ }
39
+ }
40
+ else {
41
+ userData.id = "user_" + utils_1.Utils.makeid();
42
+ await this.db.insert(this.tableName, userData);
43
+ return userData;
44
+ }
45
+ }
46
+ catch (err) {
47
+ throw new Error(err.message || 'Some error occurred while creating users.');
48
+ }
49
+ }
50
+ ;
51
+ }
52
+ exports.NPUserController = NPUserController;
53
+ ;
@@ -0,0 +1,103 @@
1
+ export type Callback = (err?: any, res?: any) => void;
2
+ export interface NPUser {
3
+ id: string;
4
+ name: string;
5
+ email: string;
6
+ phone: string;
7
+ createdAt?: number;
8
+ }
9
+ /**
10
+ * NPTransaction is the interface for the transaction object stored in the database. It contains all the details of a transaction, including the order ID, customer ID, time of transaction, status, name, email, phone number, amount, product name, and any extra information.
11
+ * time: in miliseconds
12
+ * status: can be 'TXN_SUCCESS', 'TXN_FAILURE', 'PENDING', 'INITIATED'
13
+ * extra: json can be used to store any extra information related to the transaction, such as the payment method used, the bank name, etc.
14
+ */
15
+ export interface NPTransaction {
16
+ id: string;
17
+ orderId: string;
18
+ cusId: string;
19
+ time: Number;
20
+ status: string;
21
+ name: string;
22
+ email: string;
23
+ phone: string;
24
+ amount: Number;
25
+ pname: string;
26
+ extra: string;
27
+ readonly?: string;
28
+ txnId?: string;
29
+ clientId: string;
30
+ state?: string;
31
+ returnUrl: string;
32
+ webhookUrl: string;
33
+ }
34
+ export interface NPCallbacks {
35
+ onStart: (orderId: string, paymentData?: NPTransaction) => void;
36
+ onFinish: (orderId: string, paymentData?: NPTransaction) => void;
37
+ }
38
+ export type NPConfigTheme = {
39
+ logo: string;
40
+ primary: string;
41
+ accent: string;
42
+ surface: string;
43
+ text: string;
44
+ success: string;
45
+ danger: string;
46
+ name: string;
47
+ brand: string;
48
+ };
49
+ export type NPConfig = {
50
+ KEY: string;
51
+ SECRET: string;
52
+ MID?: string;
53
+ WEBSITE?: string;
54
+ CHANNEL_ID?: string;
55
+ INDUSTRY_TYPE_ID?: string;
56
+ CALLBACK_URL?: string;
57
+ enableConfirmationPage?: boolean;
58
+ paytm_url?: string;
59
+ mode?: string;
60
+ razor_url?: string;
61
+ open_money_url?: string;
62
+ payu_url?: string;
63
+ templateDir?: string;
64
+ view_path: string;
65
+ host_url?: string;
66
+ path_prefix: string;
67
+ id_length?: number;
68
+ getClientConfig?: (clientId: string) => Partial<NPConfigOverrides>;
69
+ theme?: NPConfigTheme;
70
+ };
71
+ export type NPConfigOverrides = {
72
+ theme?: NPConfigTheme;
73
+ paytm_url?: string;
74
+ razor_url?: string;
75
+ open_money_url?: string;
76
+ payu_url?: string;
77
+ KEY: string;
78
+ SECRET: string;
79
+ MID?: string;
80
+ CALLBACK_URL?: string;
81
+ host_url?: string;
82
+ path_prefix: string;
83
+ };
84
+ export type NPTableNames = {
85
+ USER: string;
86
+ TRANSACTION: string;
87
+ };
88
+ export type NPParam = {
89
+ ORDER_ID?: string;
90
+ CUST_ID?: string;
91
+ TXN_AMOUNT: string;
92
+ CALLBACK_URL?: string;
93
+ EMAIL?: string;
94
+ MOBILE_NO?: string;
95
+ NAME?: string;
96
+ PRODUCT_NAME?: string;
97
+ RETURN_URL?: string;
98
+ MID?: string;
99
+ WEBSITE?: string;
100
+ CHANNEL_ID?: string;
101
+ INDUSTRY_TYPE_ID?: string;
102
+ CURRENCY?: string;
103
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ declare const paymentRoute: (app: any, express: any, callbacks?: any) => any;
2
+ export default paymentRoute;
@@ -0,0 +1,46 @@
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 body_parser_1 = __importDefault(require("body-parser"));
7
+ const express_handlebars_1 = __importDefault(require("express-handlebars"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const payment_controller_1 = require("../controllers/payment.controller");
10
+ const paymentRoute = function (app, express, callbacks) {
11
+ const config = app.get('np_config');
12
+ const pc = new payment_controller_1.PaymentController(app, callbacks);
13
+ const router = express.Router();
14
+ app.set('view_path', __dirname + config.view_path);
15
+ const vp = app.get('view_path');
16
+ console.log('PaytmPG : Using MultiDB ORM');
17
+ app.engine('hbs', (0, express_handlebars_1.default)({
18
+ extname: 'hbs',
19
+ defaultLayout: vp + '/layouts/index.hbs',
20
+ helpers: {
21
+ theme_color: function () {
22
+ return config.theme_color;
23
+ },
24
+ logo: function () {
25
+ return config.logo;
26
+ }
27
+ }
28
+ }));
29
+ app.set('view engine', 'handlebars');
30
+ let saveRawBody = function (req, res, buf, encoding) {
31
+ req.rawBody = buf.toString();
32
+ };
33
+ app.use(body_parser_1.default.urlencoded({ extended: true }));
34
+ app.use(body_parser_1.default.json({ verify: saveRawBody }));
35
+ app.use('/' + config.path_prefix, express.static(path_1.default.join(__dirname, '../../public')));
36
+ app.use('/' + config.path_prefix, router);
37
+ router.all('/', pc.init);
38
+ router.all('/init', pc.init);
39
+ router.all('/callback', pc.callback);
40
+ router.all(['/api/webhook', '/api/webhook/*'], pc.webhook);
41
+ router.all('/api/status', pc.status);
42
+ router.all('/api/createTxn/token', pc.createTxnToken);
43
+ router.all('/api/createTxn', pc.createTxn);
44
+ return router;
45
+ };
46
+ exports.default = paymentRoute;
@@ -0,0 +1,4 @@
1
+ import { Request } from "express";
2
+ import { NPConfig, NPTransaction } from "../models";
3
+ export declare function withClientConfigOverrides(config: NPConfig, req: Request, orderData?: NPTransaction): NPConfig;
4
+ export declare function buildConfig(userConfig?: Record<string, any>): NPConfig;
@@ -0,0 +1,224 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withClientConfigOverrides = withClientConfigOverrides;
4
+ exports.buildConfig = buildConfig;
5
+ const defaults = {
6
+ // Server configuration
7
+ host_url: 'http://localhost:3000',
8
+ path_prefix: '_pay',
9
+ homepage: '/',
10
+ // Template configuration
11
+ templateDir: null, // null = use built-in views, or provide path to custom templates
12
+ templateEngine: 'handlebars',
13
+ // UI Customization
14
+ theme_color: '#3399cc',
15
+ logo: '/favicon.ico',
16
+ // Transaction ID configuration
17
+ id_length: 10,
18
+ // Database
19
+ db_url: null, // MongoDB URL (legacy), leave null to use multidborm
20
+ // Payment Gateway URLs
21
+ // paytm_url: null, // e.g., 'https://securegw-stage.paytm.in' for test, 'https://securegw.paytm.in' for production
22
+ // razor_url: null, // e.g., 'https://api.razorpay.com/v1/'
23
+ // payu_url: null, // e.g., 'https://test.payu.in' for test, 'https://secure.payu.in' for production
24
+ // open_money_url: null, // e.g., 'https://sandbox-icp-api.bankopen.co/api' for sandbox, 'https://icp-api.bankopen.co/api' for live
25
+ // Gateway Credentials (must be provided by user)
26
+ // MID: null,
27
+ // WEBSITE: null,
28
+ // KEY: null,
29
+ // SECRET: null,
30
+ // CHANNEL_ID: 'WEB',
31
+ // INDUSTRY_TYPE_ID: 'Retail',
32
+ // Payment mode configuration (optional)
33
+ // mode: null // JSON string of enabled payment modes for Paytm
34
+ };
35
+ function pickEnv(keys) {
36
+ const output = {};
37
+ keys.forEach((key) => {
38
+ if (process.env[key] !== undefined) {
39
+ output[key] = process.env[key];
40
+ }
41
+ });
42
+ return output;
43
+ }
44
+ /**
45
+ * Validates and merges config with defaults
46
+ * @param {Object} userConfig - User-provided configuration
47
+ * @returns {Object} Merged and validated configuration
48
+ * @throws {Error} If required fields are missing
49
+ */
50
+ function validateConfig(userConfig) {
51
+ if (!userConfig || typeof userConfig !== 'object') {
52
+ throw new Error('Config must be an object');
53
+ }
54
+ // Merge with defaults
55
+ const config = { ...defaults, ...userConfig };
56
+ // Detect which payment gateway is being used
57
+ const hasPaytm = !!config.paytm_url;
58
+ const hasRazorpay = !!config.razor_url;
59
+ const hasPayU = !!config.payu_url;
60
+ const hasOpenMoney = !!config.open_money_url;
61
+ if (!hasPaytm && !hasRazorpay && !hasPayU && !hasOpenMoney) {
62
+ throw new Error('At least one payment gateway must be configured. ' +
63
+ 'Please provide one of: paytm_url, razor_url, payu_url, or open_money_url');
64
+ }
65
+ // Validate required credentials based on gateway
66
+ if (hasPaytm) {
67
+ validatePaytmConfig(config);
68
+ }
69
+ if (hasRazorpay) {
70
+ validateRazorpayConfig(config);
71
+ }
72
+ if (hasPayU) {
73
+ validatePayUConfig(config);
74
+ }
75
+ if (hasOpenMoney) {
76
+ validateOpenMoneyConfig(config);
77
+ }
78
+ // Validate common fields
79
+ if (!config.host_url) {
80
+ throw new Error('host_url is required');
81
+ }
82
+ if (!config.path_prefix) {
83
+ throw new Error('path_prefix is required');
84
+ }
85
+ return config;
86
+ }
87
+ function validatePaytmConfig(config) {
88
+ const required = ['MID', 'WEBSITE', 'KEY', 'CHANNEL_ID', 'INDUSTRY_TYPE_ID'];
89
+ const missing = required.filter(field => !config[field]);
90
+ if (missing.length > 0) {
91
+ throw new Error(`Paytm configuration incomplete. Missing fields: ${missing.join(', ')}`);
92
+ }
93
+ }
94
+ function validateRazorpayConfig(config) {
95
+ const required = ['KEY', 'SECRET'];
96
+ const missing = required.filter(field => !config[field]);
97
+ if (missing.length > 0) {
98
+ throw new Error(`Razorpay configuration incomplete. Missing fields: ${missing.join(', ')}`);
99
+ }
100
+ }
101
+ function validatePayUConfig(config) {
102
+ const required = ['KEY', 'SECRET'];
103
+ const missing = required.filter(field => !config[field]);
104
+ if (missing.length > 0) {
105
+ throw new Error(`PayU configuration incomplete. Missing fields: ${missing.join(', ')}`);
106
+ }
107
+ }
108
+ function validateOpenMoneyConfig(config) {
109
+ const required = ['KEY', 'SECRET'];
110
+ const missing = required.filter(field => !config[field]);
111
+ if (missing.length > 0) {
112
+ throw new Error(`OpenMoney configuration incomplete. Missing fields: ${missing.join(', ')}`);
113
+ }
114
+ }
115
+ function withClientConfigOverrides(config, req, orderData) {
116
+ let _client = config;
117
+ if (config.getClientConfig && (req || (orderData === null || orderData === void 0 ? void 0 : orderData.clientId))) {
118
+ const clientId = (orderData === null || orderData === void 0 ? void 0 : orderData.clientId) || req.headers['x-client-id'] || req.query.client_id || req.body.client_id || req.body.CLIENT_ID || req.query.CLIENT_ID;
119
+ if (clientId) {
120
+ const clientConfig = config.getClientConfig(clientId);
121
+ if (clientConfig) {
122
+ _client = { ...config, ...clientConfig };
123
+ }
124
+ }
125
+ }
126
+ return _client;
127
+ }
128
+ function buildConfig(userConfig = {}) {
129
+ var _a, _b, _c, _d, _e, _f;
130
+ const envOverrides = pickEnv([
131
+ 'NP_HOST_URL',
132
+ 'NP_PATH_PREFIX',
133
+ 'NP_HOMEPAGE',
134
+ 'NP_TEMPLATE_DIR',
135
+ 'NP_THEME_COLOR',
136
+ 'NP_LOGO',
137
+ 'NP_DB_URL',
138
+ 'NP_PAYTM_URL',
139
+ 'NP_RAZOR_URL',
140
+ 'NP_PAYU_URL',
141
+ 'NP_OPEN_MONEY_URL',
142
+ 'NP_MID',
143
+ 'NP_WEBSITE',
144
+ 'NP_KEY',
145
+ 'NP_SECRET',
146
+ 'NP_CHANNEL_ID',
147
+ 'NP_INDUSTRY_TYPE_ID',
148
+ 'NP_MODE',
149
+ 'NP_THEME_NAME',
150
+ ]);
151
+ const merged = {
152
+ ...defaults,
153
+ ...normalizeEnv(envOverrides),
154
+ ...userConfig,
155
+ };
156
+ // theme normalization
157
+ const themeName = (userConfig.themeName || ((_a = userConfig.theme) === null || _a === void 0 ? void 0 : _a.name) || merged.theme_name || 'dark').toLowerCase();
158
+ const theme = {
159
+ primary: getThemeColor(userConfig, merged),
160
+ accent: ((_b = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _b === void 0 ? void 0 : _b.accent) || merged.theme_accent || '#4ae0ff',
161
+ surface: ((_c = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _c === void 0 ? void 0 : _c.surface) || '#0f1021',
162
+ text: ((_d = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _d === void 0 ? void 0 : _d.text) || '#e9ecf2',
163
+ success: ((_e = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _e === void 0 ? void 0 : _e.success) || '#24cf5f',
164
+ danger: ((_f = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _f === void 0 ? void 0 : _f.danger) || '#ff6b6b',
165
+ name: themeName,
166
+ };
167
+ merged.theme = theme;
168
+ merged.theme_color = theme.primary;
169
+ merged.logo = userConfig.logo || merged.logo;
170
+ merged.brand = userConfig.brand || 'Secure Pay';
171
+ merged.callbacks = userConfig.callbacks || userConfig.hooks || merged.callbacks || {};
172
+ merged.templateDir = userConfig.templateDir || merged.templateDir;
173
+ merged.themeName = themeName;
174
+ // ensure view path remains compatible with legacy controllers
175
+ if (!merged.view_path) {
176
+ merged.view_path = '/../views/';
177
+ }
178
+ if (userConfig.host_url) {
179
+ merged.host_url = userConfig.host_url;
180
+ }
181
+ else if (process.env.NP_HOST_URL) {
182
+ merged.host_url = process.env.NP_HOST_URL;
183
+ }
184
+ return validateConfig(merged);
185
+ }
186
+ function getThemeColor(userConfig, merged) {
187
+ var _a;
188
+ if ((_a = userConfig === null || userConfig === void 0 ? void 0 : userConfig.theme) === null || _a === void 0 ? void 0 : _a.primary)
189
+ return userConfig.theme.primary;
190
+ if (userConfig.theme_color)
191
+ return userConfig.theme_color;
192
+ if (merged.NP_THEME_COLOR)
193
+ return merged.NP_THEME_COLOR;
194
+ return merged.theme_color;
195
+ }
196
+ function normalizeEnv(env) {
197
+ const mapping = {
198
+ NP_HOST_URL: 'host_url',
199
+ NP_PATH_PREFIX: 'path_prefix',
200
+ NP_HOMEPAGE: 'homepage',
201
+ NP_TEMPLATE_DIR: 'templateDir',
202
+ NP_THEME_COLOR: 'theme_color',
203
+ NP_LOGO: 'logo',
204
+ NP_DB_URL: 'db_url',
205
+ NP_PAYTM_URL: 'paytm_url',
206
+ NP_RAZOR_URL: 'razor_url',
207
+ NP_PAYU_URL: 'payu_url',
208
+ NP_OPEN_MONEY_URL: 'open_money_url',
209
+ NP_MID: 'MID',
210
+ NP_WEBSITE: 'WEBSITE',
211
+ NP_KEY: 'KEY',
212
+ NP_SECRET: 'SECRET',
213
+ NP_CHANNEL_ID: 'CHANNEL_ID',
214
+ NP_INDUSTRY_TYPE_ID: 'INDUSTRY_TYPE_ID',
215
+ NP_MODE: 'mode',
216
+ NP_THEME_NAME: 'themeName',
217
+ };
218
+ return Object.keys(env).reduce((acc, key) => {
219
+ const target = mapping[key];
220
+ if (target)
221
+ acc[target] = env[key];
222
+ return acc;
223
+ }, {});
224
+ }
@@ -0,0 +1,5 @@
1
+ import { NPTransaction } from "../models";
2
+ export declare class Utils {
3
+ static makeid(length?: number): string;
4
+ static sanitizeRequest(body: NPTransaction | any): void;
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Utils = void 0;
4
+ const IDLEN = 10;
5
+ class Utils {
6
+ static makeid(length = IDLEN) {
7
+ let text = "";
8
+ const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9
+ for (let i = 0; i < length; i++)
10
+ text += possible.charAt(Math.floor(Math.random() * possible.length));
11
+ return text;
12
+ }
13
+ static sanitizeRequest(body) {
14
+ if (body.amount)
15
+ body.amount = parseFloat(body.amount);
16
+ if (body.TXN_AMOUNT)
17
+ body.amount = parseFloat(body.TXN_AMOUNT);
18
+ }
19
+ }
20
+ exports.Utils = Utils;
@@ -0,0 +1,22 @@
1
+ <p>
2
+ <h4>About</h4>
3
+ <div>
4
+
5
+ <table border="1">
6
+
7
+ <tr>
8
+ <td>Name</td><td>{{name}}</td>
9
+ </tr>
10
+ <tr>
11
+ <td>Version</td><td>{{version}}</td>
12
+ </tr>
13
+ <tr>
14
+ <td>Repository</td><td><a href='{{repository.url}}'>GITHUB</a></td>
15
+ </tr>
16
+
17
+
18
+ </table>
19
+
20
+
21
+ </div>
22
+ </p>