-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters