upiqr 1.3.1 → 1.3.4

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 +8 -30
  2. package/package.json +4 -2
package/dist/index.js CHANGED
@@ -1,30 +1,8 @@
1
- import QRCode from 'qrcode';
2
- function validateParams({ pa, pn }) {
3
- var _a, _b;
4
- if (!pa || !pn)
5
- return "Virtual Payee's Address/Payee's Name is compulsory";
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
- return "Virtual Payee's Address/Payee's Name is too short.";
8
- return '';
9
- }
10
- function buildUrl(params) {
11
- let qs = "";
12
- for (let [key, value] of Object.entries(params)) {
13
- if (value)
14
- qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
15
- }
16
- return "upi://pay?" + qs.slice(0, -1); // Remove trailing '&'
17
- }
18
- export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }, qrOptions) {
19
- return new Promise((resolve, reject) => {
20
- const params = { pa, pn, am, mam, cu, mc, tid, tr, tn };
21
- let error = validateParams(params);
22
- if (error)
23
- return reject(new Error(error));
24
- const intent = buildUrl(params);
25
- QRCode
26
- .toDataURL(intent, qrOptions)
27
- .then((base64Data) => resolve({ qr: base64Data, intent }))
28
- .catch(err => reject(new Error("Unable to generate UPI QR Code.\n" + err)));
29
- });
30
- }
1
+ import QRCode from'qrcode';function validateParams({pa,pn}){if(!pa||!pn)
2
+ return"Virtual payee's address/name is compulsory";if(pa.length<5||pn.length<4)
3
+ return"Virtual payee's address/name is too short.";return'';}
4
+ function buildUrl(params){let qs="";for(let[key,value]of Object.entries(params)){if(value)
5
+ qs+=encodeURIComponent(key)+"="+encodeURIComponent(value)+"&";}
6
+ return"upi://pay?"+qs.slice(0,-1);}
7
+ export default function upiqr({payeeVPA:pa,payeeName:pn,payeeMerchantCode:mc,transactionId:tid,transactionRef:tr,transactionNote:tn,amount:am,minimumAmount:mam,currency:cu,},qrOptions){return new Promise((resolve,reject)=>{const params={pa,pn,am,mam,cu,mc,tid,tr,tn};let error=validateParams(params);if(error)
8
+ return reject(new Error(error));const intent=buildUrl(params);QRCode.toDataURL(intent,qrOptions).then((base64Data)=>resolve({qr:base64Data,intent})).catch(err=>reject(new Error("Unable to generate UPI QR Code.\n"+err)));});}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "upiqr",
3
- "version": "1.3.1",
3
+ "version": "1.3.4",
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",
@@ -12,7 +12,8 @@
12
12
  "package.json"
13
13
  ],
14
14
  "scripts": {
15
- "build": "tsc"
15
+ "minify": "jsmin -o dist/index.js dist/index.js",
16
+ "build": "tsc && npm run minify"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",
@@ -34,6 +35,7 @@
34
35
  "devDependencies": {
35
36
  "@types/node": "^20.5.6",
36
37
  "@types/qrcode": "^1.5.1",
38
+ "jsmin": "^1.0.1",
37
39
  "typescript": "^5.2.2"
38
40
  }
39
41
  }