node-paytmpg 7.4.0 → 7.4.1
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 +22 -8
- package/dist/app/controllers/payment.controller.js +5 -11
- package/dist/package.json +1 -1
- package/package.json +1 -1
package/README.MD
CHANGED
|
@@ -13,7 +13,10 @@ npm install node-paytmpg multi-db-orm
|
|
|
13
13
|
```js
|
|
14
14
|
const express = require("express");
|
|
15
15
|
const { FireStoreDB } = require("multi-db-orm");
|
|
16
|
-
const {
|
|
16
|
+
const {
|
|
17
|
+
attachRawBodyAndEngine,
|
|
18
|
+
createPaymentMiddleware,
|
|
19
|
+
} = require("node-paytmpg");
|
|
17
20
|
|
|
18
21
|
const app = express();
|
|
19
22
|
const db = new FireStoreDB(require("./creds.json"));
|
|
@@ -37,7 +40,10 @@ const config = {
|
|
|
37
40
|
INDUSTRY_TYPE_ID: "Retail",
|
|
38
41
|
};
|
|
39
42
|
|
|
40
|
-
|
|
43
|
+
// Make sure to call this before adding any other body parsers
|
|
44
|
+
// this preserves the original body in req.rawBody so it can be used to verify
|
|
45
|
+
// signatures in webhooks especially for razorpay
|
|
46
|
+
attachRawBodyAndEngine(app, config);
|
|
41
47
|
|
|
42
48
|
const paymentRouter = createPaymentMiddleware(app, config, db);
|
|
43
49
|
app.use("/" + config.path_prefix, paymentRouter);
|
|
@@ -47,17 +53,25 @@ app.listen(5544, () => {
|
|
|
47
53
|
});
|
|
48
54
|
```
|
|
49
55
|
|
|
50
|
-
## `
|
|
56
|
+
## `attachRawBodyAndEngine(app, config)`
|
|
51
57
|
|
|
52
|
-
|
|
58
|
+
> ⚠️ Caution — avoid calling this helper directly in production apps.
|
|
59
|
+
|
|
60
|
+
Use this only if your application does **not** already configure body parsing or a view engine. In most cases you should **not** call this helper; prefer one of the alternatives below.
|
|
53
61
|
|
|
54
62
|
What it does:
|
|
55
63
|
|
|
56
|
-
- Adds JSON and URL-encoded body parsing.
|
|
57
|
-
-
|
|
58
|
-
- Sets
|
|
64
|
+
- Adds JSON and URL-encoded body parsing and captures `req.rawBody` (required for some gateway webhook verifications).
|
|
65
|
+
- Configures Handlebars (`hbs`) view engine and a default layout used by the payment pages.
|
|
66
|
+
- Sets `app.set('attachRawBodyAndEngine', true)` so the middleware knows the setup is present.
|
|
67
|
+
|
|
68
|
+
When _not_ to use it:
|
|
69
|
+
|
|
70
|
+
- Do **not** call this if your app already defines body-parsing middleware or a view engine — it will override or duplicate global settings and can cause conflicts.
|
|
71
|
+
- Instead, either let `createPaymentMiddleware` auto-attach the required parsers/engine (it logs a warning if missing) or manually ensure `req.rawBody` and a compatible view engine are configured.
|
|
72
|
+
- If you must call it, call it once at app startup and do not call it from sub-apps or multiple times.
|
|
59
73
|
|
|
60
|
-
If you skip this call, `createPaymentMiddleware` auto-attaches a default parser and logs a warning. For custom body-parser setups, make sure raw request body is still available as `req.rawBody`.
|
|
74
|
+
If you skip this call, `createPaymentMiddleware` auto-attaches a default parser/engine and logs a warning. For custom body-parser setups, make sure raw request body is still available as `req.rawBody`.
|
|
61
75
|
|
|
62
76
|
## How to invoke `createPaymentMiddleware`
|
|
63
77
|
|
|
@@ -829,11 +829,6 @@ class PaymentController {
|
|
|
829
829
|
// parameters can be from query or body
|
|
830
830
|
// MID, MOBILE_NO, PRODUCT_NAME, EMAIL, NAME, limit, offset
|
|
831
831
|
const params = { ...(req.query || {}), ...(req.body || {}) };
|
|
832
|
-
// Basic authz guard if caller supplies MID and it mismatches current config
|
|
833
|
-
if (params.MID && this.config.MID && params.MID !== this.config.MID) {
|
|
834
|
-
res.status(403).send({ message: 'MID mismatch' });
|
|
835
|
-
return;
|
|
836
|
-
}
|
|
837
832
|
// Build query map from incoming fields to db columns
|
|
838
833
|
const query = {};
|
|
839
834
|
const fieldMap = {
|
|
@@ -861,17 +856,16 @@ class PaymentController {
|
|
|
861
856
|
const limit = Math.min(parseInt(params.limit, 10) || 20, 100);
|
|
862
857
|
const offset = Math.max(parseInt(params.offset, 10) || 0, 0);
|
|
863
858
|
try {
|
|
864
|
-
let transactions = [];
|
|
865
859
|
const all = await this.db.get(this.tableNames.TRANSACTION, query, {
|
|
866
|
-
sort: [{ field: 'time', order: 'desc' }]
|
|
860
|
+
sort: [{ field: 'time', order: 'desc' }],
|
|
861
|
+
limit: limit,
|
|
862
|
+
offset: offset
|
|
867
863
|
});
|
|
868
|
-
const safeAll = Array.isArray(all) ? all : [];
|
|
869
|
-
transactions = safeAll.slice(offset, offset + limit);
|
|
870
864
|
res.send({
|
|
871
865
|
limit,
|
|
872
866
|
offset,
|
|
873
|
-
count:
|
|
874
|
-
transactions
|
|
867
|
+
count: all.length,
|
|
868
|
+
transactions: all
|
|
875
869
|
});
|
|
876
870
|
}
|
|
877
871
|
catch (err) {
|
package/dist/package.json
CHANGED