(function (window) { // You can enable the strict mode commenting the following line   // 'use strict'; // This function will contain all our code function loadJS(path) { var script = document.createElement('script'); script.type = "text/javascript"; script.src = path; document.getElementsByTagName('head')[0].appendChild(script); } function loadCSS(path) { var css = document.createElement('link'); css.rel = "stylesheet"; css.href = path; document.getElementsByTagName('head')[0].appendChild(css); } function gw() { var _gwObject = {}; var _gwFrameID; var _merchant_key; var _invoice_id; var _callback; if (!window.jQuery) { var script = document.createElement('script'); script.type = "text/javascript"; script.src = "https://code.jquery.com/jquery-3.5.1.min.js"; script.integrity = "sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" document.getElementsByTagName('head')[0].appendChild(script); } document.addEventListener("DOMContentLoaded", function () { var overlayElem = document.createElement('div'); overlayElem.id = "overlay"; document.body.appendChild(overlayElem); var modalOverlayElem = document.createElement('div'); modalOverlayElem.id = "gw_modal"; document.body.appendChild(modalOverlayElem); //Load overlay script loadJS("https://cdnjs.cloudflare.com/ajax/libs/jquery-loading-overlay/2.1.7/loadingoverlay.min.js"); loadJS("https://cdnjs.cloudflare.com/ajax/libs/izimodal/1.5.1/js/iziModal.min.js"); loadCSS("https://cdnjs.cloudflare.com/ajax/libs/izimodal/1.5.1/css/iziModal.min.css"); //$.fn.iziModal = iziModal; //$("#gw_modal").iziModal(); // $("#modal-iframe").iziModal({ // iframe: true, // iframeHeight: 800, // iframeURL: "http://izimodal.marcelodolza.com" // }); }); // Just create a property to our library object. _gwObject.Init = function (frameID, merchant_key, invoice_id, callback) { _gwFrameID = frameID; _merchant_key = merchant_key; _invoice_id = invoice_id; _callback = callback; iframe = document.getElementById(_gwFrameID); iframe.frameBorder = 0; iframe.height = "180px"; iframe.contentWindow.postMessage({ event_id: "init_form", data: { merchant_key: _merchant_key, invoice_id: _invoice_id } }, '*'); }; _gwObject.Pay = function () { iframe = document.getElementById(_gwFrameID); iframe.contentWindow.postMessage({ event_id: "perform_3ds_check", data: { merchant_key: _merchant_key, invoice_id: _invoice_id } }, '*'); }; _gwObject.CompletePayment = function () { iframe = document.getElementById(_gwFrameID); iframe.contentWindow.postMessage({ event_id: "pay", data: { merchant_key: _merchant_key, invoice_id: _invoice_id } }, '*'); }; _gwObject.Show3DsForm = function(url){ //$("#gw_modal").iziModal(); console.log(url); $("#gw_modal").iziModal({ iframe: true, iframeHeight: 800, iframeURL: url, zindex: 4000 }); $('#gw_modal').iziModal('setFullscreen', true); $('#gw_modal').iziModal('open'); } _gwObject.ShowOverlay = function () { $.LoadingOverlay("show"); }; _gwObject.HideOverlay = function () { $.LoadingOverlay("hide"); }; _gwObject.PaidEventHandler = function (e) { console.log("PaidEventHandler called"); console.log(e); // alert(e.data.msg); _callback(e); }; _gwObject.FailedEventHandler = function (e) { // alert(e.data.msg); _callback(e); }; _gwObject.ErrorEventHandler = function (e) { // alert(e.data.msg); _callback(e); }; _gwObject.MessageHandler = function (e) { if (e.data.event_id == 'gw_show_overlay') { _gwObject.ShowOverlay(); } else if (e.data.event_id == 'gw_hide_overlay') { _gwObject.HideOverlay(); } else if (e.data.event_id == 'gw_show_3ds_form') { _gwObject.Show3DsForm(e.data.data.url); } else if (e.data.event_id == 'gw_auth_failed') { $('#gw_modal').iziModal('close'); //alert("Authentication failed"); //_gwObject.Pay(); _gwObject.FailedEventHandler(e.data); } else if (e.data.event_id == 'gw_auth_ok') { $('#gw_modal').iziModal('close'); _gwObject.ShowOverlay(); _gwObject.CompletePayment(); } else if (e.data.event_id == 'gw_paid'){ _gwObject.HideOverlay(); _gwObject.PaidEventHandler(e.data); } else if (e.data.event_id == 'gw_auth_failed'){ _gwObject.HideOverlay(); _gwObject.FailedEventHandler(e.data); } else if (e.data.event_id == 'gw_pay_failed'){ _gwObject.HideOverlay(); _gwObject.FailedEventHandler(e.data); } else if (e.data.event_id == 'gw_pay_unsuccessful'){ _gwObject.HideOverlay(); _gwObject.FailedEventHandler(e.data); }else if (e.data.event_id == 'gw_pay_unexpected'){ _gwObject.HideOverlay(); _gwObject.FailedEventHandler(e.data); } }; return _gwObject; } // We need that our library is globally accesible, then we save in the window if (typeof (window.gw) === 'undefined') { window.gw = gw(); window.addEventListener("message", window.gw.MessageHandler, false); } })(window); // We send the window variable withing our function // Then we can call our custom function using //myWindowGlobalLibraryName.myCustomLog(["My library","Rules"]);