node-paytmpg 7.1.3 → 7.1.6

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.
@@ -0,0 +1,23 @@
1
+ export interface OpenMoneyConfig {
2
+ accesskey: string;
3
+ secretkey: string;
4
+ url: string;
5
+ script_url: string;
6
+ KEY?: string;
7
+ SECRET?: string;
8
+ open_money_url?: string;
9
+ }
10
+ type AnyObject = {
11
+ [k: string]: any;
12
+ };
13
+ export default class OpenMoney {
14
+ config: OpenMoneyConfig;
15
+ constructor(npconfig: AnyObject);
16
+ generatePaymentToken(params: AnyObject): Promise<AnyObject>;
17
+ verifyResult(req: AnyObject): Promise<AnyObject>;
18
+ processWebhook(req: AnyObject, res: AnyObject, updateTransaction: Function): void;
19
+ getPaymentStatus(paymentTokenId: string, cb?: (data: any) => void): Promise<any>;
20
+ renderProcessingPage(params: AnyObject, pmttoken: AnyObject, res: AnyObject, loadingSVG: string): void;
21
+ renderError(params: AnyObject, error: any, res: AnyObject): void;
22
+ }
23
+ export {};
@@ -0,0 +1,2 @@
1
+ import { NPConfig, NPParam } from "../../models";
2
+ export declare function createPaytmJsCheckoutHtml(params: NPParam, config: NPConfig): string;
@@ -0,0 +1,41 @@
1
+ type Dict = Record<string, any>;
2
+ interface PayUConfig {
3
+ key: string;
4
+ salt: string;
5
+ baseUrl: string;
6
+ paymentUrl: string;
7
+ verifyUrl: string;
8
+ }
9
+ interface PayURequestLike {
10
+ body?: Dict;
11
+ query?: Dict;
12
+ rawBody?: any;
13
+ headers?: Dict;
14
+ }
15
+ interface PayUResponseLike {
16
+ writeHead: (status: number, headers: Dict) => void;
17
+ write: (chunk: string) => void;
18
+ end: () => void;
19
+ status: (code: number) => void;
20
+ send: (body: any) => void;
21
+ }
22
+ declare class PayU {
23
+ config: PayUConfig;
24
+ constructor(npconfig: Dict);
25
+ normalizeAmount(amount: any): string;
26
+ buildRequestHash(payload: Dict): string;
27
+ buildResponseHash(data: Dict): string;
28
+ generatePaymentRequest(params: Dict): {
29
+ html: string;
30
+ payload: Dict;
31
+ };
32
+ decodeTransactionResponse(txnDataBase64FromPayu: string): Dict;
33
+ verifyResult(req: PayURequestLike): Promise<Dict>;
34
+ getPaymentStatus(txnId: string): Promise<Dict>;
35
+ postCommand(command: string, transactionId: string): Promise<Dict>;
36
+ checkBqrTxnStatus(transactionId: string): Promise<Dict>;
37
+ renderProcessingPage(params: Dict, paymentReq: Dict, res: PayUResponseLike, loadingSVG: string): void;
38
+ renderError(params: Dict, error: any, res: PayUResponseLike): void;
39
+ processWebhook(req: PayURequestLike, res: PayUResponseLike, updateTransaction: Function): void;
40
+ }
41
+ export default PayU;
@@ -0,0 +1,13 @@
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
+ }
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1 @@
1
+ export {};
@@ -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,30 @@
1
+ import { MultiDbORM } from 'multi-db-orm';
2
+ import { Request, Response } from 'express';
3
+ import { NPConfig, NPTableNames } from '../models';
4
+ export declare class PaymentController {
5
+ private config;
6
+ private callbacks;
7
+ private db;
8
+ private tableNames;
9
+ private useController;
10
+ private viewPath;
11
+ private payuInstance;
12
+ private openMoneyInstance;
13
+ private razorPayInstance;
14
+ constructor(config: NPConfig, db: MultiDbORM, callbacks?: any, tableNames?: NPTableNames);
15
+ encodeTxnDataForUrl(txnDataJson: any): string;
16
+ decodeTxnDataFromUrl(encodedStr: string): any;
17
+ private configure;
18
+ private insertTransactionInDb;
19
+ private generateChecksum;
20
+ home(req: Request, res: Response): void | Response<any, Record<string, any>>;
21
+ init(req: Request, res: Response): Promise<void | Response<any, Record<string, any>>>;
22
+ updateTransaction(req: Request, res: Response): Promise<void>;
23
+ callback(req: Request, res: Response): Promise<void>;
24
+ webhook(req: Request, res: Response): Promise<void>;
25
+ createTxn(req: Request, res: Response): Promise<void>;
26
+ createTxnToken(req: Request, res: Response): Promise<void>;
27
+ getTransactions(req: Request, res: Response): Promise<void>;
28
+ status(req: Request, res: Response): Promise<void>;
29
+ private getStatusFromPaytm;
30
+ }
@@ -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,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,78 @@
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
+ returnUrl: string;
31
+ webhookUrl: string;
32
+ }
33
+ export interface NPCallbacks {
34
+ onStart: (orderId: string, paymentData?: NPTransaction) => void;
35
+ onFinish: (orderId: string, paymentData?: NPTransaction) => void;
36
+ }
37
+ export type NPConfig = {
38
+ KEY: string;
39
+ SECRET: string;
40
+ MID?: string;
41
+ WEBSITE?: string;
42
+ CHANNEL_ID?: string;
43
+ INDUSTRY_TYPE_ID?: string;
44
+ CALLBACK_URL?: string;
45
+ paytm_url?: string;
46
+ mode?: string;
47
+ razor_url?: string;
48
+ open_money_url?: string;
49
+ payu_url?: string;
50
+ templateDir?: string;
51
+ view_path: string;
52
+ theme_color?: string;
53
+ brand?: string;
54
+ logo?: string;
55
+ host_url?: string;
56
+ path_prefix: string;
57
+ id_length?: number;
58
+ };
59
+ export type NPTableNames = {
60
+ USER: string;
61
+ TRANSACTION: string;
62
+ };
63
+ export type NPParam = {
64
+ ORDER_ID?: string;
65
+ CUST_ID?: string;
66
+ TXN_AMOUNT: string;
67
+ CALLBACK_URL?: string;
68
+ EMAIL?: string;
69
+ MOBILE_NO?: string;
70
+ NAME?: string;
71
+ PRODUCT_NAME?: string;
72
+ RETURN_URL?: string;
73
+ MID?: string;
74
+ WEBSITE?: string;
75
+ CHANNEL_ID?: string;
76
+ INDUSTRY_TYPE_ID?: string;
77
+ CURRENCY?: string;
78
+ };
@@ -0,0 +1,2 @@
1
+ declare const paymentRoute: (app: any, express: any, callbacks?: any) => any;
2
+ export default paymentRoute;
@@ -0,0 +1,2 @@
1
+ import { NPConfig } from "../models";
2
+ export declare function buildConfig(userConfig?: Record<string, any>): NPConfig;
@@ -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,10 @@
1
+ import { Application, RequestHandler, Router } from 'express';
2
+ import { NPCallbacks, NPConfig, NPTableNames } from './app/models';
3
+ import { MultiDbORM } from 'multi-db-orm';
4
+ export * from './app/models';
5
+ export declare function attachViewEngine(app: Application, userConfig?: Partial<NPConfig>): void;
6
+ export declare function createPaymentMiddleware(app: Application, userConfig: NPConfig, db: MultiDbORM, callbacks?: NPCallbacks, authenticationMiddleware?: RequestHandler, tableNames?: NPTableNames): Router;
7
+ declare const _default: {
8
+ createPaymentMiddleware: typeof createPaymentMiddleware;
9
+ };
10
+ export default _default;
package/dist/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.attachBodyParser = attachBodyParser;
20
+ exports.attachViewEngine = attachViewEngine;
21
21
  exports.createPaymentMiddleware = createPaymentMiddleware;
