upiqr 1.2.2 → 1.3.0
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/README.md +21 -9
- package/dist/index.d.ts +2 -1
- package/dist/index.js +16 -29
- package/dist/types/upiqr.d.ts +3 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,14 +25,11 @@ This package will work on client and server.
|
|
|
25
25
|
payeeVPA: "bhar4t@upi",
|
|
26
26
|
payeeName: "Bharat Sahu"
|
|
27
27
|
})
|
|
28
|
-
.then((
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(
|
|
28
|
+
.then(({ qr, intent }) => {
|
|
29
|
+
console.log(qr); // data:image/png;base64,eR0lGODP...
|
|
30
|
+
console.log(intent); // upi://pay?pa=bhar4t@upi&pn=Bhar...
|
|
31
31
|
})
|
|
32
|
-
.catch(
|
|
33
|
-
console.log(err);
|
|
34
|
-
});
|
|
35
|
-
|
|
32
|
+
.catch(console.error)
|
|
36
33
|
|
|
37
34
|
```
|
|
38
35
|
|
|
@@ -54,9 +51,22 @@ This package will work on client and server.
|
|
|
54
51
|
|
|
55
52
|
In table, fields requirement column is based on static QR, For dynamic QR you need to change more fields along with `payeeVPA` and `payeeName`.
|
|
56
53
|
|
|
57
|
-
For a complete list of supported fields, refer to the [NPCI UPI Linking Specs]
|
|
54
|
+
For a complete list of supported fields, refer to the [NPCI UPI Linking Specs][upi-specs-url]
|
|
55
|
+
|
|
56
|
+
### Customization:
|
|
57
|
+
|
|
58
|
+
Internally using `qrcode` for QR Generation. And, it accepts [second optional param object][qr-code-options] for cusomizing the QR code.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
upiqr(intentFields, {
|
|
62
|
+
color: {
|
|
63
|
+
dark: '#000000',
|
|
64
|
+
light: '#FFFFFF'
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
```
|
|
58
69
|
|
|
59
|
-
Internally using `qrcode` for QR Generation.
|
|
60
70
|
|
|
61
71
|
<!--- [![Code Coverage][codecov-img]][codecov-url] --->
|
|
62
72
|
|
|
@@ -74,3 +84,5 @@ Internally using `qrcode` for QR Generation.
|
|
|
74
84
|
[semantic-release-url]:https://github.com/semantic-release/semantic-release
|
|
75
85
|
[commitizen-img]:https://img.shields.io/badge/commitizen-friendly-brightgreen.svg
|
|
76
86
|
[commitizen-url]:http://commitizen.github.io/cz-cli/
|
|
87
|
+
[qr-code-options]:https://www.npmjs.com/package/qrcode#qr-code-options
|
|
88
|
+
[upi-specs-url]:https://www.npci.org.in/PDF/npci/upi/circular/2017/Circular18_BankCompliances_to_enbaleUPIMerchantecosystem_0.pdf
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import QRCode from 'qrcode';
|
|
1
2
|
import { QRResult, UPIIntentParams } from './types/upiqr';
|
|
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>;
|
|
3
|
+
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }: UPIIntentParams, qrOptions?: QRCode.QRCodeToDataURLOptions): Promise<QRResult>;
|
package/dist/index.js
CHANGED
|
@@ -1,44 +1,31 @@
|
|
|
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
|
|
11
|
-
for (let [key, value] of Object.entries(params))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }) {
|
|
20
|
+
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }, qrOptions) {
|
|
18
21
|
return new Promise((resolve, reject) => {
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
.toDataURL(intent)
|
|
28
|
+
.toDataURL(intent, qrOptions)
|
|
42
29
|
.then((base64Data) => resolve({ qr: base64Data, intent }))
|
|
43
30
|
.catch(err => reject(new Error("Unable to generate UPI QR Code.\n" + err)));
|
|
44
31
|
});
|
package/dist/types/upiqr.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
type ImageType = 'png' | 'jpeg';
|
|
2
|
-
export type Base64<imageType extends ImageType> = `data:image/${imageType};base64
|
|
1
|
+
export type ImageType = 'png' | 'jpeg' | 'webp';
|
|
2
|
+
export type Base64<imageType extends ImageType> = `data:image/${imageType};base64,${string}`;
|
|
3
3
|
export interface UPIIntentParams {
|
|
4
4
|
payeeVPA: string;
|
|
5
5
|
payeeName: string;
|
|
@@ -13,7 +13,6 @@ export interface UPIIntentParams {
|
|
|
13
13
|
transactionRefUrl?: string;
|
|
14
14
|
}
|
|
15
15
|
export interface QRResult {
|
|
16
|
-
qr:
|
|
16
|
+
qr: Base64<ImageType>;
|
|
17
17
|
intent: string;
|
|
18
18
|
}
|
|
19
|
-
export {};
|
package/package.json
CHANGED