@getruba/checkout 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ var e="RUBA_PAYMENT_METHOD",t="/embed/payment-method",a="ruba_payment_method_status",n=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},s=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},o=class o{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,a){this.iframe=e,this.mode=t,this.loader=a,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,a){window.parent.postMessage({...t,type:e},a)}static create(e){const{sessionToken:a,theme:r,setAsDefault:i,returnUrl:d,locale:l,onLoaded:c}=e,m=document.createElement("style");m.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===r?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===r?"#fff":"#000"};\n animation: ruba-loader-spinner-animation 1s infinite;\n }\n @keyframes ruba-loader-spinner-animation {\n 100% {box-shadow: 0 0 0 30px #0000}\n }\n body.ruba-no-scroll {\n overflow: hidden;\n }\n `,document.head.appendChild(m);const h=document.createElement("div");h.style.position="absolute",h.style.top="50%",h.style.left="50%",h.style.transform="translate(-50%, -50%)",h.style.zIndex="2147483647",h.style.colorScheme="auto";const u=document.createElement("div");u.className="ruba-loader-spinner",h.appendChild(u),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(h);const b=new URL(t,n());b.searchParams.set("session_token",a),b.searchParams.set("embed","true"),b.searchParams.set("embed_origin",window.location.origin),b.searchParams.set("mode","modal"),b.searchParams.set("embed_return_url",d??window.location.href),r&&b.searchParams.set("theme",r),!1===i&&b.searchParams.set("set_default","false"),l&&b.searchParams.set("locale",l);const w=document.createElement("iframe");w.src=b.toString(),w.style.position="fixed",w.style.top="0",w.style.left="0",w.style.width="100%",w.style.height="100%",w.style.border="none",w.style.zIndex="2147483647",w.style.backgroundColor="rgba(0, 0, 0, 0.5)",w.style.colorScheme="auto",w.allow=s(),document.body.appendChild(w);const p=new o(w,"modal",h);return c&&p.addEventListener("loaded",c,{once:!0}),new Promise(e=>{p.addEventListener("loaded",()=>e(p),{once:!0})})}static createInline(e){const{sessionToken:a,element:r,theme:i,setAsDefault:d,locale:l,onLoaded:c}=e,m=new URL(t,n());m.searchParams.set("session_token",a),m.searchParams.set("embed","true"),m.searchParams.set("embed_origin",window.location.origin),m.searchParams.set("mode","inline"),i&&m.searchParams.set("theme",i),!1===d&&m.searchParams.set("set_default","false"),l&&m.searchParams.set("locale",l);const h=document.createElement("iframe");h.src=m.toString(),h.style.display="block",h.style.width="100%",h.style.height="0",h.style.border="none",h.style.colorScheme="auto",h.allow=s(),r.replaceChildren(h);const u=new o(h,"inline",null);return c&&u.addEventListener("loaded",c,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(e=>{e.removeEventListener("click",o.elementClickHandler),e.addEventListener("click",o.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(a);if("succeeded"!==t&&"failed"!==t)return null;e.delete(a);const n=e.toString();return window.history.replaceState({},"",`${window.location.pathname}${n?`?${n}`:""}${window.location.hash}`),{status:t}}close(){window.removeEventListener("message",this.windowMessageListener),this.iframe.remove(),"modal"===this.mode&&document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,a){this.eventTarget.addEventListener(e,t,a)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(e){e.preventDefault();let t=e.target;for(;!t.hasAttribute("data-ruba-payment-method");){if(!t.parentElement)return;t=t.parentElement}const a=t.getAttribute("data-ruba-payment-method");if(!a)return;const n=t.getAttribute("data-ruba-payment-method-theme"),s=t.getAttribute("data-ruba-payment-method-set-as-default"),r=t.getAttribute("data-ruba-payment-method-return-url"),i=t.getAttribute("data-ruba-payment-method-locale");o.create({sessionToken:a,theme:n??void 0,setAsDefault:null===s?void 0:"false"!==s,returnUrl:r??void 0,locale:i??void 0})}handleLoaded(){this.loaded||(this.loader&&document.body.contains(this.loader)&&document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(){"inline"!==this.mode&&(this.closable=!0,this.close())}handleError(){this.closable=!0}handleWindowMessage({data:t,origin:a}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(a))return;if(t.type!==e)return;if("resize"===t.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(t.height))}px`));const n=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(t.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess();break;case"error":this.handleError()}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedPaymentMethod:o}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{o.init()})}export{a as REDIRECT_STATUS_PARAM,o as EmbedPaymentMethod};
@@ -0,0 +1 @@
1
+ var g=Object.create;var f=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.getPrototypeOf,k=Object.prototype.hasOwnProperty;var m=(b,a)=>()=>(a||b((a={exports:{}}).exports,a),a.exports);var l=(b,a,c,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!k.call(b,d)&&d!==c&&f(b,d,{get:()=>a[d],enumerable:!(e=h(a,d))||e.enumerable});return b};var n=(b,a,c)=>(c=b!=null?g(j(b)):{},l(a||!b||!b.__esModule?f(c,"default",{value:b,enumerable:!0}):c,b));export{m as a,n as b};