upiqr 1.2.3 → 1.3.1
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 +2 -4
- 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
|
@@ -13,11 +13,9 @@ function buildUrl(params) {
|
|
|
13
13
|
if (value)
|
|
14
14
|
qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
|
|
15
15
|
}
|
|
16
|
-
if (!qs.length)
|
|
17
|
-
throw new Error("No valid parameters found to build UPI intent.");
|
|
18
16
|
return "upi://pay?" + qs.slice(0, -1); // Remove trailing '&'
|
|
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
|
+
export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: mc, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, }, qrOptions) {
|
|
21
19
|
return new Promise((resolve, reject) => {
|
|
22
20
|
const params = { pa, pn, am, mam, cu, mc, tid, tr, tn };
|
|
23
21
|
let error = validateParams(params);
|
|
@@ -25,7 +23,7 @@ export default function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode:
|
|
|
25
23
|
return reject(new Error(error));
|
|
26
24
|
const intent = buildUrl(params);
|
|
27
25
|
QRCode
|
|
28
|
-
.toDataURL(intent)
|
|
26
|
+
.toDataURL(intent, qrOptions)
|
|
29
27
|
.then((base64Data) => resolve({ qr: base64Data, intent }))
|
|
30
28
|
.catch(err => reject(new Error("Unable to generate UPI QR Code.\n" + err)));
|
|
31
29
|
});
|
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