Frontend JS
<!-- PHP/Laravel -->
<script src="/js/checkout.js" result="{{ isset($result) ? json_encode($result) : '' }}" csrf="{{ csrf_token() }}"></script>function submit3DSForm() {
var threeDSContainer = document.createElement('div');
threeDSContainer.setAttribute("id", "threeDSContainer");
threeDSContainer.classList.add('flexcenter');
document.body.appendChild(threeDSContainer);
var threeDSIframe = document.createElement("iframe");
threeDSIframe.setAttribute("id", "threeDSIframe");
threeDSIframe.setAttribute("height", "1");
threeDSIframe.setAttribute("width", "1");
threeDSIframe.setAttribute("sandbox", "allow-scripts allow-forms allow-top-navigation allow-same-origin allow-popups allow-modals allow-popups allow-popups-to-escape-sandbox allow-top-navigation-by-user-activation");
threeDSIframe.setAttribute("name", "threeds_iframe");
threeDSContainer.appendChild(threeDSIframe);
var threeDSForm = document.createElement("form");
threeDSForm.setAttribute("method", "post");
threeDSForm.setAttribute("target", "threeds_iframe");
threeDSForm.setAttribute("action", result.threeDSUrl);
threeDSForm.classList.add('hidden');
threeDSContainer.appendChild(threeDSForm);
if(!result.display) {
threeDSIframe.classList.add('hidden');
} else {
var threeDSBackground = document.createElement('div');
threeDSBackground.setAttribute("id", "iframeBackground");
threeDSContainer.appendChild(threeDSBackground);
threeDSForm.setAttribute("target", "_parent");
threeDSIframe.classList.remove('hidden');
}
let response = JSON.parse(result.threeDSMethodData);
Object.keys(response).forEach(key => {
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("name", key);
input.value = response[key];
threeDSForm.appendChild(input);
});
var input = document.createElement("input");
input.setAttribute("type", "text");
input.setAttribute("name", "_token");
input.value = csrf;
threeDSForm.appendChild(input);
var button = document.createElement("button");
button.setAttribute("type", "submit");
threeDSForm.appendChild(button);
button.click();
}Last updated