Skip to content

Commit

Permalink
Removed dist from .gitignore
Browse files Browse the repository at this point in the history
  • Loading branch information
bhar4t committed Aug 26, 2023
1 parent f7ae8e4 commit 0a0be19
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 4 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ build/Release
node_modules/
jspm_packages/

# Distribution directories
dist/

# Typescript v1 declaration files
typings/

Expand Down
26 changes: 26 additions & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
declare const QRCode: any;
type ImageType = 'png' | 'jpeg';
type Base64<imageType extends ImageType> = `data:image/${imageType};base64${string}`;
interface UPIIntentParams {
payeeVPA?: string;
payeeName?: string;
payeeMerchantCode?: string;
transactionId?: string;
transactionRef?: string;
transactionNote?: string;
amount?: string;
minimumAmount?: string;
currency?: string;
transactionRefUrl?: string;
}
interface UPIIntentResult {
qr: string;
intent: string;
error: string;
}
declare function validateParams({ pa, pn }: {
pa: string | undefined;
pn: string | undefined;
}): string;
declare function buildUrl(this: string, params: object): string;
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>;
49 changes: 49 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use strict";
const QRCode = require("qrcode");
function validateParams({ pa, pn }) {
let error = '';
if (!pa || !pn)
return "Virtual Payee's Address/Payee's Name is compulsory";
if ((pa === null || pa === void 0 ? void 0 : pa.length) < 5 || (pn === null || pn === void 0 ? void 0 : pn.length) < 4)
return "Virtual Payee's Address/Payee's Name is too short.";
return error;
}
function buildUrl(params) {
let url = this, qs = "";
for (let [key, value] of Object.entries(params))
qs += encodeURIComponent(key) + "=" + encodeURIComponent(value) + "&";
if (qs.length > 0)
url = url + qs;
return url;
}
function upiqr({ payeeVPA: pa, payeeName: pn, payeeMerchantCode: me, transactionId: tid, transactionRef: tr, transactionNote: tn, amount: am, minimumAmount: mam, currency: cu, transactionRefUrl: url, }) {
return new Promise((resolve, reject) => {
let error = validateParams({ pa, pn });
if (error)
reject(new Error(error));
let intent = "upi://pay?";
if (pa)
intent = buildUrl.call(intent, { pa, pn });
if (am)
intent = buildUrl.call(intent, { am });
if (mam)
intent = buildUrl.call(intent, { mam });
if (cu)
intent = buildUrl.call(intent, { cu });
if (me)
intent = buildUrl.call(intent, { me });
if (tid)
intent = buildUrl.call(intent, { tid });
if (tr)
intent = buildUrl.call(intent, { tr }); // tr: transactionRef upto 35 digits
if (tn)
intent = buildUrl.call(intent, { tn });
intent = intent.substring(0, intent.length - 1);
QRCode.toDataURL(intent, (err, qr) => {
if (err)
reject(new Error("Unable to generate UPI QR Code."));
resolve({ qr, intent, error: '' });
});
});
}
exports.default = upiqr;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "upiqr",
"version": "1.0.34",
"version": "1.0.35",
"description": "Generate NPCI's UPI QR code along with UPI intent link, By using it any payment is possible from UPI enabled apps.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

0 comments on commit 0a0be19

Please sign in to comment.