promptpay
Version:
PromptPay QR Code Toolkit
36 lines (31 loc) • 805 B
JavaScript
const { anyId } = require("promptparse/generate");
const QRCode = require("qrcode");
module.exports = {
/**
*
* @param {string} target Mobile No., Tax ID, Ewallet ID, etc.
* @param {string} amount Amount to Transfer
* @param {string} outputType 'base64url', 'terminal' (default 'base64url')
*/
qr: async (target, amount = null, outputType = 'base64url') => {
let type = 'MSISDN'
if (target.length == 13) {
type = 'NATID'
} else if (target.length >= 15) {
type = 'EWALLETID'
}
const payload = anyId({
type,
target,
amount
})
if (outputType == 'terminal') {
return await QRCode.toString(payload, {
errorCorrectionLevel: 'M',
})
}
return await QRCode.toDataURL(payload, {
errorCorrectionLevel: 'M',
})
}
};