upiqr 1.2.1 → 1.2.3
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/dist/index.d.ts +1 -1
- package/dist/index.js +16 -30
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { QRResult, UPIIntentParams } from './types/upiqr';
|
|
2
|
-
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode:
|
|
2
|
+
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }: UPIIntentParams): Promise<QRResult>;
|
package/dist/index.js
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
import QRCode from 'qrcode';
|
|
2
2
|
function validateParams({ pa, pn }) {
|
|
3
|
-
|
|
3
|
+
var _a, _b;
|
|
4
4
|
if (!pa || !pn)
|
|
5
5
|
return "Virtual Payee's Address/Payee's Name is compulsory";
|
|
6
|
-
if ((pa === null || pa === void 0 ? void 0 : pa.length) < 5 || (pn === null || pn === void 0 ? void 0 : pn.length) < 4)
|
|
6
|
+
if (((_a = pa === null || pa === void 0 ? void 0 : pa.length) !== null && _a !== void 0 ? _a : 0) < 5 || ((_b = pn === null || pn === void 0 ? void 0 : pn.length) !== null && _b !== void 0 ? _b : 0) < 4)
|
|
7
7
|
return "Virtual Payee's Address/Payee's Name is too short.";
|
|
8
|
-
return
|
|
8
|
+
return '';
|
|
9
9
|
}
|
|
10
10
|
function buildUrl(params) {
|
|
11
|
-
let
|
|
12
|
-
for (let [key, value] of Object.entries(params))
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
let qs = "";
|
|
12
|
+
for (let [key, value] of Object.entries(params)) {
|
|
13
|
+
if (value)
|
|
14
|
+
qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
|
|
15
|
+
}
|
|
16
|
+
if (!qs.length)
|
|
17
|
+
throw new Error("No valid parameters found to build UPI intent.");
|
|
18
|
+
return "upi://pay?" + qs.slice(0, -1); // Remove trailing '&'
|
|
17
19
|
}
|
|
18
|
-
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode:
|
|
20
|
+
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }) {
|
|
19
21
|
return new Promise((resolve, reject) => {
|
|
20
|
-
|
|
22
|
+
const params = { pa, pn, am, mam, cu, mc, tid, tr, tn };
|
|
23
|
+
let error = validateParams(params);
|
|
21
24
|
if (error)
|
|
22
|
-
reject(new Error(error));
|
|
23
|
-
|
|
24
|
-
if (pa)
|
|
25
|
-
intent = buildUrl.call(intent, { pa, pn });
|
|
26
|
-
if (am)
|
|
27
|
-
intent = buildUrl.call(intent, { am });
|
|
28
|
-
if (mam)
|
|
29
|
-
intent = buildUrl.call(intent, { mam });
|
|
30
|
-
if (cu)
|
|
31
|
-
intent = buildUrl.call(intent, { cu });
|
|
32
|
-
if (me)
|
|
33
|
-
intent = buildUrl.call(intent, { me });
|
|
34
|
-
if (tid)
|
|
35
|
-
intent = buildUrl.call(intent, { tid });
|
|
36
|
-
if (tr)
|
|
37
|
-
intent = buildUrl.call(intent, { tr }); // tr: transactionRef upto 35 digits
|
|
38
|
-
if (tn)
|
|
39
|
-
intent = buildUrl.call(intent, { tn });
|
|
40
|
-
intent = intent.substring(0, intent.length - 1);
|
|
25
|
+
return reject(new Error(error));
|
|
26
|
+
const intent = buildUrl(params);
|
|
41
27
|
QRCode
|
|
42
28
|
.toDataURL(intent)
|
|
43
29
|
.then((base64Data) => resolve({ qr: base64Data, intent }))
|
package/package.json
CHANGED