upiqr 1.0.34 → 1.0.35

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.
@@ -0,0 +1,26 @@
1
+ declare const QRCode: any;
2
+ type ImageType = 'png' | 'jpeg';
3
+ type Base64<imageType extends ImageType> = `data:image/${imageType};base64${string}`;
4
+ interface UPIIntentParams {
5
+ payeeVPA?: string;
6
+ payeeName?: string;
7
+ payeeMerchantCode?: string;
8
+ transactionId?: string;
9
+ transactionRef?: string;
10
+ transactionNote?: string;
11
+ amount?: string;
12
+ minimumAmount?: string;
13
+ currency?: string;
14
+ transactionRefUrl?: string;
15
+ }
16
+ interface UPIIntentResult {
17
+ qr: string;
18
+ intent: string;
19
+ error: string;
20
+ }
21
+ declare function validateParams({ pa, pn }: {
22
+ pa: string | undefined;
23
+ pn: string | undefined;
24
+ }): string;
25
+ declare function buildUrl(this: string, params: object): string;
26
+ declare function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: me, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, transactionRefUrl, }: UPIIntentParams): Promise<UPIIntentResult | Error>;
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ const QRCode = require("qrcode");
3
+ function validateParams({ pa, pn }) {
4
+ let error = '';
5
+ if (!pa || !pn)
6
+ return "Virtual Payee's Address/Payee's Name is compulsory";
7
+ if ((pa === null || pa === void 0 ? void 0 : pa.length) < 5 || (pn === null || pn === void 0 ? void 0 : pn.length) < 4)
8
+ return "Virtual Payee's Address/Payee's Name is too short.";
9
+ return error;
10
+ }
11
+ function buildUrl(params) {
12
+ let url = this, qs = "";
13
+ for (let [key, value] of Object.entries(params))
14
+ qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
15
+ if (qs.length > 0)
16
+ url = url + qs;
17
+ return url;
18
+ }
19
+ function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: me, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, transactionRefUrl: url, }) {
20
+ return new Promise((resolve, reject) => {
21
+ let error = validateParams({ pa, pn });
22
+ if (error)
23
+ reject(new Error(error));
24
+ let intent = "upi://pay?";
25
+ if (pa)
26
+ intent = buildUrl.call(intent, { pa, pn });
27
+ if (am)
28
+ intent = buildUrl.call(intent, { am });
29
+ if (mam)
30
+ intent = buildUrl.call(intent, { mam });
31
+ if (cu)
32
+ intent = buildUrl.call(intent, { cu });
33
+ if (me)
34
+ intent = buildUrl.call(intent, { me });
35
+ if (tid)
36
+ intent = buildUrl.call(intent, { tid });
37
+ if (tr)
38
+ intent = buildUrl.call(intent, { tr }); // tr: transactionRef upto 35 digits
39
+ if (tn)
40
+ intent = buildUrl.call(intent, { tn });
41
+ intent = intent.substring(0, intent.length - 1);
42
+ QRCode.toDataURL(intent, (err, qr) => {
43
+ if (err)
44
+ reject(new Error("Unable to generate UPI QR Code."));
45
+ resolve({ qr, intent, error: '' });
46
+ });
47
+ });
48
+ }
49
+ exports.default = upiqr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "upiqr",
3
- "version": "1.0.34",
3
+ "version": "1.0.35",
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",