node-paytmpg 7.5.12 → 7.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.MD +1 -1
- package/dist/app/controllers/adapters/payu.d.ts +16 -7
- package/dist/app/controllers/adapters/payu.js +31 -3
- package/dist/app/controllers/payment.controller.js +9 -9
- package/dist/app/routes/payment_route.js +1 -1
- package/dist/index.js +1 -1
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -25,9 +25,9 @@ const config = {
|
|
|
25
25
|
host_url: "http://127.0.0.1:5544",
|
|
26
26
|
path_prefix: "pay",
|
|
27
27
|
homepage: "/",
|
|
28
|
-
|
|
29
28
|
// enable one gateway
|
|
30
29
|
payu_url: "https://test.payu.in/_payment",
|
|
30
|
+
// payu_url: "https://secure.payu.in/_payment",
|
|
31
31
|
// paytm_url: 'https://securegw-stage.paytm.in',
|
|
32
32
|
// razor_url: 'https://api.razorpay.com/',
|
|
33
33
|
// open_money_url: 'https://sandbox-icp-api.bankopen.co/api',
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { NPConfig, NPTransaction } from '../../models';
|
|
1
2
|
type Dict = Record<string, any>;
|
|
2
3
|
interface PayUConfig {
|
|
3
4
|
key: string;
|
|
@@ -6,22 +7,24 @@ interface PayUConfig {
|
|
|
6
7
|
paymentUrl: string;
|
|
7
8
|
verifyUrl: string;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
type PayURequestLike = {
|
|
10
11
|
body?: Dict;
|
|
11
12
|
query?: Dict;
|
|
12
13
|
rawBody?: any;
|
|
13
14
|
headers?: Dict;
|
|
14
|
-
}
|
|
15
|
-
|
|
15
|
+
} & any;
|
|
16
|
+
type PayUResponseLike = {
|
|
16
17
|
writeHead: (status: number, headers: Dict) => void;
|
|
17
18
|
write: (chunk: string) => void;
|
|
18
19
|
end: () => void;
|
|
19
|
-
status: (code: number) =>
|
|
20
|
+
status: (code: number) => PayUResponseLike;
|
|
20
21
|
send: (body: any) => void;
|
|
21
|
-
}
|
|
22
|
+
};
|
|
22
23
|
declare class PayU {
|
|
23
24
|
config: PayUConfig;
|
|
24
|
-
|
|
25
|
+
baseConfig: NPConfig;
|
|
26
|
+
constructor(npconfig: NPConfig);
|
|
27
|
+
initParams(npconfig: NPConfig & Dict): void;
|
|
25
28
|
normalizeAmount(amount: any): string;
|
|
26
29
|
buildRequestHash(payload: Dict): string;
|
|
27
30
|
buildResponseHash(data: Dict): string;
|
|
@@ -36,6 +39,12 @@ declare class PayU {
|
|
|
36
39
|
checkBqrTxnStatus(transactionId: string): Promise<Dict>;
|
|
37
40
|
renderProcessingPage(params: Dict, paymentReq: Dict, res: PayUResponseLike, loadingSVG: string): void;
|
|
38
41
|
renderError(params: Dict, error: any, res: PayUResponseLike): void;
|
|
39
|
-
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @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":""}
|
|
45
|
+
* @param res
|
|
46
|
+
* @param updateTransaction
|
|
47
|
+
*/
|
|
48
|
+
processWebhook(req: PayURequestLike, res: PayUResponseLike, updateTransaction: Function, getOrder: (req: Request, orderId?: string) => Promise<NPTransaction | null>): Promise<void>;
|
|
40
49
|
}
|
|
41
50
|
export default PayU;
|
|
@@ -5,8 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const crypto_1 = __importDefault(require("crypto"));
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const buildConfig_1 = require("../../utils/buildConfig");
|
|
8
9
|
class PayU {
|
|
9
10
|
constructor(npconfig) {
|
|
11
|
+
this.initParams(npconfig);
|
|
12
|
+
}
|
|
13
|
+
initParams(npconfig) {
|
|
14
|
+
this.baseConfig = npconfig;
|
|
10
15
|
const baseUrl = (npconfig.payu_url || '').replace(/\/$/, '');
|
|
11
16
|
const isSandbox = baseUrl.indexOf('test.payu.in') > -1;
|
|
12
17
|
const verifyUrl = npconfig.payu_verify_url || (isSandbox
|
|
@@ -196,9 +201,32 @@ class PayU {
|
|
|
196
201
|
res.write(html);
|
|
197
202
|
res.end();
|
|
198
203
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
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
|
+
let updatedConfig = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, originalOrder);
|
|
221
|
+
this.initParams(updatedConfig);
|
|
222
|
+
const payuRest = await this.verifyResult(req);
|
|
223
|
+
let result = !!payuRest.STATUS;
|
|
224
|
+
req.body.STATUS = payuRest.STATUS;
|
|
225
|
+
req.body.TXNID = payuRest.TXNID;
|
|
226
|
+
req.body.ORDERID = payuRest.ORDERID || req.query.order_id;
|
|
227
|
+
req.body.extras = payuRest.data;
|
|
228
|
+
let isCancelled = !!payuRest.cancelled;
|
|
229
|
+
updateTransaction(req, res, true);
|
|
202
230
|
}
|
|
203
231
|
}
|
|
204
232
|
exports.default = PayU;
|
|
@@ -637,8 +637,6 @@ class PaymentController {
|
|
|
637
637
|
return objForUpdate;
|
|
638
638
|
}
|
|
639
639
|
async callback(req, res) {
|
|
640
|
-
const payuInstance = this.getProviderInstance('PayU', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
|
|
641
|
-
const openMoneyInstance = this.getProviderInstance('OpenMoney', (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req));
|
|
642
640
|
console.log("request_data ", req.originalUrl, JSON.stringify(req.body));
|
|
643
641
|
// Normalize common order id and txn id field names (support ORDER_ID, ORDERID, etc.)
|
|
644
642
|
try {
|
|
@@ -659,6 +657,8 @@ class PaymentController {
|
|
|
659
657
|
let isCancelled = false;
|
|
660
658
|
const objForUpdate = await this.getOrder(req);
|
|
661
659
|
const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, objForUpdate);
|
|
660
|
+
const payuInstance = this.getProviderInstance('PayU', (0, buildConfig_1.withClientConfigOverrides)(config, req, objForUpdate));
|
|
661
|
+
const openMoneyInstance = this.getProviderInstance('OpenMoney', (0, buildConfig_1.withClientConfigOverrides)(config, req, objForUpdate));
|
|
662
662
|
if (config.paytm_url) {
|
|
663
663
|
const checksumhash = req.body.CHECKSUMHASH;
|
|
664
664
|
if (checksumhash) {
|
|
@@ -820,11 +820,11 @@ class PaymentController {
|
|
|
820
820
|
return;
|
|
821
821
|
}
|
|
822
822
|
if (serviceUsed === 'PayU') {
|
|
823
|
-
payuInstance.processWebhook(req, res, this.updateTransaction);
|
|
823
|
+
payuInstance.processWebhook(req, res, this.updateTransaction, this.getOrder);
|
|
824
824
|
return;
|
|
825
825
|
}
|
|
826
826
|
if (serviceUsed === 'OpenMoney') {
|
|
827
|
-
openMoneyInstance.processWebhook(req, res, this.updateTransaction);
|
|
827
|
+
openMoneyInstance.processWebhook(req, res, this.updateTransaction, this.getOrder);
|
|
828
828
|
}
|
|
829
829
|
}
|
|
830
830
|
catch (e) {
|
|
@@ -978,11 +978,6 @@ class PaymentController {
|
|
|
978
978
|
}
|
|
979
979
|
}
|
|
980
980
|
async status(req, res) {
|
|
981
|
-
const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req);
|
|
982
|
-
const callbacks = this.callbacks;
|
|
983
|
-
const payuInstance = this.getProviderInstance('PayU', config);
|
|
984
|
-
const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
|
|
985
|
-
const razorPayInstance = this.getProviderInstance('Razorpay', config);
|
|
986
981
|
if (!req.body.ORDERID && req.query.ORDERID) {
|
|
987
982
|
req.body.ORDERID = req.query.ORDERID;
|
|
988
983
|
}
|
|
@@ -1001,6 +996,11 @@ class PaymentController {
|
|
|
1001
996
|
res.send(err);
|
|
1002
997
|
return null;
|
|
1003
998
|
});
|
|
999
|
+
const config = (0, buildConfig_1.withClientConfigOverrides)(this.baseConfig, req, orderData);
|
|
1000
|
+
const callbacks = this.callbacks;
|
|
1001
|
+
const payuInstance = this.getProviderInstance('PayU', config);
|
|
1002
|
+
const openMoneyInstance = this.getProviderInstance('OpenMoney', config);
|
|
1003
|
+
const razorPayInstance = this.getProviderInstance('Razorpay', config);
|
|
1004
1004
|
if (!orderData) {
|
|
1005
1005
|
if (!res.headersSent) {
|
|
1006
1006
|
res.send({ message: "Order Not Found or not initiated yet!", ORDER_ID: req.body.ORDER_ID });
|
|
@@ -37,7 +37,7 @@ const paymentRoute = function (app, express, callbacks) {
|
|
|
37
37
|
router.all('/', pc.init);
|
|
38
38
|
router.all('/init', pc.init);
|
|
39
39
|
router.all('/callback', pc.callback);
|
|
40
|
-
router.all('/api/webhook', pc.webhook);
|
|
40
|
+
router.all(['/api/webhook', '/api/webhook/*'], pc.webhook);
|
|
41
41
|
router.all('/api/status', pc.status);
|
|
42
42
|
router.all('/api/createTxn/token', pc.createTxnToken);
|
|
43
43
|
router.all('/api/createTxn', pc.createTxn);
|
package/dist/index.js
CHANGED
|
@@ -94,7 +94,7 @@ function createPaymentMiddleware(app, userConfig, db, callbacks, authenticationM
|
|
|
94
94
|
subApp.all('/callback', authenticationMiddleware, (req, res) => {
|
|
95
95
|
pc.callback(req, res);
|
|
96
96
|
});
|
|
97
|
-
subApp.all('/api/webhook', authenticationMiddleware, (req, res) => {
|
|
97
|
+
subApp.all(['/api/webhook', '/api/webhook/*'], authenticationMiddleware, (req, res) => {
|
|
98
98
|
pc.webhook(req, res);
|
|
99
99
|
});
|
|
100
100
|
subApp.all('/api/status', authenticationMiddleware, (req, res) => {
|
package/dist/package.json
CHANGED