payeth-checkout
Version:
Inline Payeth Checkout SDK
3 lines (2 loc) • 2.07 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PayethCheckoutInline=function(){function e(e){if(this.sdkUrl="https://payeth-checkout-qa.herokuapp.com/",this.key=e.key,this.key.length<1)throw new Error("Key cannot be empty");if(this.amount=e.amount,this.amount<=0)throw new Error("Amount must be greater than 0");if(this.currency=null==e.currency?"":e.currency,this.email=null==e.email?"":e.email,this.name=null==e.name?"":e.name,this.onSuccess=e.onSuccess,null==this.onSuccess||"function"!=typeof this.onSuccess)throw new Error("onSuccess must be a function");if(this.onCancel=e.onCancel,null==this.onCancel||"function"!=typeof this.onCancel)throw new Error("onCancel must be a function");var t="";t+="?x_public_key="+this.key,t+="&amount="+this.amount,this.currency.length>0&&(t+="¤cy="+this.currency),this.email.length>0&&(t+="&customer_email="+encodeURI(this.email)),this.name.length>0&&(t+="&customer_name="+encodeURI(this.name));var n=this.sdkUrl+t,s=document.createElement("iframe");s.style.display="none",s.style.border="none",s.style.width="100vw",s.style.height="100vh",s.style.position="absolute",s.style.top="0",s.style.zIndex="24500302",s.allow="payment",s.src=n,this.iframe=s,document.body.appendChild(s);var a=window.addEventListener?"addEventListener":"attachEvent",o=window[a],i=this;o("attachEvent"==a?"onmessage":"message",(function(e){i.handleMessage(e[e.message?"message":"data"])}),!1)}var t=e.prototype;return t.initiate=function(){this.iframe.style.display="flex"},t.handleMessage=function(e){switch(e){case"payeth.modal.cancelled":this.closeModal();break;case"payeth.modal.success":this.paymentSuccess()}},t.closeModal=function(){var e;this.iframe.style.display="none",this.onCancel(),null==(e=this.iframe.contentWindow)||e.postMessage("payeth.modal.close.handle","*")},t.paymentSuccess=function(){var e;this.iframe.style.display="none",this.onSuccess(),null==(e=this.iframe.contentWindow)||e.postMessage("payeth.modal.close.handle","*")},e}();
//# sourceMappingURL=payeth-checkout.cjs.production.min.js.map