sepa-payment-code
Version:
Generates SEPA payment codes for embedding in QR codes
57 lines • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var IBAN = require("iban");
var PaymentCode = /** @class */ (function () {
function PaymentCode(name, iban, amount, structuredText, unstructuredText) {
this.structuredText = "";
this.unstructuredText = "";
if (!name) {
throw new Error("Name cannot be empty");
}
if (!IBAN.isValid(iban)) {
throw new Error("Invalid IBAN");
}
if (amount < 0.01 || amount > 999999999.99) {
throw new Error("Amount must be 0.01 or more and 999999999.99 or less");
}
this.name = name;
this.amount = amount;
this.iban = iban;
if (structuredText && unstructuredText) {
throw new Error("You can't set structured and unstructured text at the same time");
}
if (structuredText) {
this.structuredText = structuredText;
}
else if (unstructuredText) {
this.unstructuredText = unstructuredText;
}
}
PaymentCode.prototype.getPayload = function () {
var serviceTag = "BCD";
var version = "002";
var characterSet = 1;
var identification = "SCT";
var bic = "";
var amount = "EUR" + this.amount;
var purpose = "";
var information = "";
return [
serviceTag,
version,
characterSet,
identification,
bic,
this.name,
this.iban.replace(/ /g, ""),
amount,
purpose,
this.structuredText,
this.unstructuredText,
information,
].join("\n");
};
return PaymentCode;
}());
exports.PaymentCode = PaymentCode;
//# sourceMappingURL=PaymentCode.js.map