node-paytmpg 6.4.6 → 7.0.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 +132 -182
- package/app/views/layouts/index.hbs +7 -7
- package/app/views/result.hbs +1 -1
- package/dist/app/controllers/adapters/open_money.js +400 -0
- package/dist/app/controllers/adapters/paytm.js +34 -0
- package/{app → dist/app}/controllers/adapters/payu.js +208 -239
- package/dist/app/controllers/checksum/PaytmChecksum.js +118 -0
- package/dist/app/controllers/checksum/checksum.js +158 -0
- package/dist/app/controllers/checksum/crypt.js +117 -0
- package/dist/app/controllers/checksum/server.js +130 -0
- package/dist/app/controllers/payment.controller.js +985 -0
- package/dist/app/controllers/static/loadingsvg.js +54 -0
- package/dist/app/controllers/user.controller.js +53 -0
- package/dist/app/models/index.js +2 -0
- package/dist/app/routes/payment_route.js +46 -0
- package/dist/app/utils/buildConfig.js +210 -0
- package/dist/app/utils/utils.js +20 -0
- package/dist/app/views/home.hbs +22 -0
- package/dist/app/views/init.hbs +98 -0
- package/dist/app/views/layouts/index.hbs +53 -0
- package/dist/app/views/result.hbs +33 -0
- package/dist/index.js +119 -0
- package/dist/package.json +67 -0
- package/dist/public/css/style.css +455 -0
- package/dist/public/js/index.js +283 -0
- package/dist/public/layer_checkout.js +38 -0
- package/dist/public/pay.png +0 -0
- package/dist/public/start.png +0 -0
- package/dist/public/start2.png +0 -0
- package/dist/public/stat.png +0 -0
- package/dist/public/test.html +24 -0
- package/dist/public/test.html~ +24 -0
- package/package.json +29 -6
- package/public/test.html~ +24 -0
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.github/workflows/nodejs.yml +0 -24
- package/.github/workflows/npm-publish.yml +0 -23
- package/Dockerfile +0 -9
- package/app/controllers/adapters/open_money.js +0 -515
- package/app/controllers/checksum/PaytmChecksum.js +0 -94
- package/app/controllers/checksum/checksum.js +0 -154
- package/app/controllers/checksum/crypt.js +0 -98
- package/app/controllers/checksum/server.js +0 -132
- package/app/controllers/np_user.controller.js +0 -89
- package/app/controllers/payment_controller.js +0 -1204
- package/app/models/np_multidbplugin.js +0 -111
- package/app/models/np_transaction.model.js +0 -16
- package/app/models/np_user.model.js +0 -12
- package/app/routes/payment_route.js +0 -73
- package/app.yaml +0 -18
- package/example.js +0 -34
- package/index.js +0 -86
- package/lib/config/buildConfig.js +0 -113
- package/lib/config/defaults.js +0 -37
- package/lib/config/validator.js +0 -103
- package/lib/services/database.service.js +0 -153
- package/lib/utils/id-generator.js +0 -30
- package/lib/utils/sanitizer.js +0 -25
package/README.MD
CHANGED
|
@@ -1,245 +1,195 @@
|
|
|
1
|
-
##
|
|
1
|
+
## node-paytmpg
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://github.com/shiveshnavin/node_paytm/actions/workflows/nodejs.yml)
|
|
3
|
+
Express middleware for integrating Paytm / Razorpay / PayU / Open Money payments with built-in checkout pages and APIs.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
- Paytm
|
|
8
|
-
- RazorPay
|
|
9
|
-
- Open Money
|
|
10
|
-
|
|
11
|
-
Does all the hardwork for you while integrating payments in any express app. Comes with inbuilt UI and REST APIs for lightning fast development and prototyping .
|
|
5
|
+
## Install
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
Use any Card Details or Net Banking
|
|
18
|
-
username : test
|
|
19
|
-
password : test
|
|
20
|
-
|
|
21
|
-
Example App Sourcecode : https://github.com/shiveshnavin/payment-gateway-example
|
|
22
|
-
|
|
23
|
-
### Requirments
|
|
24
|
-
|
|
25
|
-
1. MongoDB / Firestore / SQlite
|
|
26
|
-
2. Your Merchant Credentials
|
|
27
|
-
3. Express . This only works with NodeJS express server
|
|
7
|
+
```bash
|
|
8
|
+
npm install node-paytmpg multi-db-orm
|
|
9
|
+
```
|
|
28
10
|
|
|
29
|
-
|
|
30
|
-
https://developer.paytm.com/docs
|
|
11
|
+
## Quick start (current API)
|
|
31
12
|
|
|
13
|
+
```js
|
|
14
|
+
const express = require("express");
|
|
15
|
+
const { FireStoreDB } = require("multi-db-orm");
|
|
16
|
+
const { attachBodyParser, createPaymentMiddleware } = require("node-paytmpg");
|
|
32
17
|
|
|
18
|
+
const app = express();
|
|
19
|
+
const db = new FireStoreDB(require("./creds.json"));
|
|
33
20
|
|
|
34
|
-
|
|
21
|
+
const config = {
|
|
22
|
+
host_url: "http://127.0.0.1:5544",
|
|
23
|
+
path_prefix: "pay",
|
|
24
|
+
homepage: "/",
|
|
35
25
|
|
|
36
|
-
|
|
26
|
+
// enable one gateway
|
|
27
|
+
payu_url: "https://test.payu.in/_payment",
|
|
28
|
+
// paytm_url: 'https://securegw-stage.paytm.in',
|
|
29
|
+
// razor_url: 'https://api.razorpay.com/',
|
|
30
|
+
// open_money_url: 'https://sandbox-icp-api.bankopen.co/api',
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
MID: "YOUR_MID",
|
|
33
|
+
WEBSITE: "WEBSTAGING",
|
|
34
|
+
KEY: "YOUR_KEY",
|
|
35
|
+
SECRET: "YOUR_SECRET",
|
|
36
|
+
CHANNEL_ID: "WAP",
|
|
37
|
+
INDUSTRY_TYPE_ID: "Retail",
|
|
38
|
+
};
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
attachBodyParser(app, config);
|
|
42
41
|
|
|
43
|
-
|
|
42
|
+
const paymentRouter = createPaymentMiddleware(app, config, db);
|
|
43
|
+
app.use("/" + config.path_prefix, paymentRouter);
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
app.listen(5544, () => {
|
|
46
|
+
console.log("Server started on 5544");
|
|
47
|
+
});
|
|
47
48
|
```
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
## `attachBodyParser(app, config)`
|
|
50
51
|
|
|
52
|
+
Use this before creating the payment middleware.
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
```code
|
|
54
|
-
host_url : Host URL of your server . This will be used to redirect user after payment
|
|
55
|
-
view_path : Ignore and dont change unless you know what you are doing . This is the useful in case you want to modify payment init page UI from node_paytm_pg library
|
|
56
|
-
paytm_url : For Test "https://securegw-stage.paytm.in" and for Production "https://securegw.paytm.in"
|
|
57
|
-
MID : Your Paytm Merchant ID
|
|
58
|
-
Website : "WEBSTAGING" for Test and for Production , the website you entered while activation
|
|
59
|
-
KEY : Your Unique Key from Paytm used for hashing
|
|
60
|
-
CHANNEL_ID : Know More at Paytm Docs
|
|
61
|
-
INDUSTRY_TYPE_ID : Know More at Paytm Docs
|
|
62
|
-
homepage : Homepage of your website where user can go after payment confirmation page
|
|
63
|
-
path_prefix : All node_paytm_pg apis/pages will be available relative to this path prefix
|
|
64
|
-
db_url : Your MongoDB url in case you want to use legacy mongodb connection . You can use multidborm to support MongoDB/Firestore/Sqlite
|
|
65
|
-
id_length: Length of Order ID and User ID
|
|
54
|
+
What it does:
|
|
66
55
|
|
|
67
|
-
|
|
56
|
+
- Adds JSON and URL-encoded body parsing.
|
|
57
|
+
- Captures `req.rawBody` for webhook signature verification (important for Razorpay webhooks).
|
|
58
|
+
- Sets up handlebars view engine expected by payment pages.
|
|
68
59
|
|
|
69
|
-
|
|
70
|
-
In case you want to use razorpay , Use the below configuration
|
|
71
|
-
```
|
|
72
|
-
host_url : Host URL of your server . This will be used to redirect user after payment
|
|
73
|
-
view_path : Ignore and dont change unless you know what you are doing . This is the useful in case you want to modify payment init page UI from node_paytm_pg library
|
|
74
|
-
razor_url : https://api.razorpay.com/
|
|
75
|
-
MID : Your Paytm Merchant ID
|
|
76
|
-
KEY : Your generated API Key
|
|
77
|
-
SECRET : Your API Key secret
|
|
78
|
-
homepage : Homepage of your website where user can go after payment confirmation page
|
|
79
|
-
path_prefix : All node_paytm_pg apis/pages will be available relative to this path prefix
|
|
80
|
-
db_url : Your MongoDB url in case you want to use legacy mongodb connection . You can use multidborm to support MongoDB/Firestore/Sqlite
|
|
81
|
-
id_length: Length of Order ID and User ID
|
|
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`.
|
|
82
61
|
|
|
83
|
-
|
|
62
|
+
## How to invoke `createPaymentMiddleware`
|
|
84
63
|
|
|
85
|
-
|
|
86
|
-
In case you want to use Open Money https://app.open.money/settings/developer-api/api . Use the below configuration
|
|
87
|
-
```
|
|
88
|
-
host_url : Host URL of your server . This will be used to redirect user after payment
|
|
89
|
-
view_path : Ignore and dont change unless you know what you are doing . This is the useful in case you want to modify payment init page UI from node_paytm_pg library
|
|
90
|
-
open_money_url : SANDBOX https://sandbox-icp-api.bankopen.co/api OR LIVE https://icp-api.bankopen.co/api
|
|
91
|
-
KEY : Your generated API Key
|
|
92
|
-
SECRET : Your API secret
|
|
93
|
-
homepage : Homepage of your website where user can go after payment confirmation page
|
|
94
|
-
path_prefix : All node_paytm_pg apis/pages will be available relative to this path prefix
|
|
95
|
-
db_url : Your MongoDB url in case you want to use legacy mongodb connection . You can use multidborm to support MongoDB/Firestore/Sqlite
|
|
96
|
-
id_length: Length of Order ID and User ID (Optional)
|
|
64
|
+
Signature:
|
|
97
65
|
|
|
66
|
+
```ts
|
|
67
|
+
createPaymentMiddleware(
|
|
68
|
+
app,
|
|
69
|
+
userConfig,
|
|
70
|
+
db,
|
|
71
|
+
callbacks?,
|
|
72
|
+
authenticationMiddleware?,
|
|
73
|
+
tableNames?
|
|
74
|
+
)
|
|
98
75
|
```
|
|
99
76
|
|
|
77
|
+
Required params:
|
|
100
78
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
79
|
+
- `app`: your Express app instance.
|
|
80
|
+
- `userConfig`: payment config.
|
|
81
|
+
- `db`: `multi-db-orm` database instance.
|
|
104
82
|
|
|
105
|
-
|
|
106
|
-
* Uncomment in case you want to use multidborm to support
|
|
107
|
-
* MongoDB / Firestore / SQlite
|
|
108
|
-
* https://www.npmjs.com/package/multi-db-orm
|
|
109
|
-
* Refer to example.js
|
|
83
|
+
Optional params:
|
|
110
84
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
85
|
+
- `callbacks`: `{ onStart(orderId, txn), onFinish(orderId, txn) }`.
|
|
86
|
+
- `authenticationMiddleware`: middleware to protect all payment routes.
|
|
87
|
+
- `tableNames`: override default table/collection names.
|
|
114
88
|
|
|
115
|
-
|
|
89
|
+
Mounting:
|
|
116
90
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"MID":"XXXXXXXXXXX",
|
|
121
|
-
"WEBSITE":"WEBSTAGING",
|
|
122
|
-
"KEY":"XXXXXXXXXXX",
|
|
123
|
-
"CHANNEL_ID":"WEB",
|
|
124
|
-
"INDUSTRY_TYPE_ID":"Retail",
|
|
125
|
-
"homepage":"/_pay/home",
|
|
126
|
-
"path_prefix":"_pay",
|
|
127
|
-
"db_url":"mongodb://user:password123@db.host.com:5551/dbname_123", // Remove this property in case you want to use multidborm
|
|
128
|
-
"id_length":10,
|
|
129
|
-
"logo":"/favicon.ico",
|
|
130
|
-
"theme_color":"#3399cc",
|
|
91
|
+
- Router paths are relative (`/init`, `/callback`, `/api/createTxn`, etc.).
|
|
92
|
+
- Mount with `app.use('/' + config.path_prefix, router)`.
|
|
93
|
+
- Keep mount path aligned with `config.path_prefix` so generated `payurl` is correct.
|
|
131
94
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"razor_url":"https://api.razorpay.com/", // Only For RazorPay
|
|
135
|
-
"SECRET":"XXXXXXXXXXX", //Only For RazorPay , Your razorpay api key secret
|
|
95
|
+
## Request fields: `RETURN_URL` and `WEBHOOK_URL`
|
|
136
96
|
|
|
137
|
-
|
|
97
|
+
`RETURN_URL` and `WEBHOOK_URL` are optional fields accepted in payment-init/create APIs and stored per transaction.
|
|
138
98
|
|
|
139
|
-
|
|
99
|
+
### `RETURN_URL`
|
|
140
100
|
|
|
141
|
-
|
|
101
|
+
If provided:
|
|
142
102
|
|
|
143
|
-
|
|
144
|
-
|
|
103
|
+
- User is redirected to this URL after payment update instead of only rendering library result page.
|
|
104
|
+
- Query params are appended by the middleware:
|
|
105
|
+
- `status` (for example `TXN_SUCCESS`, `TXN_FAILURE`, `FAILED`)
|
|
106
|
+
- `ORDERID`
|
|
107
|
+
- `TXNID` (when available)
|
|
108
|
+
- `message` in some failure cases
|
|
145
109
|
|
|
146
|
-
|
|
147
|
-
```
|
|
148
|
-
simply open page /_pay/init in browser
|
|
149
|
-
```
|
|
150
|
-
#### Method 2 : Post these params to /_pay/init using browser form
|
|
151
|
-
```
|
|
152
|
-
NAME
|
|
153
|
-
EMAIL
|
|
154
|
-
MOBILE_NO
|
|
155
|
-
PRODUCT_NAME
|
|
156
|
-
TXN_AMOUNT
|
|
157
|
-
```
|
|
110
|
+
Examples:
|
|
158
111
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
Create an Order by posting to URL /_pay/api/createTxn
|
|
112
|
+
- `https://your-app.com/payment/return?status=TXN_SUCCESS&ORDERID=...&TXNID=...`
|
|
113
|
+
- If URL already has query string, middleware appends with `&`.
|
|
162
114
|
|
|
163
|
-
|
|
164
|
-
EMAIL
|
|
165
|
-
MOBILE_NO
|
|
166
|
-
PRODUCT_NAME
|
|
167
|
-
TXN_AMOUNT
|
|
115
|
+
### `WEBHOOK_URL`
|
|
168
116
|
|
|
169
|
-
|
|
170
|
-
Now Post to /_pay/init using browser form
|
|
117
|
+
If provided:
|
|
171
118
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
MOBILE_NO
|
|
175
|
-
ORDER_ID
|
|
119
|
+
- Middleware posts transaction result payload to this URL on status update.
|
|
120
|
+
- Also used for some error states (for example, transaction not found).
|
|
176
121
|
|
|
177
|
-
|
|
178
|
-
Simply open `payurl` in your browser
|
|
122
|
+
Typical payload includes transaction/order fields (`orderId`, `txnId`, `status`, etc.) depending on update stage.
|
|
179
123
|
|
|
180
|
-
|
|
181
|
-
APIS
|
|
182
|
-
```
|
|
183
|
-
For Checking Status
|
|
124
|
+
## Create transaction API
|
|
184
125
|
|
|
185
|
-
|
|
186
|
-
path : /_pay/api/status
|
|
187
|
-
Params:
|
|
188
|
-
ORDER_ID
|
|
126
|
+
Endpoint:
|
|
189
127
|
|
|
128
|
+
```http
|
|
129
|
+
POST /{path_prefix}/api/createTxn
|
|
190
130
|
```
|
|
191
131
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
You can use callbacks to sync node-paytmpg transactions with you own database using .
|
|
195
|
-
|
|
196
|
-
```
|
|
197
|
-
var PayTMPG=require('node-paytmpg')(app,express,{
|
|
132
|
+
Required body fields:
|
|
198
133
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
{
|
|
205
|
-
console.log("Payment Has finished \n",orderid,data)
|
|
134
|
+
- `NAME`
|
|
135
|
+
- `EMAIL`
|
|
136
|
+
- `MOBILE_NO`
|
|
137
|
+
- `TXN_AMOUNT`
|
|
138
|
+
- `PRODUCT_NAME`
|
|
206
139
|
|
|
207
|
-
|
|
140
|
+
Optional body fields:
|
|
208
141
|
|
|
209
|
-
|
|
142
|
+
- `RETURN_URL`
|
|
143
|
+
- `WEBHOOK_URL`
|
|
144
|
+
- `EXTRA`
|
|
210
145
|
|
|
211
|
-
|
|
212
|
-
var User=PayTMPG.User;
|
|
146
|
+
Response includes generated transaction info and `payurl`:
|
|
213
147
|
|
|
214
|
-
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"orderId": "...",
|
|
151
|
+
"status": "INITIATED",
|
|
152
|
+
"payurl": "http://host/{path_prefix}/init?to=..."
|
|
153
|
+
}
|
|
154
|
+
```
|
|
215
155
|
|
|
216
|
-
|
|
156
|
+
## Core routes
|
|
217
157
|
|
|
218
|
-
|
|
158
|
+
All routes below are mounted under `/{path_prefix}`:
|
|
219
159
|
|
|
160
|
+
- `GET|POST /init`
|
|
161
|
+
- `GET|POST /callback`
|
|
162
|
+
- `GET|POST /api/webhook`
|
|
163
|
+
- `GET|POST /api/status`
|
|
164
|
+
- `GET|POST /api/transactions`
|
|
165
|
+
- `GET|POST /api/createTxn`
|
|
166
|
+
- `GET|POST /api/createTxn/token`
|
|
220
167
|
|
|
221
|
-
|
|
168
|
+
## Config summary
|
|
222
169
|
|
|
223
|
-
|
|
170
|
+
Common:
|
|
224
171
|
|
|
225
|
-
|
|
172
|
+
- `host_url`
|
|
173
|
+
- `path_prefix`
|
|
174
|
+
- `KEY`, `SECRET`
|
|
226
175
|
|
|
227
|
-
|
|
228
|
-
Make sure to use the same secret in your webhook as the merchant secret.
|
|
229
|
-
https://razorpay.com/docs/webhooks/
|
|
176
|
+
Gateway-specific:
|
|
230
177
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
178
|
+
- Paytm: `paytm_url`, `MID`, `WEBSITE`, `CHANNEL_ID`, `INDUSTRY_TYPE_ID`
|
|
179
|
+
- Razorpay: `razor_url`, `KEY`, `SECRET`
|
|
180
|
+
- PayU: `payu_url`, `KEY`, `SECRET`
|
|
181
|
+
- Open Money: `open_money_url`, `KEY`, `SECRET`
|
|
234
182
|
|
|
235
|
-
|
|
236
|
-
Nothing extra needed
|
|
237
|
-
https://docs.bankopen.com/reference/webhook-url
|
|
183
|
+
UI / behavior:
|
|
238
184
|
|
|
185
|
+
- `brand`, `logo`, `theme`, `themeName`, `templateDir`, `id_length`
|
|
239
186
|
|
|
240
|
-
|
|
187
|
+
## Notes
|
|
241
188
|
|
|
242
|
-
|
|
243
|
-
|
|
189
|
+
- Configure at least one gateway URL: `paytm_url`, `razor_url`, `payu_url`, or `open_money_url`.
|
|
190
|
+
- `host_url` + `path_prefix` are used to build checkout links.
|
|
191
|
+
- This package is designed for Express apps.
|
|
244
192
|
|
|
193
|
+
## License
|
|
245
194
|
|
|
195
|
+
MIT
|
|
@@ -13,18 +13,18 @@
|
|
|
13
13
|
<link rel="shortcut icon" href="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2016%2016'%3E%3Crect%20width='16'%20height='16'%20rx='3'%20fill='%23ff5722'/%3E%3C/svg%3E" />
|
|
14
14
|
<style>
|
|
15
15
|
:root {
|
|
16
|
-
--color-primary: {{theme.primary}};
|
|
17
|
-
--color-accent: {{theme.accent}};
|
|
18
|
-
--color-surface: {{theme.surface}};
|
|
19
|
-
--color-text: {{theme.text}};
|
|
20
|
-
--color-success: {{theme.success}};
|
|
21
|
-
--color-danger: {{theme.danger}};
|
|
16
|
+
--color-primary: {{#if theme.primary}}{{theme.primary}}{{else}}#2f8bff{{/if}};
|
|
17
|
+
--color-accent: {{#if theme.accent}}{{theme.accent}}{{else}}#5ce1e6{{/if}};
|
|
18
|
+
--color-surface: {{#if theme.surface}}{{theme.surface}}{{else}}#0f1021{{/if}};
|
|
19
|
+
--color-text: {{#if theme.text}}{{theme.text}}{{else}}#e9ecf2{{/if}};
|
|
20
|
+
--color-success: {{#if theme.success}}{{theme.success}}{{else}}#24cf5f{{/if}};
|
|
21
|
+
--color-danger: {{#if theme.danger}}{{theme.danger}}{{else}}#ff6b6b{{/if}};
|
|
22
22
|
--color-outline: rgba(255,255,255,0.08);
|
|
23
23
|
--radius: 14px;
|
|
24
24
|
}
|
|
25
25
|
</style>
|
|
26
26
|
</head>
|
|
27
|
-
<body class="theme-{{themeName}}">
|
|
27
|
+
<body class="theme-{{#if themeName}}{{themeName}}{{else}}dark{{/if}}">
|
|
28
28
|
<div class="shell">
|
|
29
29
|
<header class="shell__header">
|
|
30
30
|
<div class="brand">
|