elpaypg 0.0.0-stage → 2.0.0
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/.env.example +8 -0
- package/README.md +176 -2
- package/package.json +21 -4
- package/public/elpay-checkout.js +769 -0
- package/public/elpay-sms-gateway.apk +0 -0
- package/public/elpay-sms-gateway.apk.sha256 +1 -0
- package/public/elpay.js +785 -0
- package/public/fonts/dm-sans.woff2 +0 -0
- package/public/fonts/sora.woff2 +0 -0
- package/public/views/checkout.html +2839 -0
- package/public/views/partials/auth.html +110 -0
- package/public/views/partials/footer.html +54 -0
- package/public/views/partials/header.html +101 -0
- package/public/views/partials/modals.html +179 -0
- package/public/views/partials/payment-methods.html +526 -0
- package/public/views/partials/sidebar.html +75 -0
- package/public/views/partials/splash.html +35 -0
- package/src/__tests__/smoke.test.js +8 -0
- package/src/auth-guard.js +95 -0
- package/src/index.js +137 -0
- package/src/router.js +46 -0
- package/src/routes/admin.routes.js +2421 -0
- package/src/routes/checkout.routes.js +2000 -0
- package/src/routes/customer.routes.js +650 -0
- package/src/routes/device.routes.js +303 -0
- package/src/routes/payments.routes.js +446 -0
- package/src/routes/pollers.routes.js +653 -0
- package/src/services/observer-poller.service.js +369 -0
- package/src/services/tunnel-manager.js +130 -0
- package/src/services/whatsapp-berry.service.js +743 -0
- package/src/vendor/common/__tests__/common.test.js +297 -0
- package/src/vendor/common/__tests__/common.test.ts +160 -0
- package/src/vendor/common/contracts.js +64 -0
- package/src/vendor/common/contracts.ts +188 -0
- package/src/vendor/common/crypto.js +132 -0
- package/src/vendor/common/crypto.ts +112 -0
- package/src/vendor/common/enums.js +91 -0
- package/src/vendor/common/enums.ts +91 -0
- package/src/vendor/common/index.js +12 -0
- package/src/vendor/common/index.ts +8 -0
- package/src/vendor/common/money.js +62 -0
- package/src/vendor/common/money.ts +56 -0
- package/src/vendor/common/observation.js +27 -0
- package/src/vendor/common/observation.ts +52 -0
- package/src/vendor/common/runtime-config.js +246 -0
- package/src/vendor/common/secrets.js +374 -0
- package/src/vendor/common/state-machine.d.ts +1 -0
- package/src/vendor/common/state-machine.js +1 -0
- package/src/vendor/common/state-transitions.js +85 -0
- package/src/vendor/common/tunnel-command.js +59 -0
- package/src/vendor/common/upi-providers.js +389 -0
- package/src/vendor/common/upi-providers.ts +400 -0
- package/src/vendor/common/upi.js +69 -0
- package/src/vendor/common/upi.ts +61 -0
- package/src/vendor/core/__tests__/core.test.js +683 -0
- package/src/vendor/core/__tests__/queue-timing.test.js +237 -0
- package/src/vendor/core/__tests__/webhook-engine.test.js +243 -0
- package/src/vendor/core/attribution-engine.js +855 -0
- package/src/vendor/core/bank-email-parser.js +105 -0
- package/src/vendor/core/bank-sms-parser.js +183 -0
- package/src/vendor/core/device-security.js +506 -0
- package/src/vendor/core/index.js +13 -0
- package/src/vendor/core/normalizer.js +165 -0
- package/src/vendor/core/qr-lib.js +8 -0
- package/src/vendor/core/qr.js +62 -0
- package/src/vendor/core/queue-engine.js +153 -0
- package/src/vendor/core/recovery-engine.js +159 -0
- package/src/vendor/core/state-machine.js +42 -0
- package/src/vendor/core/timing-engine.js +272 -0
- package/src/vendor/core/verification-pipeline.js +1164 -0
- package/src/vendor/core/webhook-engine.js +280 -0
- package/src/vendor/db/__tests__/auth-matrix.test.js +564 -0
- package/src/vendor/db/__tests__/customer-reset.test.js +95 -0
- package/src/vendor/db/__tests__/db.test.js +265 -0
- package/src/vendor/db/__tests__/schema-parity.test.js +137 -0
- package/src/vendor/db/__tests__/sqlite_verify.test.js +15 -0
- package/src/vendor/db/database.js +181 -0
- package/src/vendor/db/index.js +12 -0
- package/src/vendor/db/migrate.js +210 -0
- package/src/vendor/db/repositories/audit-log.repository.js +68 -0
- package/src/vendor/db/repositories/customer-session.repository.js +181 -0
- package/src/vendor/db/repositories/customer.repository.js +636 -0
- package/src/vendor/db/repositories/device.repository.js +285 -0
- package/src/vendor/db/repositories/merchant.repository.js +158 -0
- package/src/vendor/db/repositories/observation.repository.js +124 -0
- package/src/vendor/db/repositories/payment-session.repository.js +618 -0
- package/src/vendor/db/repositories/receiving-account.repository.js +244 -0
- package/src/vendor/db/repositories/support-ticket.repository.js +140 -0
- package/src/vendor/db/schema.sql +266 -0
- package/src/vendor/db/sqlite-schema.sql +270 -0
package/.env.example
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# ELPAY PG environment variables
|
|
2
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/myapp
|
|
3
|
+
BASE_URL=http://localhost:5000
|
|
4
|
+
ELPAY_WEBHOOK_SECRET=change-me-to-a-long-random-string
|
|
5
|
+
ELPAY_ADMIN_TOKEN=change-me-admin-token
|
|
6
|
+
ELPAY_PUBLIC_KEY=pk_test_abc
|
|
7
|
+
ELPAY_BIND_HOST=127.0.0.1
|
|
8
|
+
```
|
package/README.md
CHANGED
|
@@ -1,3 +1,177 @@
|
|
|
1
|
-
#
|
|
1
|
+
# elpay-pg — Simple Guide
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A payment gateway you install into your own backend. No separate servers. No extra ports. Your database stores everything.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Environment setup (.env)
|
|
8
|
+
|
|
9
|
+
Create a `.env` file in your project root:
|
|
10
|
+
|
|
11
|
+
```env
|
|
12
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/myapp
|
|
13
|
+
BASE_URL=http://localhost:5000
|
|
14
|
+
ELPAY_WEBHOOK_SECRET=change-me-to-a-long-random-string
|
|
15
|
+
ELPAY_ADMIN_TOKEN=change-me-admin-token
|
|
16
|
+
ELPAY_PUBLIC_KEY=pk_test_abc
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
A template is included as `.env.example` in the package.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install elpay-pg pg
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 2. Set environment variables
|
|
28
|
+
|
|
29
|
+
Create a `.env` file:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
DATABASE_URL=postgresql://user:password@localhost:5432/myapp
|
|
33
|
+
BASE_URL=http://localhost:5000
|
|
34
|
+
ELPAY_WEBHOOK_SECRET=any-long-random-string
|
|
35
|
+
ELPAY_ADMIN_TOKEN=any-admin-token
|
|
36
|
+
ELPAY_PUBLIC_KEY=pk_test_abc
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## 3. Add to your backend (Express)
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
import express from 'express';
|
|
43
|
+
import { elpay } from 'elpay-pg';
|
|
44
|
+
|
|
45
|
+
const app = express();
|
|
46
|
+
app.use(express.json());
|
|
47
|
+
|
|
48
|
+
const gateway = await elpay({
|
|
49
|
+
databaseUrl: process.env.DATABASE_URL,
|
|
50
|
+
baseUrl: process.env.BASE_URL,
|
|
51
|
+
webhookSecret: process.env.ELPAY_WEBHOOK_SECRET,
|
|
52
|
+
adminToken: process.env.ELPAY_ADMIN_TOKEN,
|
|
53
|
+
publicKey: process.env.ELPAY_PUBLIC_KEY,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Mount everything under /elpay
|
|
57
|
+
app.use('/elpay', gateway.router);
|
|
58
|
+
|
|
59
|
+
// When a payment succeeds, update your orders
|
|
60
|
+
gateway.on('payment:success', async ({ orderId, utr }) => {
|
|
61
|
+
await db.query('UPDATE orders SET status=$1, utr=$2 WHERE id=$3', ['paid', utr, orderId]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
app.listen(5000);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## 4. Add to your frontend (React)
|
|
68
|
+
|
|
69
|
+
```jsx
|
|
70
|
+
import { useEffect } from 'react';
|
|
71
|
+
|
|
72
|
+
const SDK_URL = 'http://localhost:5000/elpay/elpay.js';
|
|
73
|
+
|
|
74
|
+
export default function BuyButton() {
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
if (document.getElementById('elpay-sdk')) return;
|
|
77
|
+
const s = document.createElement('script');
|
|
78
|
+
s.id = 'elpay-sdk';
|
|
79
|
+
s.src = SDK_URL;
|
|
80
|
+
s.setAttribute('data-elpay-key', 'pk_test_abc');
|
|
81
|
+
document.body.appendChild(s);
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
const buy = () => {
|
|
85
|
+
window.Elpay?.pay({
|
|
86
|
+
order_id: 'ORDER-1',
|
|
87
|
+
amount: 499,
|
|
88
|
+
currency: 'INR',
|
|
89
|
+
customer: { name: 'Mohit', email: 'mohit@example.com' },
|
|
90
|
+
handler: (res) => console.log('Paid', res),
|
|
91
|
+
onClose: () => console.log('Closed')
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return <button onClick={buy}>Buy Now</button>;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## 5. Run
|
|
100
|
+
|
|
101
|
+
- Start Postgres
|
|
102
|
+
- Start your backend on port 5000
|
|
103
|
+
- Start your frontend (Vite/React)
|
|
104
|
+
- Click "Buy Now" → modal opens → pay with UPI
|
|
105
|
+
|
|
106
|
+
## 6. Admin dashboard
|
|
107
|
+
|
|
108
|
+
Open `http://localhost:5000/elpay/admin` and log in with `ELPAY_ADMIN_TOKEN`.
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## If auto-migration fails
|
|
113
|
+
|
|
114
|
+
The module runs migrations automatically on first boot. If that fails (permissions, network, etc.), run this SQL manually in your Postgres database:
|
|
115
|
+
|
|
116
|
+
```sql
|
|
117
|
+
-- Minimal tables required by elpay-pg
|
|
118
|
+
CREATE TABLE IF NOT EXISTS merchants (
|
|
119
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
120
|
+
name TEXT NOT NULL,
|
|
121
|
+
webhook_secret TEXT,
|
|
122
|
+
created_at TIMESTAMPTZ DEFAULT now()
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
CREATE TABLE IF NOT EXISTS payment_sessions (
|
|
126
|
+
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
127
|
+
merchant_id UUID REFERENCES merchants(id),
|
|
128
|
+
order_id TEXT NOT NULL,
|
|
129
|
+
amount_paise BIGINT NOT NULL,
|
|
130
|
+
currency TEXT DEFAULT 'INR',
|
|
131
|
+
status TEXT NOT NULL,
|
|
132
|
+
method TEXT DEFAULT 'UPI',
|
|
133
|
+
utr TEXT,
|
|
134
|
+
created_at TIMESTAMPTZ DEFAULT now(),
|
|
135
|
+
expires_at TIMESTAMPTZ,
|
|
136
|
+
completed_at TIMESTAMPTZ
|
|
137
|
+
);
|
|
138
|
+
|
|
139
|
+
CREATE TABLE IF NOT EXISTS elpay_migrations (
|
|
140
|
+
id SERIAL PRIMARY KEY,
|
|
141
|
+
name TEXT NOT NULL,
|
|
142
|
+
applied_at TIMESTAMPTZ DEFAULT now()
|
|
143
|
+
);
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Then restart your backend — it will detect the tables and skip re-creating them.
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## Theming
|
|
151
|
+
|
|
152
|
+
Pass a `theme` object:
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
const gateway = await elpay({
|
|
156
|
+
// ...
|
|
157
|
+
theme: {
|
|
158
|
+
primaryColor: '#ff5722',
|
|
159
|
+
borderRadius: '12px',
|
|
160
|
+
fontFamily: 'Inter, sans-serif'
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Or override CSS variables in your own stylesheet:
|
|
166
|
+
|
|
167
|
+
```css
|
|
168
|
+
:root {
|
|
169
|
+
--elpay-primary: #ff5722;
|
|
170
|
+
--elpay-radius: 12px;
|
|
171
|
+
--elpay-font: Inter, sans-serif;
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "elpaypg",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "ELPAY PG - single-backend payment gateway module",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"src/",
|
|
12
|
+
"public/",
|
|
13
|
+
"README.md",
|
|
14
|
+
".env.example"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"express": "^4.19.0",
|
|
18
|
+
"qrcode": "^1.5.4"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22.5.0"
|
|
22
|
+
}
|
|
23
|
+
}
|