(function(window, document, undefined) { var PagaCheckout = (function (name) { var root = typeof window !== 'undefined' ? window : global, had = Object.prototype.hasOwnProperty.call(root, name), prev = root[name], me = root[name] = {}, jQuery = null, form = null, button = null, frame = null; if (typeof PagaCheckout !== 'undefined' && PagaCheckout.exports) { PagaCheckout.exports = me; } var _utils = { user_agent : window.navigator.userAgent, $: function(sel){ return document.querySelectorAll(sel) }, a$ : function(elem, att_name){ return elem.getAttribute(att_name) }, $$ : function(cls) { var el, reg, _i, _len, _ref, _results; if (typeof document.getElementsByClassName === "function") { return document.getElementsByClassName(cls) } else if (typeof document.querySelectorAll === "function") { return document.querySelectorAll("." + cls) } else { reg = new RegExp("(^|\\s)" + cls + "(\\s|$)"); _ref = document.getElementsByTagName("*"); _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { el = _ref[_i]; if (reg.test(el.className)) { _results.push(el) } } return _results } }, escape: function(value) { return value && ("" + value).replace(/&/g, "&").replace(//g, ">").replace(/\"/g, """) }, trim: function(value) { return value.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, "") }, user_agent_version : function (regex) { return function () { var ua = this.user_agent.match(regex); return ua && parseInt(uaMatch[1]) } }, attr_prop_name : function (attribute) { return attribute.nodeName.substring("data-".length); }, serialize : function(obj, prefix) { var str = []; for(var p in obj) { if (obj.hasOwnProperty(p)) { var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p]; str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v)); } } return str.join("&"); }, form_to_params : function(elm, next_scope) { var propName; var val; var _ref; var element; var elements; var data; var key; var i; var _len; var l; if (null == next_scope) { /** @type {Array} */ next_scope = []; } if (elm.jquery) { elm = elm[0]; } _ref = elm.getElementsByTagName("input"); elements = elm.getElementsByTagName("select"); data = {}; /** @type {number} */ key = 0; _len = _ref.length; for (;_len > key;key++) { val = _ref[key]; data[val.getAttribute('name')] = val.value; } /** @type {number} */ i = 0; l = elements.length; for (;l > i;i++) { element = elements[i]; data[element.getAttribute('name')] = element.options[element.selectedIndex].value; } if(!data['charge_url']){ data['charge_url'] = elm.action } return data; }, create_hidden : function(n, v){ var i = document.createElement('input'); i.type='hidden'; i.name=n; i.value=v; return i; }, host: function(url) { var parent, parser; parent = document.createElement("div"); parent.innerHTML = 'x'; parser = parent.firstChild; return "" + parser.protocol + "//" + parser.host }, deviceType : function (){ /* @media (min-width:320px) { // smartphones, iPhone, portrait 480x320 phones @media (min-width:481px) { // portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. @media (min-width:641px) { // portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones @media (min-width:961px) { // tablet, landscape iPad, lo-res laptops ands desktops @media (min-width:1025px) { // big landscape tablets, laptops, and desktops @media (min-width:1281px) { // hi-res laptops and desktops */ if(window.matchMedia("only screen and (max-width: 480px)").matches) { return 'mobile'; } if(window.matchMedia("only screen and (max-height: 480px) and (orientation : landscape)").matches) { return 'mobile'; } if(window.matchMedia("only screen and (max-width: 960px) and (orientation : portrait)").matches) { return 'tablet'; } return 'desktop'; }, isHD : function (){ return ((window.matchMedia && (window.matchMedia('only screen and (min-resolution: 124dpi), only screen and (min-resolution: 1.3dppx), only screen and (min-resolution: 48.8dpcm)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3), only screen and (-o-min-device-pixel-ratio: 2.6/2), only screen and (min--moz-device-pixel-ratio: 1.3), only screen and (min-device-pixel-ratio: 1.3)').matches)) || (window.devicePixelRatio && window.devicePixelRatio > 1.3)); }, scriptAsync: function(doc, url, onload) { var script_tag = doc.createElement('script'); script_tag.setAttribute("type", "text/javascript"); script_tag.setAttribute("src", url); if (onload) { if (script_tag.readyState) { script_tag.onreadystatechange = function () { // For old versions of IE if (this.readyState == 'complete' || this.readyState == 'loaded') { onload(); } }; } else { // Other browsers script_tag.onload = onload; } } // Try to find the head, otherwise default to the documentElement (doc.getElementsByTagName("head")[0] || doc.documentElement).appendChild(script_tag); }, request : function(url, params, callback) { var image, k, v; if (params == null) { params = {} } params.i = (new Date).getTime(); params = function() { var _results; _results = []; for (k in params) { v = params[k]; _results.push("" + k + "=" + encode(v)) } return _results }().join("&"); image = new Image; if (callback) { image.onload = callback } image.src = "" + url + "?" + params; return true }, init: function() { this.iOSVersion = this.user_agent_version(/(?:iPhone OS |iPad; CPU OS )(\d+)_\d+/); this.iOSMinorVersion = this.user_agent_version(/(?:iPhone OS |iPad; CPU OS )\d+_(\d+)/); this.iOSBuildVersion = this.user_agent_version(/(?:iPhone OS |iPad; CPU OS )\d+_\d+_(\d+)/); this.androidWebkitVersion = this.user_agent_version(/Mozilla\/5\.0.*Android.*AppleWebKit\/([\d]+)/); this.androidVersion = this.user_agent_version(/Android (\d+)\.\d+/); this.firefoxVersion = this.user_agent_version(/Firefox\/(\d+)\.\d+/); this.chromeVersion = this.user_agent_version(/Chrome\/(\d+)\.\d+/); this.safariVersion = this.user_agent_version(/Version\/(\d+)\.\d+ Safari/); this.iOSChromeVersion = this.user_agent_version(/CriOS\/(\d+)\.\d+/); this.ieVersion = this.user_agent_version(/(?:MSIE |Trident\/.*rv:)(\d{1,2})\./); this.isiOS = /iPad|iPhone|iPod/.test(this.user_agent) && !window.MSStream; this.isAndroidOS = /Android/.test(this.user_agent) && !window.MSStream; return this; } }.init(); //var _css = function(){ // var h = document.getElementsByTagName('head')[0]; // var c = document.createElement('link'); // c.type = 'text/css'; // c.rel = 'stylesheet'; // c.href = 'https://www.mypaga.com/checkout/assets/css/checkout.css'; // c.media = 'screen'; // h.appendChild(c); //}; var _form = function() { var me = document.currentScript; if(!me) { me = document.querySelector('script[data-public_key]'); } if(!me) { var scripts = document.getElementsByTagName("script") for (var i = 0; i < scripts.length; ++i) { if( scripts[i].src.indexOf('paga-webservices/checkout') > -1){ me = scripts[i]; break; } } } if(!me) { alert('Unable to execute checkout script. You may be using an unsupported browser. For help, please refer to developer documentation at: '); throw 'Unable to execute checkout script. You may be using an unsupported browser.'; } var pub_key = me.getAttribute('data-public_key'); if(!pub_key || pub_key.length == 0) { alert('Unable to execute checkout script. Missing required "data-public_key" parameter'); throw 'Unable to execute checkout script. Missing required "data-public_key" parameter'; } var f = me.parentNode; if(!f || !f.tagName == 'form') { if(!f.getAttribute('data-charge_url')) { alert('Unable to execute checkout. You must include your script in a
element with an action attribute or include the "data-charge_url" parameter in your script tag. For help, please refer to developer documentation at: '); throw 'Unable to execute checkout. You must include your script in a element with an action attribute or include the "data-charge_url" parameter in your script tag.'; } f = document.createElement('form'); f.method = "post"; me.parentNode.insertBefore(f, me.nextSibling); } var create_data_attribute = function(attribute){ if(!attribute.nodeName.startsWith('data-')){ return null; } f.appendChild(_utils.create_hidden(_utils.attr_prop_name(attribute), attribute.nodeValue)); }; var atts = me.attributes; for (var i = 0; i < atts.length; i++){ create_data_attribute(atts[i]); } return f; }; var _button = function(form) { var btn_h = '40'; var btn_w = '150'; var btn_url = 'https://donate.ng/assets/images/brand/donate_button.png'; btn_url = btn_url || 'https://www.mypaga.com/checkout/assets/img/pwp' + (_utils.isHD() ? '@2x' : '') + '.png'; if(btn_h.length > 0 || btn_w.length > 0) { if(btn_h.length == 0) { btn_h = btn_w / 4.5; } else if(btn_h.length == 0) { btn_w = btn_h * 4.5; } } else { btn_h = 30; btn_w = 135; } var a = document.createElement('a'); a.setAttribute('style','width: ' + btn_w + 'px; height: ' + btn_h + 'px; visibility: visible; display: block; cursor: pointer; background: center no-repeat url(' + btn_url + '); background-size: ' + btn_w + 'px ' + btn_h + 'px;'); a.className = 'checkout-btn'; a.setAttribute('onclick','PagaCheckout.submit();'); form.appendChild(a); }; var _frame = function() { var frame = document.createElement("iframe"); frame.setAttribute("allowtransparency", "true"); frame.setAttribute("frameBorder", "0"); frame.setAttribute("src", 'https://www.mypaga.com/checkout/frame'); var bg = _utils.deviceType() === 'mobile' ? "#fff" : "transparent"; var css = "z-index: 2000000000;\ndisplay: none;\nbackground: " + bg + ";\nborder: 0px none transparent;\noverflow-x: hidden;\noverflow-y: auto;\nvisibility: hidden;\nmargin: 0;\npadding: 0;\n-webkit-tap-highlight-color: transparent;\n-webkit-touch-callout: none;"; if (_utils.isiOS || _utils.isAndroidOS) { css += "position: absolute;\ntop:0;\nleft:0;\nwidth: 100vw;\nheight: 100vh;" } else { css += "position: fixed;\nleft: 0;\ntop: 0;\nwidth: 100%;\nheight: 100%;" } frame.style.cssText = css; document.body.appendChild(frame); return frame; }; var _scripts = function() { // Localize jQuery variable /******** Load jQuery if not present *********/ if (!window.jQuery || (window.jQuery && window.jQuery.fn.jquery !== '3.6.0')) { _utils.scriptAsync(document, 'https://www.mypaga.com/checkout/assets/js/vendor/jquery/jquery-3.6.0.min.js', function() { /******** Called once jQuery has loaded ******/ // Restore $ and window.jQuery to their previous values and store the // new jQuery in our local jQuery variable jQuery = window.jQuery.noConflict(true); }); } else { jQuery = window.jQuery; } }; var initialize = function() { //_css(); _scripts(); form = _form(); button = _button(form); frame = _frame(); //allow CORS messaging from frame using postMessage window.addEventListener("message", receiveMessage, false); function receiveMessage(event) { var origin = event.origin || event.originalEvent.origin; // For Chrome, the origin property is in the event.originalEvent object. if (origin !== 'https://www.mypaga.com') { return; } try { var name = event.data.name; switch (name) { case 'open': open(event.source); break; case 'openError': close(); alert(event.data.data + ". Please contact the merchant and provide this error message."); break; case 'close': close(); break; } } catch(e) { return; } } }; var close = function(){ jQuery(frame).css({'visibility':'visible', 'display':'block'}).off('load'); frame.style.visibility = 'hidden'; frame.style.display = 'none'; frame.setAttribute("src", 'https://www.mypaga.com/checkout/frame'); }; /** public function **/ var noConflict = function () { if (root[name] === me) { root[name] = had ? prev : undefined; if (!had) { try { delete root[name]; } catch (ex) {} } } return me; }; /** public function **/ var submit = function(){ jQuery(frame).css({'visibility':'visible', 'display':'block'}); frame.src = 'https://www.mypaga.com/checkout/open?device=' + _utils.deviceType() + '&hd=' + (_utils.isHD() ? 'true&origin=' : 'false&origin=') + encodeURIComponent(document.origin || document.defaultView.location.origin) + '&' + _utils.serialize(_utils.form_to_params(form)); }; /** public function **/ var open = function(frameWindow){ function keyUpHandler(e) { if (e.keyCode == 13) { // enter e.preventDefault(); return false; }; if (e.keyCode == 27) { // esc close(); } } jQuery(document).on('keyup', keyUpHandler); var message = { name : 'open', data : {} }; frameWindow.postMessage(message, 'https://www.mypaga.com'); }; /** public function **/ var complete3Ds = function (authorizationReference, authorizationStatusCode, authorizationMessage, authorizationDataMap) { try { jQuery.ajax({ url: 'https://www.mypaga.com/checkout/card/auth3DS', method: 'post', contentType: "application/json", data: jQuery.stringifyJSON({ 'authorizationStatusCode': authorizationStatusCode, 'authorizationReference': authorizationReference, 'authorizationMessage': authorizationMessage, 'authorizationDataJSON': authorizationDataMap }), success: function (data, textStatus, jqXHR) { var $baBtn = jQuery('#bank-auth-button', $bauth) pay_success($baBtn, data); /* var $3ds = jQuery('.content.recognized', $checkout); jQuery('#iframe-3ds', $3ds).setAttribute("src", 'jqXHR.responseText'); var $visible = jQuery('.body .content:visible', frame_doc); resize(357); transit($visible, $3ds); */ }, error: function (jqXHR, textStatus, errorThrown) { var errorMsg = jqXHR.responseText || jqXHR.statusText || textStatus || 'processing error'; var $pay = jQuery("#pay",frame_doc); error($pay, 'right', errorMsg); resetHtml($pay); } }); } catch (e) { error($pay, 'right', e); resetHtml($pay); } }; return { noConflict: noConflict, initialize: initialize, submit : submit, open : open }; return me; })('PagaCheckout'); this.PagaCheckout.noConflict = PagaCheckout.noConflict; this.PagaCheckout.submit = PagaCheckout.submit; this.PagaCheckout.open = PagaCheckout.open; PagaCheckout.initialize(); }(window, document));