upiqr 1.3.16 → 1.3.18

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 CHANGED
@@ -35,18 +35,18 @@ This package will work on client and server.
35
35
 
36
36
  ### Fields detail:
37
37
 
38
- | Fields | Description | Required |
39
- |-------------------|---------------------------------------------------|-----------|
40
- | payeeVPA | VPA address from UPI payment account | Mandatory |
41
- | payeeName | Merchant Name registered in UPI payment account | Mandatory |
42
- | payeeMerchantCode | Merchant Code from UPI payment account | Optional |
43
- | transactionId | Unique transaction id for merchant's reference | Optional |
44
- | transactionRef | Unique transaction id for merchant's reference | Optional |
45
- | transactionNote | Note will appear in payment app while transaction | Optional |
46
- | amount | Amount | Optional |
47
- | minimumAmount | Minimum amount that has to be transferred | Optional |
48
- | currency | Currency of amount (default: INR) | Optional |
49
- | transactionRefUrl | URL for the order | Optional |
38
+ | Fields | Description | Required |
39
+ |--------------------|---------------------------------------------------|-----------|
40
+ | `payeeVPA` | UPI ID of the payee (e.g., `example@upi`). | Yes |
41
+ | `payeeName` | Registered name of the payee (e.g., `John Doe`). | Yes |
42
+ | `payeeMerchantCode`| Merchant Code from UPI payment account | No |
43
+ | `transactionId` | Unique transaction id for merchant's reference | No |
44
+ | `transactionRef` | Unique transaction id for merchant's reference | No |
45
+ | `transactionNote` | Note for the payment (e.g., `Electricity Bill`). | No |
46
+ | `amount` | Amount | No |
47
+ | `minimumAmount` | Amount to be paid (e.g., `100.00` or `499`). | No |
48
+ | `currency` | Currency of amount (default: `INR`) | No |
49
+ | `transactionRefUrl`| URL for the order | No |
50
50
 
51
51
 
52
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`.
package/dist/index.d.ts CHANGED
@@ -1,9 +1 @@
1
- import QRCode from 'qrcode';
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 '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
- }
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)));});}
@@ -1,31 +1,3 @@
1
- /**
2
- * Supported image types for the QR code.
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.16",
3
+ "version": "1.3.18",
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
- "build": "tsc"
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",
@@ -44,6 +45,7 @@
44
45
  "devDependencies": {
45
46
  "@types/node": "^20.5.6",
46
47
  "@types/qrcode": "^1.5.1",
48
+ "jsmin": "^1.0.1",
47
49
  "typescript": "^5.2.2"
48
50
  }
49
51
  }