modify-qris
Version:
Modify QRIS Generator is a javascript based libraries that enabling flexible payments with customizable amounts for improved efficiency and user experience
66 lines (65 loc) • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Parse = void 0;
const qris_1 = require("./helpers/qris");
const crc16_ccitt_1 = require("./helpers/crc16_ccitt");
class Parse {
constructor(codeString) {
this.codeString = codeString;
}
getCodeString() {
return this.codeString;
}
codeStringIsEmpty() {
if ([undefined, ''].includes(this.codeString)) {
return true;
}
return false;
}
parsed() {
let result;
if (this.codeStringIsEmpty()) {
return result;
}
result = qris_1.QRIS.parse(this.codeString);
return result;
}
checkErrorParsed() {
let results;
if (this.codeStringIsEmpty()) {
const errors = [];
errors.push('Code is not empty!');
return {
status: false,
errors: errors,
};
}
const parsed = qris_1.QRIS.parse(this.codeString);
const isValid = qris_1.QRIS.isValid(parsed);
return {
status: isValid.length <= 0,
errors: isValid,
};
}
isValid() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6;
const qrisParsed = this.parsed();
let qrStringConverted = ((_b = (_a = qrisParsed.version) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : '') +
((_d = (_c = qrisParsed.category) === null || _c === void 0 ? void 0 : _c.data) !== null && _d !== void 0 ? _d : '') +
((_f = (_e = qrisParsed.acquirer) === null || _e === void 0 ? void 0 : _e.data) !== null && _f !== void 0 ? _f : '') +
((_h = (_g = qrisParsed.switching) === null || _g === void 0 ? void 0 : _g.data) !== null && _h !== void 0 ? _h : '') +
((_k = (_j = qrisParsed.merchant_category_code) === null || _j === void 0 ? void 0 : _j.data) !== null && _k !== void 0 ? _k : '') +
((_m = (_l = qrisParsed.currency_code) === null || _l === void 0 ? void 0 : _l.data) !== null && _m !== void 0 ? _m : '') +
((_p = (_o = qrisParsed.payment_amount) === null || _o === void 0 ? void 0 : _o.data) !== null && _p !== void 0 ? _p : '') +
((_r = (_q = qrisParsed.payment_fee_category) === null || _q === void 0 ? void 0 : _q.data) !== null && _r !== void 0 ? _r : '') +
((_t = (_s = qrisParsed.payment_fee) === null || _s === void 0 ? void 0 : _s.data) !== null && _t !== void 0 ? _t : '') +
((_v = (_u = qrisParsed.country_code) === null || _u === void 0 ? void 0 : _u.data) !== null && _v !== void 0 ? _v : '') +
((_x = (_w = qrisParsed.merchant_name) === null || _w === void 0 ? void 0 : _w.data) !== null && _x !== void 0 ? _x : '') +
((_z = (_y = qrisParsed.merchant_city) === null || _y === void 0 ? void 0 : _y.data) !== null && _z !== void 0 ? _z : '') +
((_1 = (_0 = qrisParsed.merchant_postal_code) === null || _0 === void 0 ? void 0 : _0.data) !== null && _1 !== void 0 ? _1 : '') +
((_3 = (_2 = qrisParsed.additional_information) === null || _2 === void 0 ? void 0 : _2.data) !== null && _3 !== void 0 ? _3 : '') +
((_5 = (_4 = qrisParsed.crc_code) === null || _4 === void 0 ? void 0 : _4.tag) !== null && _5 !== void 0 ? _5 : '') + '04';
return ((_6 = qrisParsed.crc_code) === null || _6 === void 0 ? void 0 : _6.content) === crc16_ccitt_1.CRC16CCITT.generateCode(qrStringConverted);
}
}
exports.Parse = Parse;