upiqr 1.3.15 → 1.3.17
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/dist/index.d.ts +1 -9
- package/dist/index.js +8 -45
- package/dist/types/upiqr.d.ts +3 -31
- package/package.json +7 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
import QRCode from
|
|
2
|
-
import { QRResult, UPIIntentParams } from './types/upiqr';
|
|
3
|
-
/**
|
|
4
|
-
* Generates a UPI QR code and intent URL.
|
|
5
|
-
* @param {UPIIntentParams} params - The UPI intent parameters.
|
|
6
|
-
* @param {QRCode.QRCodeToDataURLOptions} [qrOptions] - Optional QR code generation options.
|
|
7
|
-
* @returns {Promise<QRResult>} - A promise that resolves to the QR code and intent URL.
|
|
8
|
-
*/
|
|
9
|
-
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>;
|
|
1
|
+
import QRCode from'qrcode';import{QRResult,UPIIntentParams}from'./types/upiqr';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,45 +1,8 @@
|
|
|
1
|
-
import QRCode from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function
|
|
8
|
-
|
|
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
|
-
}
|
|
1
|
+
import QRCode from'qrcode';function validate({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){const params={pa,pn,am,mam,cu,mc,tid,tr,tn};const error=validate(params);if(error)
|
|
8
|
+
return Promise.reject(new Error(error));const intent=buildUrl(params);return new Promise((resolve,reject)=>{QRCode.toDataURL(intent,qrOptions).then((base64Data)=>resolve({qr:base64Data,intent})).catch(err=>reject(new Error("Unable to generate UPI QR Code.\n"+err)));});}
|
package/dist/types/upiqr.d.ts
CHANGED
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export type ImageType = 'png' | 'jpeg' | 'webp';
|
|
5
|
-
/**
|
|
6
|
-
* Base64 encoded image string.
|
|
7
|
-
* @template imageType - The type of the image.
|
|
8
|
-
*/
|
|
9
|
-
export type Base64<imageType extends ImageType> = `data:image/${imageType};base64,${string}`;
|
|
10
|
-
/**
|
|
11
|
-
* Parameters for generating UPI intent.
|
|
12
|
-
*/
|
|
13
|
-
export interface UPIIntentParams {
|
|
14
|
-
payeeVPA: string;
|
|
15
|
-
payeeName: string;
|
|
16
|
-
payeeMerchantCode?: string;
|
|
17
|
-
transactionId?: string;
|
|
18
|
-
transactionRef?: string;
|
|
19
|
-
transactionNote?: string;
|
|
20
|
-
amount?: string;
|
|
21
|
-
minimumAmount?: string;
|
|
22
|
-
currency?: string;
|
|
23
|
-
transactionRefUrl?: string;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Result of the UPI QR code generation.
|
|
27
|
-
*/
|
|
28
|
-
export interface QRResult {
|
|
29
|
-
qr: Base64<ImageType>;
|
|
30
|
-
intent: string;
|
|
31
|
-
}
|
|
1
|
+
|
|
2
|
+
export type ImageType='png'|'jpeg'|'webp';export type Base64<imageType extends ImageType>=`data:image/${imageType};base64,${string}`;export interface UPIIntentParams{payeeVPA:string;payeeName:string;payeeMerchantCode?:string;transactionId?:string;transactionRef?:string;transactionNote?:string;amount?:string;minimumAmount?:string;currency?:string;transactionRefUrl?:string;}
|
|
3
|
+
export interface QRResult{qr:Base64<ImageType>;intent:string;}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "upiqr",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.17",
|
|
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
|
-
"
|
|
15
|
+
"minify": "jsmin -o dist/index.d.ts dist/index.d.ts && jsmin -o dist/index.js dist/index.js && jsmin -o dist/types/upiqr.d.ts dist/types/upiqr.d.ts",
|
|
16
|
+
"build": "tsc && npm run minify"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -29,6 +30,9 @@
|
|
|
29
30
|
"upi qr code",
|
|
30
31
|
"NPCI"
|
|
31
32
|
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"provenance": true
|
|
35
|
+
},
|
|
32
36
|
"author": "Bharat Sahu",
|
|
33
37
|
"license": "MIT",
|
|
34
38
|
"funding": {
|
|
@@ -41,6 +45,7 @@
|
|
|
41
45
|
"devDependencies": {
|
|
42
46
|
"@types/node": "^20.5.6",
|
|
43
47
|
"@types/qrcode": "^1.5.1",
|
|
48
|
+
"jsmin": "^1.0.1",
|
|
44
49
|
"typescript": "^5.2.2"
|
|
45
50
|
}
|
|
46
51
|
}
|