upiqr 1.3.10 → 1.3.12

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 +45 -8
  2. package/package.json +6 -4
package/dist/index.js CHANGED
@@ -1,8 +1,45 @@
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)));});}
1
+ import QRCode from 'qrcode';
2
+ /**
3
+ * Validates the required parameters for generating UPI intent.
4
+ * @param {Object} params - The parameters object containing payeeVPA and payeeName.
5
+ * @returns {string} - An error message if validation fails, otherwise an empty string.
6
+ */
7
+ function validate({ pa, pn }) {
8
+ if (!pa || !pn)
9
+ return "Virtual payee's address/name is compulsory";
10
+ if (pa.length < 5 || pn.length < 4)
11
+ return "Virtual payee's address/name is too short.";
12
+ return '';
13
+ }
14
+ /**
15
+ * Builds the UPI intent URL from the given parameters.
16
+ * @param {Object} params - The parameters object containing UPI intent fields.
17
+ * @returns {string} - The constructed UPI intent URL.
18
+ */
19
+ function buildUrl(params) {
20
+ let qs = "";
21
+ for (let [key, value] of Object.entries(params)) {
22
+ if (value)
23
+ qs += `${encodeURIComponent(key)}=${encodeURIComponent(value)}&`;
24
+ }
25
+ return "upi://pay?" + qs.slice(0, -1); // Remove trailing '&'
26
+ }
27
+ /**
28
+ * Generates a UPI QR code and intent URL.
29
+ * @param {UPIIntentParams} params - The UPI intent parameters.
30
+ * @param {QRCode.QRCodeToDataURLOptions} [qrOptions] - Optional QR code generation options.
31
+ * @returns {Promise<QRResult>} - A promise that resolves to the QR code and intent URL.
32
+ */
33
+ export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }, qrOptions) {
34
+ const params = { pa, pn, am, mam, cu, mc, tid, tr, tn };
35
+ const error = validate(params);
36
+ if (error)
37
+ return Promise.reject(new Error(error));
38
+ const intent = buildUrl(params);
39
+ return new Promise((resolve, reject) => {
40
+ QRCode
41
+ .toDataURL(intent, qrOptions)
42
+ .then((base64Data) => resolve({ qr: base64Data, intent }))
43
+ .catch(err => reject(new Error("Unable to generate UPI QR Code.\n" + err)));
44
+ });
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "upiqr",
3
- "version": "1.3.10",
3
+ "version": "1.3.12",
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,8 +12,7 @@
12
12
  "package.json"
13
13
  ],
14
14
  "scripts": {
15
- "minify": "jsmin -o dist/index.js dist/index.js",
16
- "build": "tsc && npm run minify"
15
+ "build": "tsc"
17
16
  },
18
17
  "repository": {
19
18
  "type": "git",
@@ -29,13 +28,16 @@
29
28
  ],
30
29
  "author": "Bharat Sahu",
31
30
  "license": "MIT",
31
+ "funding": {
32
+ "type": "github",
33
+ "url": "https://github.com/sponsors/bhar4t/"
34
+ },
32
35
  "dependencies": {
33
36
  "qrcode": "^1.4.4"
34
37
  },
35
38
  "devDependencies": {
36
39
  "@types/node": "^20.5.6",
37
40
  "@types/qrcode": "^1.5.1",
38
- "jsmin": "^1.0.1",
39
41
  "typescript": "^5.2.2"
40
42
  }
41
43
  }