@hokodo/hokodo-js
Version:
Hokodo JS SDK
2 lines (1 loc) • 7.74 kB
JavaScript
!function(){var t=0;function e(e){return"__private_"+t+++"_"+e}function n(t,e){if(!Object.prototype.hasOwnProperty.call(t,e))throw new TypeError("attempted to use private field on non-instance");return t}var r,o=function(){var t=function(t,e){return t.toString(16).padStart(e)},e=new DataView(new ArrayBuffer(16));return crypto.getRandomValues(new Uint8Array(e.buffer)),e.setUint8(6,15&e.getUint8(6)|64),e.setUint8(8,63&e.getUint8(8)|128),t(e.getUint32(0),8)+"-"+t(e.getUint16(4),4)+"-"+t(e.getUint16(6),4)+"-"+t(e.getUint16(8),4)+"-"+t(e.getUint32(10),8)+t(e.getUint16(14),4)};!function(t){t.READY="ready",t.SUCCESS="success",t.FAILURE="failure",t.CANCEL="cancel"}(r||(r={}));var i,a=e("wrapperId"),s=e("dialogId"),l=e("frameId"),c=e("target"),d=e("mounted"),u=e("component"),p=e("events"),m=e("eventHandler"),h=e("paymentUrl"),v=e("emit"),f=function(){function t(t){var e=this,i=t.paymentUrl;Object.defineProperty(this,v,{value:g}),Object.defineProperty(this,a,{writable:!0,value:void 0}),Object.defineProperty(this,s,{writable:!0,value:void 0}),Object.defineProperty(this,l,{writable:!0,value:void 0}),Object.defineProperty(this,c,{writable:!0,value:void 0}),Object.defineProperty(this,d,{writable:!0,value:void 0}),Object.defineProperty(this,u,{writable:!0,value:void 0}),Object.defineProperty(this,p,{writable:!0,value:void 0}),Object.defineProperty(this,m,{writable:!0,value:void 0}),Object.defineProperty(this,h,{writable:!0,value:void 0}),n(this,a)[a]="__privateHokodoDialog__Wrapper-"+o(),n(this,s)[s]="__privateHokodoDialog-"+o(),n(this,l)[l]="__privateHokodoDialog__Frame-"+o(),n(this,c)[c]=null,n(this,d)[d]=!1,n(this,p)[p]={};var f,b,y=new RegExp(/pay(-.*)?\.hokodo.co/);n(this,h)[h]=(i||"https://pay.hokodo.co").replace(y,"i-pay$1.hokodo.co"),n(this,h)[h]&&!y.test(i)?(n(this,u)[u]=null,console.error("Integration Error - Incorrect payment URL passed to Dialog element")):n(this,u)[u]=function(t){var e=t.wrapperId,n=t.dialogId,r=t.frameId,o=t.src,i=t.onLoad,a=document.createElement("dialog");a.setAttribute("id",n),a.setAttribute("open","true"),a.setAttribute("style","\n z-index: 99999 !important;\n position: fixed !important;\n padding: 0 !important;\n border: none !important;\n box-shadow: 0px 0px 13px 0px rgb(0 0 0 / 50%) !important;\n width: 90vw !important;\n max-width: 1000px !important;\n height: 96vh !important;\n top: 50% !important;\n left: 50% !important;\n transform: translate(-50%, -50%) !important;\n background-image: url(\"data:image/svg+xml,%3C%3Fxml version='1.0' encoding='UTF-8'%3F%3E%3Csvg width='80px' height='80px' display='block' style='margin:auto' preserveAspectRatio='xMidYMid' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='50' cy='50' r='40' fill='none' stroke='%23ca8a2a' stroke-dasharray='188.49555921538757 64.83185307179586' stroke-width='14'%3E%3CanimateTransform attributeName='transform' dur='1s' keyTimes='0;1' repeatCount='indefinite' type='rotate' values='0 50 50;360 50 50'/%3E%3C/circle%3E%3C/svg%3E%0A\") !important;\n background-position: center !important;\n background-color: white !important;\n background-repeat: no-repeat !important;\n ".replace(/\s\s+/g," ").trim());var s=document.createElement("div");s.setAttribute("style","\n z-index: 99998 !important;\n position: fixed !important;\n top: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n left: 0 !important;\n background: rgba(0, 0, 0, 0.4) !important;\n ".replace(/\s\s+/g," ").trim());var l=document.createElement("iframe");l.setAttribute("id",r),l.setAttribute("title","Hokodo Buy Now Pay Later Form"),l.setAttribute("frameBorder","0"),l.setAttribute("scrolling","yes"),l.setAttribute("allowTransparency","true"),l.setAttribute("allow","payment *"),l.setAttribute("loading","lazy"),o&&l.setAttribute("src",o),l.onload=function(){var t=document.getElementById(r);t&&(t.style.opacity="1"),i()},l.setAttribute("style","\n border: none !important;\n margin: 0px !important;\n padding: 0px !important;\n width: 1px !important;\n min-width: 100% !important;\n min-height: 100% !important;\n overflow: scroll !important;\n display: block !important;\n user-select: none !important;\n will-change: transform !important;\n opacity: 0 !important;\n transition: opacity 0.2s cubic-bezier(.42,0,.58,1)\n ".replace(/\s\s+/g," ").trim()),a.appendChild(l);var c=document.createElement("div");return c.setAttribute("id",e),c.appendChild(s),c.appendChild(a),c}({wrapperId:n(this,a)[a],dialogId:n(this,s)[s],frameId:n(this,l)[l],src:n(this,h)[h],onLoad:function(){return n(e,v)[v](r.READY)}}),n(this,m)[m]=(f=function(t){n(e,v)[v](t.event.action)},b=new URL(n(this,h)[h]).origin,function(t){var e=function(t){try{var e="string"==typeof t?JSON.parse(t):t;return function(t){return!0===(null==t?void 0:t.hokodoJs)}(e)?e:null}catch(t){return null}}(t.data);e&&t.origin===b&&f(e)})}var e=t.prototype;return e.mount=function(t){n(this,d)[d]?console.error("Integration Error - An element can only be mounted once."):(t&&(n(this,c)[c]=document.querySelector(t)),!t||n(this,c)[c]?n(this,u)[u]?(window.addEventListener("message",n(this,m)[m]),n(this,c)[c]?n(this,c)[c].innerHTML=n(this,u)[u].innerHTML:document.body.appendChild(n(this,u)[u]),n(this,d)[d]=!0):console.error("Integration error - The element has been destroyed, please recreate element to mount."):console.error("Integration error - The provided element target not found"))},e.unmount=function(){n(this,u)[u]&&n(this,d)[d]?(window.removeEventListener("message",n(this,m)[m]),n(this,c)[c]?n(this,c)[c].innerHTML="":document.body.removeChild(n(this,u)[u]),n(this,d)[d]=!1):console.warn("Integration error - An element must be created and mounted before it can be unmounted.")},e.destroy=function(){this.unmount(),n(this,u)[u]=null,n(this,d)[d]=!1,n(this,p)[p]={}},e.on=function(t,e){var o;Object.values(r).includes(t)?(n(this,p)[p][t]=n(this,p)[p][t]||[],null==(o=n(this,p)[p][t])||o.push(e)):console.warn('Integration error - The event "'+t+'" does not exist for the dialog element.')},t}();function g(t){var e;n(this,p)[p][t]&&(null==(e=n(this,p)[p][t])||e.forEach(function(t){t()}))}!function(t){t.DIALOG="dialog"}(i||(i={}));var b=e("createdElements"),y=e("create"),w=function(){function t(){}var e=t.prototype;return e.getElement=function(e){var r;return(null==(r=n(t,b)[b])?void 0:r[e])||(console.error('Integration Error - Element "'+e+'" does not exist.'),null)},e.create=function(e,r){switch(e){case i.DIALOG:if(r.paymentUrl)return n(t,y)[y](i.DIALOG,new f(r));console.error("Integration error - Incorrect Dialog options passed.");break;default:console.warn("Integration Issue - No such element available")}return null},t}();Object.defineProperty(w,y,{value:function(t,e){var r;return null!=(r=n(w,b)[b])&&r[t]?(console.error('Integration Error - Element "'+t+'" already exist.'),null):(n(w,b)[b]=n(w,b)[b]||{},n(w,b)[b][t]=e,n(w,b)[b][t]||null)}}),Object.defineProperty(w,b,{writable:!0,value:void 0});var E=e("instance"),I=e("elementsInstance"),x=function(){function t(){}return t.getInstance=function(){return n(t,E)[E]?console.error("Integration Error - Please only initialise the Hokodo instance only once per."):n(t,E)[E]=new t,n(t,E)[E]},t.prototype.elements=function(){return n(t,I)[I]?console.error("Integration Error - Please only initialise the Elements instance only once per."):n(t,I)[I]=new w,n(t,I)[I]},t}();Object.defineProperty(x,E,{writable:!0,value:void 0}),Object.defineProperty(x,I,{writable:!0,value:void 0});var A=function(){return x.getInstance()};A.version="0.0.1-alpha.5",typeof module<"u"?module.exports=A:self.Hokodo=A}();