22
22
  const express_1 = __importDefault(require("express"));
23
23
  const path_1 = __importDefault(require("path"));
@@ -26,7 +26,7 @@ const express_handlebars_1 = __importDefault(require("express-handlebars"));
26
26
  const payment_controller_1 = require("./app/controllers/payment.controller");
27
27
  const buildConfig_1 = require("./app/utils/buildConfig");
28
28
  __exportStar(require("./app/models"), exports);
29
- function attachBodyParser(app, userConfig = {}) {
29
+ function attachViewEngine(app, userConfig = {}) {
30
30
  const config = (0, buildConfig_1.buildConfig)(userConfig);
31
31
  const saveRawBody = (req, res, buf) => {
32
32
  req.rawBody = buf && buf.toString();
@@ -51,9 +51,9 @@ function attachBodyParser(app, userConfig = {}) {
51
51
  }
52
52
  function createPaymentMiddleware(app, userConfig, db, callbacks, authenticationMiddleware, tableNames) {
53
53
  //check attachBodyParser
54
- if (!app.get('attachBodyParser')) {
55
- console.error('!!! Warning from node-paytmpg !!!: Body parser not attached by calling `attachBodyParser(app, config)`. Attaching default body parser. Please attach your own body parser if you have custom requirements. but make sure `rawBody` is attached to the request object for webhook verification.');
56
- attachBodyParser(app, userConfig);
54
+ if (!app.get('view engine')) {
55
+ console.warn('[node-paytmpg]: View engine not attached. Attaching default view engine. Either call attachViewEngine() before createPaymentMiddleware() or ensure that your Express app has a view engine attached.');
56
+ attachViewEngine(app, userConfig);
57
57
  }
58
58
  const config = (0, buildConfig_1.buildConfig)(userConfig);
59
59
  const subApp = express_1.default.Router();
package/dist/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.1.3",
3
+ "version": "7.1.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "scripts": {
7
8
  "start": "node example.js",
8
9
  "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "node-paytmpg",
3
- "version": "7.1.3",
3
+ "version": "7.1.6",
4
4
  "description": "Payment Gateway Integration using NodeJS",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "scripts": {
7
8
  "start": "node example.js",
8
9
  "clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",