UNPKG

@tamara-solution/checkout

Version:

Script will be embedded in merchant's site to checkout. The merchant's don't need to redirect to tamara's site.

2 lines (1 loc) 20.2 kB
function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function r(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function o(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?i(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):i(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function l(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function f(e,t,n){return(f=l()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var a=new(Function.bind.apply(e,r));return n&&u(a,n.prototype),a}).apply(null,arguments)}function h(e){var t="function"==typeof Map?new Map:void 0;return(h=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return f(e,arguments,s(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),u(r,e)})(e)}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function v(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?d(e):t}function p(e){var t=l();return function(){var n,r=s(e);if(t){var a=s(this).constructor;n=Reflect.construct(r,arguments,a)}else n=r.apply(this,arguments);return v(this,n)}}function y(e){return"function"==typeof e}function m(t){return"object"===e(t)&&Array.isArray(t)?"array":e(t)}function g(){return"undefined"!=typeof window&&window.document&&window.document.createElement}function w(){return g()?window.innerWidth:0}function E(){return g()?window.innerHeight:0}function b(e){return e===Object(e)}var O=function(){function e(n){if(t(this,e),!b(n))throw new TamaraTypeError("Config must be an Object");this.styles=o({},n)}return r(e,[{key:"getFrameStyle",value:function(){return this._normalizeStyle({position:"fixed",top:0,right:0,bottom:0,left:0,zIndex:2019,width:"100vw",height:"100vh"})}},{key:"getWrapperStyle",value:function(){var e=o({position:"relative",zIndex:2020,overflow:"hidden",borderRadius:"26px",width:"80vw",height:"80vh",marginTop:"10vh",marginLeft:"10vw",marginRight:"10vw"},this._getWrapperSize());return this._normalizeStyle(e)}},{key:"getIframeStyle",value:function(){var e=o({width:"80vw",height:"80vh",zIndex:2021,position:"relative"},this._getIframeSize());return this._normalizeStyle(e)}},{key:"getBackgroundStyle",value:function(){return this._normalizeStyle({position:"fixed",top:0,right:0,bottom:0,left:0,opacity:.5,zIndex:2019,width:"100vw",height:"100vh",backgroundColor:"#0a1e31"})}},{key:"_getWrapperSize",value:function(){var e=w(),t=E(),n=this._getWidth(),r=(t-this._getHeight())/2,a=(e-n)/2;return{width:this._getWidth()+"px",height:this._getHeight()+"px",marginTop:r+"px",marginLeft:a+"px",marginRight:a+"px"}}},{key:"_getIframeSize",value:function(){return{width:this._getWidth()+"px",height:this._getHeight()+"px"}}},{key:"_getWidth",value:function(){var t,n=e.BREAK_POINTS,r=n.BIG_PHONE,i=n.PHONE_LANDSCAPE,o=n.TABLET,c=n.SMALL_DESKTOP,s=n.MEDIUM_DESKTOP,u=w(),l=Math.max,f=Math.min,h=Math.floor;return(a(t={},u>r,l(r,h(.8*u))),a(t,u>i,l(i,h(.8*u))),a(t,u>o,l(o,h(.8*u))),a(t,u>c,l(c,h(.8*u))),a(t,u>s,f(s,h(.8*u))),t)[!0]||u}},{key:"_getHeight",value:function(){var e=E();return Math.min(Math.floor(.9*e),700)}},{key:"_normalizeStyle",value:function(e){if(!b(e))throw new TamaraTypeError("Config must be an Object");return Object.keys(e).map((function(t){return"".concat((n=t,r={separator:"-"},function(e,t){var n=(t=t||{}).separator||"_",r=t.split||/(?=[A-Z])/;return e.split(r).join(n)}(n,r).toLowerCase()),": ").concat(e[t],";");var n,r})).join("")}}]),e}();function S(){for(var e,t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];(e=console).warn.apply(e,["TAMARA DEBUG >>> "].concat(n))}a(O,"BREAK_POINTS",{BIG_PHONE:414,PHONE_LANDSCAPE:640,TABLET:768,SMALL_DESKTOP:800,MEDIUM_DESKTOP:1024});var _=function(e){c(r,h(Error));var n=p(r);function r(e){var a;return t(this,r),(a=n.call(this,e)).name=a.constructor.name,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(d(a),a.constructor):a.stack=new Error(e).stack,a}return r}(),A=function(e){c(r,h(TypeError));var n=p(r);function r(e){var a;return t(this,r),(a=n.call(this,e)).name=a.constructor.name,"function"==typeof Error.captureStackTrace?Error.captureStackTrace(d(a),a.constructor):a.stack=new Error(e).stack,a}return r}(),C=function(e){c(r,_);var n=p(r);function r(e,a){var i;t(this,r);var o="TAMARA-CHECKOUT >>> "+e;return(i=n.call(this,o)).payload=a,i}return r}(),k=function(e){c(r,A);var n=p(r);function r(e,a){var i;t(this,r);var o="TAMARA-CHECKOUT >>> "+e;return(i=n.call(this,o)).payload=a,i}return r}();function L(){if(!g())throw new C("Do not support none browser yet!!! Please contact tamara team.");return!0}function D(e){if(L())return document.createElement(e)}function z(){}function T(e){var t,n,r,a,i=e||{},o=i.url,c=i.styles,s=void 0===c?{}:c,u=e.loaded||z,l=o||"",f=s.frame||"",h=s.wrapper||"",d=s.iframe||"",v=s.background||"",p=D("div"),y=D("div"),m=D("div"),g=D("iframe"),w=(r={ar_SA:'<svg width="47" height="67" xmlns="http://www.w3.org/2000/svg"><path fill="#6dc8bf" d="M43.596 21.201a2.725 2.725 0 0 0-2.725 2.73c0 9.724-7.886 17.622-17.594 17.622-9.708 0-17.594-7.898-17.594-17.622v-6.85h11.025a2.725 2.725 0 0 0 2.725-2.73c0-1.5-1.209-2.729-2.725-2.729H5.683V2.729a2.725 2.725 0 1 0-5.45 0v21.184c0 12.724 10.34 23.081 23.044 23.081 12.703 0 23.043-10.357 23.043-23.081a2.72 2.72 0 0 0-2.724-2.712z"/><path fill="#6dc8bf" d="M27.102 17.08c.704 0 1.408-.289 1.913-.795a2.753 2.753 0 0 0 .794-1.934c0-.705-.289-1.41-.794-1.934a3.8 3.8 0 0 0-.415-.343 3.875 3.875 0 0 0-.47-.253 2.73 2.73 0 0 0-.505-.163 2.64 2.64 0 0 0-1.064 0c-.18.036-.343.09-.506.163a2.337 2.337 0 0 0-.469.253 2.753 2.753 0 0 0-.415 4.211c.506.506 1.21.796 1.931.796zm10.376 0c.704 0 1.408-.289 1.931-.795a2.753 2.753 0 0 0 .794-1.934c0-.705-.289-1.41-.794-1.916a3.724 3.724 0 0 0-.415-.343 3.873 3.873 0 0 0-.47-.253 2.738 2.738 0 0 0-.504-.163 2.64 2.64 0 0 0-1.065 0c-.18.036-.343.09-.505.163a2.318 2.318 0 0 0-.47.253 2.743 2.743 0 0 0-1.209 2.26c0 .722.29 1.427.794 1.933a2.733 2.733 0 0 0 1.913.795zM.782 50.109a.8.8 0 0 0-.782.803v13.349a.8.8 0 0 0 .782.803c.426 0 .781-.365.781-.803V50.912c0-.438-.355-.803-.781-.803zm43.791 4.017c-.426 0-.782.366-.782.804v7.395c0 1.699-1.261 3.068-2.789 3.068-1.545 0-2.789-1.37-2.789-3.068v-3.524c0-2.575-1.954-4.675-4.352-4.675-2.399 0-4.353 2.1-4.353 4.675v3.524c0 1.699-1.261 3.068-2.789 3.068h-9.416c-1.545 0-2.789-1.37-2.789-3.068V50.912c0-.438-.355-.803-.781-.803a.8.8 0 0 0-.782.803v11.413C12.95 64.9 14.905 67 17.303 67h9.416c1.474 0 2.79-.803 3.57-2.009.782 1.206 2.097 2.01 3.572 2.01 1.474 0 2.789-.804 3.57-2.01.782 1.206 2.097 2.01 3.571 2.01 2.398 0 4.353-2.1 4.353-4.676V54.93a.788.788 0 0 0-.782-.804zM33.861 65.393c-1.546 0-2.79-1.37-2.79-3.068v-3.524c0-1.698 1.262-3.068 2.79-3.068 1.545 0 2.789 1.37 2.789 3.068v3.524c0 1.699-1.262 3.068-2.79 3.068zM10.126 54.126c-.426 0-.781.365-.781.804v7.395c0 1.698-1.262 3.068-2.79 3.068a2.61 2.61 0 0 1-1.687-.62c-.338-.275-.835-.238-1.102.109-.266.347-.23.858.107 1.132A4.072 4.072 0 0 0 6.555 67c2.399 0 4.353-2.1 4.353-4.675V54.93c0-.439-.355-.804-.782-.804zm32.528-1.278c.56 0 1.013-.466 1.013-1.04 0-.576-.453-1.042-1.013-1.042-.559 0-1.012.466-1.012 1.041s.453 1.041 1.012 1.041zm-1.957-.648a1.051 1.051 0 0 0-.548-1.36 1.003 1.003 0 0 0-1.323.563c-.214.532.032 1.14.548 1.36a1.003 1.003 0 0 0 1.323-.563z"/></svg>',en_US:n='<svg width="64" height="66" xmlns="http://www.w3.org/2000/svg"><path fill="#6dc8bf" d="M8.048 60.578a.802.802 0 0 0-.794.795c0 1.68-1.281 3.036-2.833 3.036-1.57 0-2.833-1.355-2.833-3.036V55.86h5.07a.802.802 0 0 0 .795-.795.802.802 0 0 0-.794-.795H1.588v-4.194a.802.802 0 0 0-.794-.795.802.802 0 0 0-.794.795v11.297C0 63.92 1.985 66 4.421 66s4.421-2.079 4.421-4.627a.802.802 0 0 0-.794-.795zm46.827-5.296c.27-.344.234-.85-.109-1.12a4.201 4.201 0 0 0-2.724-.977c-2.436 0-4.421 2.079-4.421 4.627v7.32c0 .434.36.796.794.796a.802.802 0 0 0 .794-.796v-7.32c0-1.68 1.28-3.036 2.833-3.036.631 0 1.227.217 1.714.614a.78.78 0 0 0 1.119-.108zM32.03 53.185c-1.498 0-2.833.795-3.627 1.988-.794-1.193-2.13-1.988-3.627-1.988-2.436 0-4.421 2.079-4.421 4.627v7.32c0 .434.36.796.794.796a.802.802 0 0 0 .794-.796v-7.32c0-1.68 1.281-3.036 2.833-3.036 1.552 0 2.833 1.355 2.833 3.036v7.32c0 .434.361.796.794.796a.802.802 0 0 0 .794-.796v-7.32c0-1.68 1.281-3.036 2.833-3.036 1.57 0 2.833 1.355 2.833 3.036v7.32c0 .434.361.796.794.796a.802.802 0 0 0 .794-.796v-7.32c0-2.548-1.985-4.627-4.42-4.627zm-17.576 0c-.992 0-1.949.343-2.725.976a.784.784 0 0 0-.108 1.12.78.78 0 0 0 1.119.11 2.663 2.663 0 0 1 1.714-.615c.09 0 .18 0 .27.018.037 0 .055 0 .091.018a.64.64 0 0 1 .18.036c.037 0 .073.018.09.018.055.018.11.036.163.036.036.018.072.018.09.036.055.018.109.036.145.055.036.018.054.018.09.036.054.018.108.054.144.072a.136.136 0 0 0 .073.036c.054.036.126.072.18.109.018.018.036.018.036.036.072.054.145.108.199.162l.054.055c.054.036.09.09.144.126.018.018.036.054.072.072.036.037.072.09.109.127.018.036.036.054.072.09s.072.09.09.127c.018.036.036.054.054.09.036.054.054.09.09.145.018.036.036.054.055.09.035.054.054.127.072.181.018.018.018.054.036.072.036.09.072.181.09.253 0 .018 0 .036.018.055.018.054.036.126.054.18h-2.96a4.231 4.231 0 0 0-4.222 4.23c0 2.548 1.985 4.627 4.421 4.627 1.137 0 2.111-.38 2.833-.777a.798.798 0 0 0 .794.777.802.802 0 0 0 .794-.795v-7.375c0-2.53-1.985-4.609-4.42-4.609zm-2.833 8.188a2.64 2.64 0 0 1 2.635-2.639h3.031v4.573c-.45.361-1.515 1.102-2.833 1.102-1.57 0-2.833-1.355-2.833-3.036zm30.189-8.188c-.992 0-1.949.343-2.725.976a.784.784 0 0 0-.108 1.12.78.78 0 0 0 1.119.11 2.664 2.664 0 0 1 1.714-.615c.09 0 .18 0 .27.018.037 0 .055 0 .091.018a.64.64 0 0 1 .18.036c.037 0 .073.018.09.018.055.018.109.036.163.036.036.018.072.018.09.036.054.018.109.036.145.055.036.018.054.018.09.036.054.018.108.054.144.072a.137.137 0 0 0 .072.036c.055.036.127.072.181.109.018.018.036.018.036.036.072.054.144.108.199.162l.054.055c.054.036.09.09.144.126.018.018.036.054.072.072.036.037.072.09.108.127.019.036.037.054.073.09s.072.09.09.127c.018.036.036.054.054.09.036.054.054.09.09.145.018.036.036.054.054.09.037.054.055.127.073.181.018.018.018.054.036.072.036.09.072.181.09.253 0 .018 0 .036.018.055.018.054.036.126.054.18h-2.96a4.231 4.231 0 0 0-4.222 4.23c0 2.548 1.985 4.627 4.421 4.627 1.137 0 2.111-.38 2.833-.777a.798.798 0 0 0 .794.777.802.802 0 0 0 .794-.795v-7.375c0-2.53-1.985-4.609-4.42-4.609zm-2.85 8.188a2.64 2.64 0 0 1 2.634-2.639h3.031v4.573c-.45.361-1.516 1.102-2.833 1.102-1.552 0-2.833-1.355-2.833-3.036zm20.084-8.188c-.993 0-1.95.343-2.725.976a.784.784 0 0 0-.108 1.12.78.78 0 0 0 1.118.11 2.663 2.663 0 0 1 1.715-.615c.09 0 .18 0 .27.018.036 0 .054 0 .09.018a.64.64 0 0 1 .18.036c.037 0 .073.018.091.018.054.018.108.036.163.036.036.018.072.018.09.036.054.018.108.036.144.055.036.018.054.018.09.036.055.018.109.054.145.072a.137.137 0 0 0 .072.036c.054.036.126.072.18.109.018.018.036.018.036.036.073.054.145.108.199.162l.054.055c.054.036.09.09.144.126.019.018.037.054.073.072.036.037.072.09.108.127a.316.316 0 0 0 .072.09.55.55 0 0 1 .09.127c.018.036.036.054.054.09.036.054.055.09.09.145.019.036.037.054.055.09a.542.542 0 0 1 .072.181c.018.018.018.054.036.072.036.09.054.163.09.253 0 .018.018.036.018.055a.64.64 0 0 1 .036.18h-2.959a4.231 4.231 0 0 0-4.222 4.23c0 2.548 1.984 4.627 4.42 4.627 1.137 0 2.112-.38 2.834-.777.018.433.36.777.794.777a.802.802 0 0 0 .794-.795v-7.375c.018-2.53-1.967-4.609-4.403-4.609zm-2.833 8.188a2.64 2.64 0 0 1 2.634-2.639h3.032v4.573c-.452.361-1.516 1.102-2.833 1.102-1.57 0-2.833-1.355-2.833-3.036zm-4.169-40.172a2.725 2.725 0 0 0-2.725 2.73c0 9.724-7.886 17.622-17.594 17.622-9.708 0-17.594-7.898-17.594-17.622v-6.85h11.026a2.725 2.725 0 0 0 2.725-2.73c0-1.5-1.21-2.729-2.725-2.729H14.129V2.729a2.725 2.725 0 1 0-5.45 0v21.184c0 12.724 10.34 23.081 23.044 23.081s23.044-10.357 23.044-23.081a2.72 2.72 0 0 0-2.725-2.712z"/><path fill="#6dc8bf" d="M35.548 17.08c.704 0 1.408-.289 1.913-.795a2.753 2.753 0 0 0 .794-1.934c0-.705-.288-1.41-.794-1.934a3.81 3.81 0 0 0-.415-.343 3.875 3.875 0 0 0-.469-.253 2.731 2.731 0 0 0-.505-.163 2.64 2.64 0 0 0-1.065 0c-.18.036-.343.09-.505.163a2.318 2.318 0 0 0-.47.253 2.753 2.753 0 0 0-.415 4.211 2.744 2.744 0 0 0 1.931.796zm10.377 0c.703 0 1.407-.289 1.93-.795a2.753 2.753 0 0 0 .794-1.934 2.74 2.74 0 0 0-.794-1.916 3.724 3.724 0 0 0-.415-.343 3.88 3.88 0 0 0-.469-.253 2.738 2.738 0 0 0-.505-.163 2.64 2.64 0 0 0-1.065 0c-.18.036-.343.09-.505.163-.162.072-.325.144-.47.253a2.743 2.743 0 0 0-1.209 2.26c0 .722.29 1.427.795 1.933a2.733 2.733 0 0 0 1.913.795z"/></svg>'}[t]||n,(a=D("div")).setAttribute("id","tamara-placeholder-logo"),a.setAttribute("style","width: 100%;height: 100%;display: flex;align-items: center;justify-content: center;background-color: #fff; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 2020;"),a.innerHTML=r,a);return p.setAttribute("id","tamara-checkout-frame"),p.setAttribute("style",f),y.setAttribute("style",h),m.setAttribute("style",v),g.setAttribute("id","tamara-checkout-iframe"),g.setAttribute("src",l),g.setAttribute("frameborder","0"),g.setAttribute("style",d),g.addEventListener("load",u),y.appendChild(w),y.appendChild(g),p.appendChild(y),p.appendChild(m),{frameElement:p,iframe:g,wrapperIframe:y}}var H=/^https:\/\/checkout(-staging|-sandbox){0,1}.tamara.co\/{0,1}\?(&{0,1}\w*=\w*)*checkoutFrame\=iframe(&{0,1}\w*=\w*)*/,R=/^https{0,1}:\/\/localhost:[0-9]{4}\/{0,1}\?(&{0,1}\w*=\w*)*checkoutFrame\=iframe(&{0,1}\w*=\w*)*/,M=/^https{0,1}:\/\/(127|192)(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}:[0-9]{4}\/{0,1}\?(&{0,1}\w*=\w*)*checkoutFrame\=iframe(&{0,1}\w*=\w*)*$/;var j={STARTED:"STARTED",LOADED:"LOADED",CLOSED:"CLOSED",SUCCESS:"SUCCESS",FAILED:"FAILED",CANCELED:"CANCELED"},P="ORDER_SUCCESS",I="ORDER_FAILED",x="ORDER_CANCELED",F=function(){function e(){t(this,e),this.config={},this.eventHandlers={},this.styles=new O({}),this.resizeListener=null,this.Events=Object.freeze(o({},j)),this._listenEventFromIframe()}return r(e,[{key:"init",value:function(e){this.config=e||{};var t=(e||{}).style,n=void 0===t?{}:t;this.styles=new O(o({},n))}},{key:"checkout",value:function(e){this.callListener(this.Events.STARTED,{started:!0});var t=T({url:this._getCheckoutURL(e),styles:this._getStyle(),loaded:this._callbackLoaded.bind(this)}),n=t.frameElement,r=t.iframe,a=t.wrapperIframe;this.resizeListener=this._recalculateStyle.bind(this,a,r),window.addEventListener("resize",this.resizeListener),function(e,t){if(L(),"body"!==e)document.getElementById(e).appendChild(t);else{if(null===document.body)throw new C("The script loaded incorrectly. Please check the documentation and try again!");document.body.appendChild(t)}}("body",n)}},{key:"addEventHandlers",value:function(e,t){if(this.config.debug&&S("ADD Event hanlders >>> ",e),"function"!==m(t))throw new k("Handler must be a function!");if("array"!==m(this.eventHandlers[e])&&(this.eventHandlers[e]=[]),this.config.debug&&S("Event hanlders >>> Before ADD >>> ",this.eventHandlers),this.eventHandlers[e].indexOf(t)>-1)throw new C("The handler is exist already!");this.eventHandlers[e].push(t),this.config.debug&&(S("Event hanlders >>> After ADDED >>> ",this.eventHandlers),S("ADD Event hanlders >>> SUCCESS"))}},{key:"removeEventHandlers",value:function(e,t){if(this.config.debug&&S("REMOVE Event hanlders >>> ",e),"function"!==m(t))throw new k("Handler must be a function!");if("array"!==m(this.eventHandlers[e]))return!0;this.config.debug&&S("Event hanlders >>> Before REMOVE >>> ",this.eventHandlers);var n=this.eventHandlers[e].indexOf(t);n>-1&&this.eventHandlers[e].splice(n,1),this.config.debug&&(S("Event hanlders >>> After REMOVED >>> ",this.eventHandlers),S("REMOVE Event hanlders >>> SUCCESS"))}},{key:"removeAllEventHandlers",value:function(e){if(this.config.debug&&S("REMOVE_ALL Event hanlders >>> ",e),"function"!==m(handler))throw new k("Handler must be a function!");if("array"!==m(this.eventHandlers[e]))return!0;this.config.debug&&S("Event hanlders >>> Before REMOVE_ALL >>> ",this.eventHandlers),this.eventHandlers[e]=[],this.config.debug&&(S("Event hanlders >>> After REMOVED >>> ",this.eventHandlers),S("REMOVE_ALL Event hanlders >>> SUCCESS"))}},{key:"callListener",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.eventHandlers[e];this.config.debug&&S("TRIGGER Event >>> ",e,t),"array"===m(n)&&n.length>0&&n.forEach((function(e){y(e)&&e(t)}))}},{key:"_recalculateStyle",value:function(e,t){var n=this._getStyle(),r=n.wrapper||"",a=n.iframe||"";e.setAttribute("style",r),t.setAttribute("style",a)}},{key:"_getStyle",value:function(){return{frame:this.styles.getFrameStyle(),wrapper:this.styles.getWrapperStyle(),iframe:this.styles.getIframeStyle(),background:this.styles.getBackgroundStyle()}}},{key:"_removePlaceholderLogo",value:function(){}},{key:"_getCheckoutURL",value:function(e){var t,n=(t=e,R.test(t)||M.test(t));if(!function(e){return H.test(e)}(e)&&n)throw new C("The URL is not tamara's domain.");return"".concat(e,"&checkoutFrame=iframe")}},{key:"_callbackLoaded",value:function(){this.callListener(this.Events.LOADED,{loaded:!0})}},{key:"_listenEventFromIframe",value:function(){var e,t=(a(e={},P,this._handleOrderSuccess.bind(this)),a(e,I,this._handleOrderFailed.bind(this)),a(e,x,this._handleOrderCanceled.bind(this)),e);window.addEventListener("message",(function(e){var n=e.data||{},r=n.type,a=n.event,i=n.data;if("tamara_checkout_message"===r){var o=t[a];y(o)&&o(i)}}))}},{key:"_handleOrderSuccess",value:function(e){this.callListener(this.Events.SUCCESS,e),this._closeIframe()}},{key:"_handleOrderFailed",value:function(e){this.callListener(this.Events.FAILED,e),this._closeIframe()}},{key:"_handleOrderCanceled",value:function(e){this.callListener(this.Events.CANCELED,e),this._closeIframe()}},{key:"_closeIframe",value:function(){!function(e){L();var t=document.getElementById(e);t&&t.remove()}("tamara-checkout-frame"),this.callListener(this.Events.CLOSED),window.removeEventListener("resize",this.resizeListener)}}]),e}();function U(){var t,n=new F;if("object"===e(t=window.tamaraCKOConfig)&&t===Object(t)){var r=window.tamaraCKOConfig.namespace||"TamaraCheckoutFrame";window[r]=n,window[r].init(window.tamaraCKOConfig),y(window.tamaraCKOConfig.init)&&window.tamaraCKOConfig.init()}else window.TamaraCheckoutFrame=n}g()&&(null!==document.body?U():window.addEventListener("DOMContentLoaded",(function(){U()})));export default null;