upiqr 1.2.2 → 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.
Files changed (2) hide show
  1. package/dist/index.js +14 -27
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,42 +1,29 @@
1
1
  import QRCode from 'qrcode';
2
2
  function validateParams({ pa, pn }) {
3
+ var _a, _b;
3
4
  if (!pa || !pn)
4
5
  return "Virtual Payee's Address/Payee's Name is compulsory";
5
- 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)
6
7
  return "Virtual Payee's Address/Payee's Name is too short.";
7
8
  return '';
8
9
  }
9
10
  function buildUrl(params) {
10
- let url = this, qs = "";
11
- for (let [key, value] of Object.entries(params))
12
- qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
13
- if (qs.length > 0)
14
- url = url + qs;
15
- return url;
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 '&'
16
19
  }
17
20
  export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }) {
18
21
  return new Promise((resolve, reject) => {
19
- let error = validateParams({ pa, pn });
22
+ const params = { pa, pn, am, mam, cu, mc, tid, tr, tn };
23
+ let error = validateParams(params);
20
24
  if (error)
21
- reject(new Error(error));
22
- let intent = "upi://pay?";
23
- if (pa)
24
- intent = buildUrl.call(intent, { pa, pn });
25
- if (am)
26
- intent = buildUrl.call(intent, { am });
27
- if (mam)
28
- intent = buildUrl.call(intent, { mam });
29
- if (cu)
30
- intent = buildUrl.call(intent, { cu });
31
- if (mc)
32
- intent = buildUrl.call(intent, { mc });
33
- if (tid)
34
- intent = buildUrl.call(intent, { tid });
35
- if (tr)
36
- intent = buildUrl.call(intent, { tr }); // tr: transactionRef upto 35 digits
37
- if (tn)
38
- intent = buildUrl.call(intent, { tn });
39
- intent = intent.substring(0, intent.length - 1);
25
+ return reject(new Error(error));
26
+ const intent = buildUrl(params);
40
27
  QRCode
41
28
  .toDataURL(intent)
42
29
  .then((base64Data) => resolve({ qr: base64Data, intent }))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "upiqr",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Generate NPCI's UPI QR code along with UPI intent link, By using it any payment is possible from UPI enabled apps.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",