@sqala/threedsecure-react
Version:
A React library for implementing 3D Secure authentication flows in payment applications
29 lines (28 loc) • 1.22 kB
JavaScript
import { useCallback as u } from "react";
import { useBase64Encoder as r } from "./useBase64Encoder.js";
import { v as l } from "../v4-CRLUkzQ6.js";
const M = (o) => {
const { encode: n } = r();
return {
executeDsMethod: u(async (d, t, e) => {
if (!d.dsMethodUrl || e.hasAttribute("data-submitted"))
return;
t.name = l(), t.style.visibility = "hidden", t.style.position = "absolute", t.style.top = "0", t.style.left = "0", t.width = "0", t.height = "0", e.style.visibility = "hidden", e.name = l(), e.target = t.name, e.action = d.dsMethodUrl, e.method = "POST";
const s = document.createElement("input");
s.type = "hidden", s.name = "threeDSMethodData", s.value = n({
threeDSServerTransID: d.transactionId,
threeDSMethodNotificationURL: d.dsMethodCallbackUrl
}), e.appendChild(s), o.current.appendChild(e), o.current.appendChild(t), await new Promise((i, h) => {
t.onload = () => {
i();
}, t.onerror = () => {
h(new Error("Failed to execute dsMethod"));
}, e.submit(), e.setAttribute("data-submitted", "true");
});
}, [n, o])
};
};
export {
M as useDsMethod
};
//# sourceMappingURL=useDsMethod.js.map