@sqala/threedsecure-js
Version:
A vanilla library for implementing 3D Secure authentication flows in payment applications
47 lines (46 loc) • 2.15 kB
JavaScript
var l = Object.defineProperty;
var c = (i, e, t) => e in i ? l(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
var o = (i, e, t) => c(i, typeof e != "symbol" ? e + "" : e, t);
import h from "./assert.js";
import { v as m } from "../v4-CRLUkzQ6.js";
class b {
constructor(e, t) {
o(this, "iFrame");
o(this, "form");
this.logger = e, this.base64Encoder = t;
}
async executeDsMethod(e, t) {
var s;
try {
if (h(e.dsMethodUrl, "dsMethodUrl is required"), h(e.dsMethodCallbackUrl, "dsMethodCallbackUrl is required"), (s = this.form) != null && s.hasAttribute("data-submitted"))
return;
this.iFrame = document.createElement("iframe"), this.iFrame.name = m(), this.iFrame.style.visibility = "hidden", this.iFrame.style.position = "absolute", this.iFrame.style.top = "0", this.iFrame.style.left = "0", this.iFrame.width = "0", this.iFrame.height = "0", this.form = document.createElement("form"), this.form.style.visibility = "hidden", this.form.name = m(), this.form.target = this.iFrame.name, this.form.action = e.dsMethodUrl, this.form.method = "POST";
const r = document.createElement("input");
r.type = "hidden", r.name = "threeDSMethodData", r.value = this.base64Encoder.encode({
threeDSServerTransID: e.transactionId,
threeDSMethodNotificationURL: e.dsMethodCallbackUrl
}), this.form.appendChild(r), t.appendChild(this.form), t.appendChild(this.iFrame), await new Promise((a, d) => {
this.iFrame.onload = () => {
a();
}, this.iFrame.onerror = () => {
d(new Error("Failed to execute dsMethod"));
}, this.form.submit(), this.form.setAttribute("data-submitted", "true");
});
} catch (r) {
throw this.logger("DSMethodService: error", r), r;
}
}
clean() {
var e, t;
this.logger("DSMethodService: clean");
try {
(e = this.iFrame) == null || e.remove(), (t = this.form) == null || t.remove();
} catch (s) {
this.logger("DSMethodService: clean - error", s);
}
}
}
export {
b as DsMethodService
};
//# sourceMappingURL=dsmethod-service.js.map