@dev-crowagent/veripay-upi 1.0.0 → 1.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 +8 -2
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,9 +129,11 @@ Read failures come back as `verified: false` with a message instead of throwing.
|
|
|
129
129
|
Requirements: Python 3.9 or newer. Only dependency is `segno`, which draws the QR images.
|
|
130
130
|
|
|
131
131
|
```bash
|
|
132
|
-
pip install
|
|
132
|
+
pip install veripay-upi
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
Installing from a clone of this repository also works: run `pip install ./sdk` from the repo root.
|
|
136
|
+
|
|
135
137
|
### Demo without a database
|
|
136
138
|
|
|
137
139
|
```python
|
|
@@ -222,6 +224,10 @@ Leave `api_key` out when the deployment has no `API_KEY` environment variable.
|
|
|
222
224
|
|
|
223
225
|
`VeriPayError` is raised for missing parameters. Inbox or network problems come back inside the result, and `VeriPayClient` raises `VeriPayClientError` for non-200 responses.
|
|
224
226
|
|
|
227
|
+
### Telegram bot example
|
|
228
|
+
|
|
229
|
+
`examples/telegram_bot/` is a ready-to-run bot built on this package: `/qr 25.50 Chai` sends a payment QR image and `/verify 25.50` checks Gmail for the matching payment. Its README lists the environment variables it needs.
|
|
230
|
+
|
|
225
231
|
## HTTP API
|
|
226
232
|
|
|
227
233
|
The `api/` folder is a Python serverless API for Vercel, built on the same core as the SDK.
|
|
@@ -404,7 +410,7 @@ Supabase is just Postgres. To use Postgres, MySQL, MongoDB or Redis instead, kee
|
|
|
404
410
|
|
|
405
411
|
1. IMAP search for the reference number, or for the amount as text.
|
|
406
412
|
2. Each message is parsed and subject plus body are checked for credit wording: `received`, `credited`, `added`.
|
|
407
|
-
3. The amount
|
|
413
|
+
3. The amount must match exactly a number tagged with `Rs.`, `INR`, `₹`, an `Amount` / `Amt` label, or written with two decimals. A ₹1 credit never satisfies a ₹3 check, and ₹13 never satisfies ₹1.
|
|
408
414
|
4. UTR and transaction ID are extracted from the body.
|
|
409
415
|
5. With logging on, a reference already stored with status `200` is skipped.
|
|
410
416
|
|
package/dist/index.js
CHANGED
|
@@ -17,8 +17,24 @@ function istStamp(when) {
|
|
|
17
17
|
const moment = when ?? new Date();
|
|
18
18
|
return moment.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' });
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
const CURRENCY_AMOUNT = /(?:rs\.?|inr|₹)\s*([0-9][0-9,]*(?:\.[0-9]{1,2})?)/gi;
|
|
21
|
+
const LABELED_AMOUNT = /(?:amount|amt)\s*[:\-]?\s*(?:rs\.?|inr|₹)?\s*([0-9][0-9,]*(?:\.[0-9]{1,2})?)/gi;
|
|
22
|
+
const PLAIN_AMOUNT = /(?<![\d.])([0-9][0-9,]*\.[0-9]{2})(?![\d])/g;
|
|
23
|
+
function amountsIn(text) {
|
|
24
|
+
const values = [];
|
|
25
|
+
for (const pattern of [CURRENCY_AMOUNT, LABELED_AMOUNT, PLAIN_AMOUNT]) {
|
|
26
|
+
pattern.lastIndex = 0;
|
|
27
|
+
for (const hit of text.matchAll(pattern)) {
|
|
28
|
+
const value = Number(hit[1].replace(/,/g, ''));
|
|
29
|
+
if (Number.isFinite(value))
|
|
30
|
+
values.push(Math.round(value * 100) / 100);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return values;
|
|
34
|
+
}
|
|
35
|
+
function amountMatches(text, expected) {
|
|
36
|
+
const target = Math.round(expected * 100) / 100;
|
|
37
|
+
return amountsIn(text).some((value) => value === target);
|
|
22
38
|
}
|
|
23
39
|
export class VeriPayUPI {
|
|
24
40
|
constructor(config) {
|
|
@@ -103,7 +119,7 @@ export class VeriPayUPI {
|
|
|
103
119
|
continue;
|
|
104
120
|
if (!reference && mail.date && Date.now() - mail.date.getTime() > FRESH_WINDOW_MS)
|
|
105
121
|
continue;
|
|
106
|
-
const amountSeen =
|
|
122
|
+
const amountSeen = amountMatches(flat, expected);
|
|
107
123
|
if (!amountSeen)
|
|
108
124
|
continue;
|
|
109
125
|
const sender = this.senderName(body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dev-crowagent/veripay-upi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Verify UPI payments automatically from a Gmail inbox over IMAP — amount or UTR matching, QR generation and duplicate protection.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|