@sqala/threedsecure-react
Version:
A React library for implementing 3D Secure authentication flows in payment applications
34 lines (33 loc) • 1.65 kB
JavaScript
import { useCallback as u } from "react";
import { useBase64Encoder as i } from "./useBase64Encoder.js";
import { v as d } from "../v4-CRLUkzQ6.js";
var h = /* @__PURE__ */ ((e) => (e.H400xW250 = "01", e.H400xW390 = "02", e.H600xW500 = "03", e.H400xW600 = "04", e.Fullscreen = "05", e))(h || {});
const m = (e) => {
const { encode: n } = i(), c = u(() => e.current.clientWidth <= 250 && "01" || e.current.clientWidth <= 390 && "02" || e.current.clientWidth <= 500 && "03" || e.current.clientWidth <= 600 && "04" || "05", [e]);
return { executeChallenge: u(async (r, t, s) => {
if (!r.acsUrl || s.hasAttribute("data-submitted"))
return;
e.current.style.position = "relative", t.name = d(), t.style.width = "100%", t.style.height = "100%", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", s.style.visibility = "hidden", s.name = d(), s.target = t.name, s.action = r.acsUrl, s.method = "POST";
const l = document.createElement("input");
l.type = "hidden", l.name = "creq", s.appendChild(l);
const a = {
threeDSServerTransID: r.transactionId,
acsTransID: r.acsTransId,
messageVersion: r.acsProtocolVersion,
messageType: "CReq",
challengeWindowSize: c()
};
l.value = n(a), e.current.appendChild(s), e.current.appendChild(t), await new Promise((o, p) => {
t.onload = () => {
o();
}, t.onerror = (x) => {
p(new Error("Failed to execute challenge"));
}, s.submit(), s.setAttribute("data-submitted", "true");
});
}, [e, n, c]) };
};
export {
h as ChallengeWindowSize,
m as useChallenge
};
//# sourceMappingURL=useChallenge.js.map