@getruba/checkout 0.3.0 → 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.
package/dist/embed.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})})(o,{RubaEmbedCheckout:()=>i}),module.exports=(e=o,((e,o,r,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let d of a(o))s.call(e,d)||d===r||t(e,d,{get:()=>o[d],enumerable:!(i=n(o,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r="RUBA_CHECKOUT",i=class e{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:r},t)}static async create(t,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const a=document.createElement("style");a.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(a);const s=document.createElement("div");s.style.position="absolute",s.style.top="50%",s.style.left="50%",s.style.transform="translate(-50%, -50%)",s.style.zIndex="2147483647",s.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",s.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(s);const r=new URL(t);r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),n?.theme&&r.searchParams.set("theme",n.theme);const i=r.toString(),d=document.createElement("iframe");d.src=i,d.style.position="fixed",d.style.top="0",d.style.left="0",d.style.width="100%",d.style.height="100%",d.style.border="none",d.style.zIndex="2147483647",d.style.backgroundColor="rgba(0, 0, 0, 0.5)",d.style.colorScheme="auto";const c="http://127.0.0.1:3000".split(",").join(" ");d.allow=`payment 'self' ${c}; publickey-credentials-get 'self' ${c};`,document.body.appendChild(d);const l=new e(d,s);return n?.onLoaded&&l.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{l.addEventListener("loaded",()=>e(l),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(t=>{t.removeEventListener("click",e.checkoutElementClickHandler),t.addEventListener("click",e.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),s=n.getAttribute("data-ruba-checkout-theme");e.create(a,s?{theme:s}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:e,origin:t}){if(!"http://127.0.0.1:3000".split(",").includes(t))return;if(e.type!==r)return;const n=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(e.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(e)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:i}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{i.init()})}
1
+ "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})})(o,{RubaEmbedCheckout:()=>d}),module.exports=(e=o,((e,o,r,d)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let i of a(o))s.call(e,i)||i===r||t(e,i,{get:()=>o[i],enumerable:!(d=n(o,i))||d.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r="RUBA_CHECKOUT",d=class e{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:r},t)}static async create(t,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const a=document.createElement("style");a.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(a);const s=document.createElement("div");s.style.position="absolute",s.style.top="50%",s.style.left="50%",s.style.transform="translate(-50%, -50%)",s.style.zIndex="2147483647",s.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",s.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(s);const r=new URL(t);r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),n?.theme&&r.searchParams.set("theme",n.theme);const d=r.toString(),i=document.createElement("iframe");i.src=d,i.style.position="fixed",i.style.top="0",i.style.left="0",i.style.width="100%",i.style.height="100%",i.style.border="none",i.style.zIndex="2147483647",i.style.backgroundColor="rgba(0, 0, 0, 0.5)",i.style.colorScheme="auto";const c="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");i.allow=`payment 'self' ${c}; publickey-credentials-get 'self' ${c};`,document.body.appendChild(i);const l=new e(i,s);return n?.onLoaded&&l.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{l.addEventListener("loaded",()=>e(l),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(t=>{t.removeEventListener("click",e.checkoutElementClickHandler),t.addEventListener("click",e.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),s=n.getAttribute("data-ruba-checkout-theme");e.create(a,s?{theme:s}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:e,origin:t}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(t))return;if(e.type!==r)return;const n=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(e.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(e)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:d}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{d.init()})}
@@ -1 +1 @@
1
- "use strict";(()=>{var e="RUBA_CHECKOUT",t=class t{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,n){window.parent.postMessage({...t,type:e},n)}static async create(e,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const a=document.createElement("style");a.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(a);const s=document.createElement("div");s.style.position="absolute",s.style.top="50%",s.style.left="50%",s.style.transform="translate(-50%, -50%)",s.style.zIndex="2147483647",s.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",s.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(s);const i=new URL(e);i.searchParams.set("embed","true"),i.searchParams.set("embed_origin",window.location.origin),n?.theme&&i.searchParams.set("theme",n.theme);const r=i.toString(),d=document.createElement("iframe");d.src=r,d.style.position="fixed",d.style.top="0",d.style.left="0",d.style.width="100%",d.style.height="100%",d.style.border="none",d.style.zIndex="2147483647",d.style.backgroundColor="rgba(0, 0, 0, 0.5)",d.style.colorScheme="auto";const l="http://127.0.0.1:3000".split(",").join(" ");d.allow=`payment 'self' ${l}; publickey-credentials-get 'self' ${l};`,document.body.appendChild(d);const c=new t(d,s);return n?.onLoaded&&c.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{c.addEventListener("loaded",()=>e(c),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(e=>{e.removeEventListener("click",t.checkoutElementClickHandler),e.addEventListener("click",t.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(e){e.preventDefault();let n=e.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),s=n.getAttribute("data-ruba-checkout-theme");t.create(a,s?{theme:s}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:t,origin:n}){if(!"http://127.0.0.1:3000".split(",").includes(n))return;if(t.type!==e)return;const a=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.defaultPrevented)switch(t.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(t)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:t}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{t.init()})}var n="RUBA_PAYMENT_METHOD",a="/embed/payment-method",s="ruba_payment_method_status",o=()=>{const e="http://127.0.0.1:3000".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},i=()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},r=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:n},t)}static create(t){const{sessionToken:n,theme:s,setAsDefault:r,returnUrl:d,locale:l,onLoaded:c}=t,h=document.createElement("style");h.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===s?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===s?"#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(h);const m=document.createElement("div");m.style.position="absolute",m.style.top="50%",m.style.left="50%",m.style.transform="translate(-50%, -50%)",m.style.zIndex="2147483647",m.style.colorScheme="auto";const u=document.createElement("div");u.className="ruba-loader-spinner",m.appendChild(u),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(m);const b=new URL(a,o());b.searchParams.set("session_token",n),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),s&&b.searchParams.set("theme",s),!1===r&&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=i(),document.body.appendChild(w);const f=new e(w,"modal",m);return c&&f.addEventListener("loaded",c,{once:!0}),new Promise(e=>{f.addEventListener("loaded",()=>e(f),{once:!0})})}static createInline(t){const{sessionToken:n,element:s,theme:r,setAsDefault:d,locale:l,onLoaded:c}=t,h=new URL(a,o());h.searchParams.set("session_token",n),h.searchParams.set("embed","true"),h.searchParams.set("embed_origin",window.location.origin),h.searchParams.set("mode","inline"),r&&h.searchParams.set("theme",r),!1===d&&h.searchParams.set("set_default","false"),l&&h.searchParams.set("locale",l);const m=document.createElement("iframe");m.src=h.toString(),m.style.display="block",m.style.width="100%",m.style.height="0",m.style.border="none",m.style.colorScheme="auto",m.allow=i(),s.replaceChildren(m);const u=new e(m,"inline",null);return c&&u.addEventListener("loaded",c,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(s);if("succeeded"!==t&&"failed"!==t)return null;e.delete(s);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,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-payment-method");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("data-ruba-payment-method");if(!a)return;const s=n.getAttribute("data-ruba-payment-method-theme"),o=n.getAttribute("data-ruba-payment-method-set-as-default"),i=n.getAttribute("data-ruba-payment-method-return-url"),r=n.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:a,theme:s??void 0,setAsDefault:null===o?void 0:"false"!==o,returnUrl:i??void 0,locale:r??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:e,origin:t}){if(!"http://127.0.0.1:3000".split(",").includes(t))return;if(e.type!==n)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const a=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.defaultPrevented)switch(e.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:r}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{r.init()})}})();
1
+ "use strict";(()=>{var e="RUBA_CHECKOUT",t=class t{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,n){window.parent.postMessage({...t,type:e},n)}static async create(e,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const a=document.createElement("style");a.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(a);const s=document.createElement("div");s.style.position="absolute",s.style.top="50%",s.style.left="50%",s.style.transform="translate(-50%, -50%)",s.style.zIndex="2147483647",s.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",s.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(s);const r=new URL(e);r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),n?.theme&&r.searchParams.set("theme",n.theme);const i=r.toString(),d=document.createElement("iframe");d.src=i,d.style.position="fixed",d.style.top="0",d.style.left="0",d.style.width="100%",d.style.height="100%",d.style.border="none",d.style.zIndex="2147483647",d.style.backgroundColor="rgba(0, 0, 0, 0.5)",d.style.colorScheme="auto";const l="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");d.allow=`payment 'self' ${l}; publickey-credentials-get 'self' ${l};`,document.body.appendChild(d);const c=new t(d,s);return n?.onLoaded&&c.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{c.addEventListener("loaded",()=>e(c),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(e=>{e.removeEventListener("click",t.checkoutElementClickHandler),e.addEventListener("click",t.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(e){e.preventDefault();let n=e.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),s=n.getAttribute("data-ruba-checkout-theme");t.create(a,s?{theme:s}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:t,origin:n}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(n))return;if(t.type!==e)return;const a=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.defaultPrevented)switch(t.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(t)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:t}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{t.init()})}var n="RUBA_PAYMENT_METHOD",a="/embed/payment-method",s="ruba_payment_method_status",o=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},r=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},i=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:n},t)}static create(t){const{sessionToken:n,theme:s,setAsDefault:i,returnUrl:d,locale:l,onLoaded:c}=t,h=document.createElement("style");h.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===s?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===s?"#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(h);const m=document.createElement("div");m.style.position="absolute",m.style.top="50%",m.style.left="50%",m.style.transform="translate(-50%, -50%)",m.style.zIndex="2147483647",m.style.colorScheme="auto";const u=document.createElement("div");u.className="ruba-loader-spinner",m.appendChild(u),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(m);const b=new URL(a,o());b.searchParams.set("session_token",n),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),s&&b.searchParams.set("theme",s),!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=r(),document.body.appendChild(w);const p=new e(w,"modal",m);return c&&p.addEventListener("loaded",c,{once:!0}),new Promise(e=>{p.addEventListener("loaded",()=>e(p),{once:!0})})}static createInline(t){const{sessionToken:n,element:s,theme:i,setAsDefault:d,locale:l,onLoaded:c}=t,h=new URL(a,o());h.searchParams.set("session_token",n),h.searchParams.set("embed","true"),h.searchParams.set("embed_origin",window.location.origin),h.searchParams.set("mode","inline"),i&&h.searchParams.set("theme",i),!1===d&&h.searchParams.set("set_default","false"),l&&h.searchParams.set("locale",l);const m=document.createElement("iframe");m.src=h.toString(),m.style.display="block",m.style.width="100%",m.style.height="0",m.style.border="none",m.style.colorScheme="auto",m.allow=r(),s.replaceChildren(m);const u=new e(m,"inline",null);return c&&u.addEventListener("loaded",c,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(s);if("succeeded"!==t&&"failed"!==t)return null;e.delete(s);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,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-payment-method");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("data-ruba-payment-method");if(!a)return;const s=n.getAttribute("data-ruba-payment-method-theme"),o=n.getAttribute("data-ruba-payment-method-set-as-default"),r=n.getAttribute("data-ruba-payment-method-return-url"),i=n.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:a,theme:s??void 0,setAsDefault:null===o?void 0:"false"!==o,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:e,origin:t}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(t))return;if(e.type!==n)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const a=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.defaultPrevented)switch(e.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:i}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{i.init()})}})();
package/dist/embed.js CHANGED
@@ -1 +1 @@
1
- var e="RUBA_CHECKOUT",t=class t{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,n){window.parent.postMessage({...t,type:e},n)}static async create(e,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const s=document.createElement("style");s.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(s);const a=document.createElement("div");a.style.position="absolute",a.style.top="50%",a.style.left="50%",a.style.transform="translate(-50%, -50%)",a.style.zIndex="2147483647",a.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",a.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(a);const d=new URL(e);d.searchParams.set("embed","true"),d.searchParams.set("embed_origin",window.location.origin),n?.theme&&d.searchParams.set("theme",n.theme);const i=d.toString(),r=document.createElement("iframe");r.src=i,r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",r.style.border="none",r.style.zIndex="2147483647",r.style.backgroundColor="rgba(0, 0, 0, 0.5)",r.style.colorScheme="auto";const c="http://127.0.0.1:3000".split(",").join(" ");r.allow=`payment 'self' ${c}; publickey-credentials-get 'self' ${c};`,document.body.appendChild(r);const l=new t(r,a);return n?.onLoaded&&l.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{l.addEventListener("loaded",()=>e(l),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(e=>{e.removeEventListener("click",t.checkoutElementClickHandler),e.addEventListener("click",t.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(e){e.preventDefault();let n=e.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const s=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),a=n.getAttribute("data-ruba-checkout-theme");t.create(s,a?{theme:a}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:t,origin:n}){if(!"http://127.0.0.1:3000".split(",").includes(n))return;if(t.type!==e)return;const s=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(s),!s.defaultPrevented)switch(t.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(t)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:t}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{t.init()})}export{t as RubaEmbedCheckout};
1
+ var e="RUBA_CHECKOUT",t=class t{iframe;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t){this.iframe=e,this.loader=t,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,n){window.parent.postMessage({...t,type:e},n)}static async create(e,n){"string"==typeof n&&(console.warn(`Passing theme as string is deprecated. Use { theme: "${n}" } instead.`),n={theme:n});const s=document.createElement("style");s.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?.theme?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?.theme?"#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(s);const a=document.createElement("div");a.style.position="absolute",a.style.top="50%",a.style.left="50%",a.style.transform="translate(-50%, -50%)",a.style.zIndex="2147483647",a.style.colorScheme="auto";const o=document.createElement("div");o.className="ruba-loader-spinner",a.appendChild(o),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(a);const d=new URL(e);d.searchParams.set("embed","true"),d.searchParams.set("embed_origin",window.location.origin),n?.theme&&d.searchParams.set("theme",n.theme);const i=d.toString(),r=document.createElement("iframe");r.src=i,r.style.position="fixed",r.style.top="0",r.style.left="0",r.style.width="100%",r.style.height="100%",r.style.border="none",r.style.zIndex="2147483647",r.style.backgroundColor="rgba(0, 0, 0, 0.5)",r.style.colorScheme="auto";const c="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");r.allow=`payment 'self' ${c}; publickey-credentials-get 'self' ${c};`,document.body.appendChild(r);const l=new t(r,a);return n?.onLoaded&&l.addEventListener("loaded",n.onLoaded,{once:!0}),new Promise(e=>{l.addEventListener("loaded",()=>e(l),{once:!0})})}static init(){document.querySelectorAll("[data-ruba-checkout]").forEach(e=>{e.removeEventListener("click",t.checkoutElementClickHandler),e.addEventListener("click",t.checkoutElementClickHandler)})}close(){window.removeEventListener("message",this.windowMessageListener),document.body.contains(this.iframe)&&document.body.removeChild(this.iframe),document.body.classList.remove("ruba-no-scroll")}addEventListener(e,t,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async checkoutElementClickHandler(e){e.preventDefault();let n=e.target;for(;!n.hasAttribute("data-ruba-checkout");){if(!n.parentElement)return;n=n.parentElement}const s=n.getAttribute("href")||n.getAttribute("data-ruba-checkout"),a=n.getAttribute("data-ruba-checkout-theme");t.create(s,a?{theme:a}:void 0)}handleLoaded(){this.loaded||(document.body.removeChild(this.loader),this.loaded=!0)}handleClose(){this.closable&&this.close()}handleConfirmed(){this.closable=!1}handleSuccess(e){this.closable=!0,e.redirect&&(window.location.href=e.successURL)}handleWindowMessage({data:t,origin:n}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(n))return;if(t.type!==e)return;const s=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(s),!s.defaultPrevented)switch(t.event){case"loaded":this.handleLoaded();break;case"close":this.handleClose();break;case"confirmed":this.handleConfirmed();break;case"success":this.handleSuccess(t)}}};if("undefined"!=typeof window&&(window.Ruba={...window.Ruba??{},EmbedCheckout:t}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",async()=>{t.init()})}export{t as RubaEmbedCheckout};
package/dist/guards.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as schemas } from './index.d-DvLuMU7T.cjs';
1
+ import { s as schemas } from './index.d-DPYkwmIv.cjs';
2
2
  import 'openapi-fetch';
3
3
 
4
4
  interface ProductCheckoutMixin {
package/dist/guards.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { s as schemas } from './index.d-DvLuMU7T.js';
1
+ import { s as schemas } from './index.d-DPYkwmIv.js';
2
2
  import 'openapi-fetch';
3
3
 
4
4
  interface ProductCheckoutMixin {
package/dist/guards.js CHANGED
@@ -1 +1 @@
1
- import{a,b,c,d}from"./chunk-GBQE5XCD.js";import"./chunk-ZWRDP37E.js";export{d as getFixedPrice,c as getSeatPrice,a as hasProductCheckout,b as isLegacyRecurringProductPrice};
1
+ import{a,b,c,d}from"./chunk-GBQE5XCD.js";import"./chunk-EK7ODJWE.js";export{d as getFixedPrice,c as getSeatPrice,a as hasProductCheckout,b as isLegacyRecurringProductPrice};
@@ -1,4 +1,4 @@
1
- import { C as Client, s as schemas } from '../index.d-DvLuMU7T.cjs';
1
+ import { C as Client, s as schemas } from '../index.d-DPYkwmIv.cjs';
2
2
  import 'openapi-fetch';
3
3
 
4
4
  declare const useCheckoutFulfillmentListener: (client: Client, checkout: schemas["CheckoutPublic"], maxWaitingTimeMs?: number) => [() => Promise<void>, string | null];
@@ -1,4 +1,4 @@
1
- import { C as Client, s as schemas } from '../index.d-DvLuMU7T.js';
1
+ import { C as Client, s as schemas } from '../index.d-DPYkwmIv.js';
2
2
  import 'openapi-fetch';
3
3
 
4
4
  declare const useCheckoutFulfillmentListener: (client: Client, checkout: schemas["CheckoutPublic"], maxWaitingTimeMs?: number) => [() => Promise<void>, string | null];
@@ -1 +1 @@
1
- "use client";import{a as S,b as P}from"../chunk-GBQE5XCD.js";import{b as D,c as H}from"../chunk-ZWRDP37E.js";var A=D((q,E)=>{"use strict";var R=Object.prototype.hasOwnProperty,a="~";function m(){}Object.create&&(m.prototype=Object.create(null),new m().__proto__||(a=!1));function T(s,e,t){this.fn=s,this.context=e,this.once=t||!1}function O(s,e,t,r,u){if(typeof t!="function")throw new TypeError("The listener must be a function");var c=new T(t,r||s,u),o=a?a+e:e;return s._events[o]?s._events[o].fn?s._events[o]=[s._events[o],c]:s._events[o].push(c):(s._events[o]=c,s._eventsCount++),s}function b(s,e){--s._eventsCount===0?s._events=new m:delete s._events[e]}function f(){this._events=new m,this._eventsCount=0}f.prototype.eventNames=function(){var e=[],t,r;if(this._eventsCount===0)return e;for(r in t=this._events)R.call(t,r)&&e.push(a?r.slice(1):r);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};f.prototype.listeners=function(e){var t=a?a+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var u=0,c=r.length,o=new Array(c);u<c;u++)o[u]=r[u].fn;return o};f.prototype.listenerCount=function(e){var t=a?a+e:e,r=this._events[t];return r?r.fn?1:r.length:0};f.prototype.emit=function(e,t,r,u,c,o){var p=a?a+e:e;if(!this._events[p])return!1;var n=this._events[p],l=arguments.length,h,i;if(n.fn){switch(n.once&&this.removeListener(e,n.fn,void 0,!0),l){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,t),!0;case 3:return n.fn.call(n.context,t,r),!0;case 4:return n.fn.call(n.context,t,r,u),!0;case 5:return n.fn.call(n.context,t,r,u,c),!0;case 6:return n.fn.call(n.context,t,r,u,c,o),!0}for(i=1,h=new Array(l-1);i<l;i++)h[i-1]=arguments[i];n.fn.apply(n.context,h)}else{var d=n.length,v;for(i=0;i<d;i++)switch(n[i].once&&this.removeListener(e,n[i].fn,void 0,!0),l){case 1:n[i].fn.call(n[i].context);break;case 2:n[i].fn.call(n[i].context,t);break;case 3:n[i].fn.call(n[i].context,t,r);break;case 4:n[i].fn.call(n[i].context,t,r,u);break;default:if(!h)for(v=1,h=new Array(l-1);v<l;v++)h[v-1]=arguments[v];n[i].fn.apply(n[i].context,h)}}return!0};f.prototype.on=function(e,t,r){return O(this,e,t,r,!1)};f.prototype.once=function(e,t,r){return O(this,e,t,r,!0)};f.prototype.removeListener=function(e,t,r,u){var c=a?a+e:e;if(!this._events[c])return this;if(!t)return b(this,c),this;var o=this._events[c];if(o.fn)o.fn===t&&(!u||o.once)&&(!r||o.context===r)&&b(this,c);else{for(var p=0,n=[],l=o.length;p<l;p++)(o[p].fn!==t||u&&!o[p].once||r&&o[p].context!==r)&&n.push(o[p]);n.length?this._events[c]=n.length===1?n[0]:n:b(this,c)}return this};f.prototype.removeAllListeners=function(e){var t;return e?(t=a?a+e:e,this._events[t]&&b(this,t)):(this._events=new m,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=a;f.EventEmitter=f;typeof E<"u"&&(E.exports=f)});import{useCallback as j,useState as z}from"react";import{EventSourcePlus as U}from"event-source-plus";var F=H(A(),1);var N=F.default;var $=s=>{let e=new N,t=new U(s,{credentials:"include"}),r={onMessage:async c=>{let o=JSON.parse(c.data);o.type!=="reconnect"&&e.emit(o.key,o.payload)}};return[e,()=>t.listen(r)]};var J=(s,e,t=15e3)=>{let[r,u]=z(null);return[j(async()=>await new Promise((o,p)=>{let n=`${s.baseUrl}/v1/checkouts/client/${e.client_secret}/stream`,[l,h]=$(n),i=h(),d=!1,v=!1,_=!S(e)||!P(e.product_price),w=!1,y=()=>{d&&v&&_&&u(`Waiting confirmation from ${e.organization.name} `),d&&v&&_&&w&&(i.abort(),o())},C=k=>{k.status==="succeeded"&&(d=!0,u("Payment successful! Processing order..."),l.off("checkout.updated",C),y())};l.on("checkout.updated",C);let L=()=>{v=!0,l.off("checkout.order_created",L),y()};l.on("checkout.order_created",L);let g=()=>{_=!0,l.off("checkout.subscription_created",g),y()};_||l.on("checkout.subscription_created",g);let x=k=>{k.status==="succeeded"&&(w=!0,l.off("checkout.webhook_event_delivered",x),y())};l.on("checkout.webhook_event_delivered",x),setTimeout(()=>{i.abort(),p()},t)}),[s,e,t]),r]};export{J as useCheckoutFulfillmentListener};
1
+ "use client";import{a as S,b as P}from"../chunk-GBQE5XCD.js";import{a as D,b as H}from"../chunk-EK7ODJWE.js";var A=D((q,E)=>{"use strict";var R=Object.prototype.hasOwnProperty,a="~";function m(){}Object.create&&(m.prototype=Object.create(null),new m().__proto__||(a=!1));function T(s,e,t){this.fn=s,this.context=e,this.once=t||!1}function O(s,e,t,r,u){if(typeof t!="function")throw new TypeError("The listener must be a function");var c=new T(t,r||s,u),o=a?a+e:e;return s._events[o]?s._events[o].fn?s._events[o]=[s._events[o],c]:s._events[o].push(c):(s._events[o]=c,s._eventsCount++),s}function b(s,e){--s._eventsCount===0?s._events=new m:delete s._events[e]}function f(){this._events=new m,this._eventsCount=0}f.prototype.eventNames=function(){var e=[],t,r;if(this._eventsCount===0)return e;for(r in t=this._events)R.call(t,r)&&e.push(a?r.slice(1):r);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};f.prototype.listeners=function(e){var t=a?a+e:e,r=this._events[t];if(!r)return[];if(r.fn)return[r.fn];for(var u=0,c=r.length,o=new Array(c);u<c;u++)o[u]=r[u].fn;return o};f.prototype.listenerCount=function(e){var t=a?a+e:e,r=this._events[t];return r?r.fn?1:r.length:0};f.prototype.emit=function(e,t,r,u,c,o){var p=a?a+e:e;if(!this._events[p])return!1;var n=this._events[p],l=arguments.length,h,i;if(n.fn){switch(n.once&&this.removeListener(e,n.fn,void 0,!0),l){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,t),!0;case 3:return n.fn.call(n.context,t,r),!0;case 4:return n.fn.call(n.context,t,r,u),!0;case 5:return n.fn.call(n.context,t,r,u,c),!0;case 6:return n.fn.call(n.context,t,r,u,c,o),!0}for(i=1,h=new Array(l-1);i<l;i++)h[i-1]=arguments[i];n.fn.apply(n.context,h)}else{var d=n.length,v;for(i=0;i<d;i++)switch(n[i].once&&this.removeListener(e,n[i].fn,void 0,!0),l){case 1:n[i].fn.call(n[i].context);break;case 2:n[i].fn.call(n[i].context,t);break;case 3:n[i].fn.call(n[i].context,t,r);break;case 4:n[i].fn.call(n[i].context,t,r,u);break;default:if(!h)for(v=1,h=new Array(l-1);v<l;v++)h[v-1]=arguments[v];n[i].fn.apply(n[i].context,h)}}return!0};f.prototype.on=function(e,t,r){return O(this,e,t,r,!1)};f.prototype.once=function(e,t,r){return O(this,e,t,r,!0)};f.prototype.removeListener=function(e,t,r,u){var c=a?a+e:e;if(!this._events[c])return this;if(!t)return b(this,c),this;var o=this._events[c];if(o.fn)o.fn===t&&(!u||o.once)&&(!r||o.context===r)&&b(this,c);else{for(var p=0,n=[],l=o.length;p<l;p++)(o[p].fn!==t||u&&!o[p].once||r&&o[p].context!==r)&&n.push(o[p]);n.length?this._events[c]=n.length===1?n[0]:n:b(this,c)}return this};f.prototype.removeAllListeners=function(e){var t;return e?(t=a?a+e:e,this._events[t]&&b(this,t)):(this._events=new m,this._eventsCount=0),this};f.prototype.off=f.prototype.removeListener;f.prototype.addListener=f.prototype.on;f.prefixed=a;f.EventEmitter=f;typeof E<"u"&&(E.exports=f)});import{useCallback as j,useState as z}from"react";import{EventSourcePlus as U}from"event-source-plus";var F=H(A(),1);var N=F.default;var $=s=>{let e=new N,t=new U(s,{credentials:"include"}),r={onMessage:async c=>{let o=JSON.parse(c.data);o.type!=="reconnect"&&e.emit(o.key,o.payload)}};return[e,()=>t.listen(r)]};var J=(s,e,t=15e3)=>{let[r,u]=z(null);return[j(async()=>await new Promise((o,p)=>{let n=`${s.baseUrl}/v1/checkouts/client/${e.client_secret}/stream`,[l,h]=$(n),i=h(),d=!1,v=!1,_=!S(e)||!P(e.product_price),w=!1,y=()=>{d&&v&&_&&u(`Waiting confirmation from ${e.organization.name} `),d&&v&&_&&w&&(i.abort(),o())},C=k=>{k.status==="succeeded"&&(d=!0,u("Payment successful! Processing order..."),l.off("checkout.updated",C),y())};l.on("checkout.updated",C);let L=()=>{v=!0,l.off("checkout.order_created",L),y()};l.on("checkout.order_created",L);let g=()=>{_=!0,l.off("checkout.subscription_created",g),y()};_||l.on("checkout.subscription_created",g);let x=k=>{k.status==="succeeded"&&(w=!0,l.off("checkout.webhook_event_delivered",x),y())};l.on("checkout.webhook_event_delivered",x),setTimeout(()=>{i.abort(),p()},t)}),[s,e,t]),r]};export{J as useCheckoutFulfillmentListener};
@@ -9157,7 +9157,7 @@ interface components {
9157
9157
 
9158
9158
  position: number;
9159
9159
 
9160
- is_polar_bot: boolean;
9160
+ is_ruba_bot: boolean;
9161
9161
 
9162
9162
  color: string;
9163
9163
  };
@@ -13209,9 +13209,9 @@ interface components {
13209
13209
 
13210
13210
  PledgeState: 'initiated' | 'created' | 'pending' | 'refunded' | 'disputed' | 'charge_disputed' | 'cancelled';
13211
13211
 
13212
- PolarSelfPaymentMethodInUse: {
13212
+ RubaSelfPaymentMethodInUse: {
13213
13213
 
13214
- error: 'PolarSelfPaymentMethodInUse';
13214
+ error: 'RubaSelfPaymentMethodInUse';
13215
13215
 
13216
13216
  detail: string;
13217
13217
  };
@@ -18551,7 +18551,7 @@ interface operations {
18551
18551
  [name: string]: unknown;
18552
18552
  };
18553
18553
  content: {
18554
- 'application/json': components['schemas']['PolarSelfPaymentMethodInUse'];
18554
+ 'application/json': components['schemas']['RubaSelfPaymentMethodInUse'];
18555
18555
  };
18556
18556
  };
18557
18557
 
@@ -9157,7 +9157,7 @@ interface components {
9157
9157
 
9158
9158
  position: number;
9159
9159
 
9160
- is_polar_bot: boolean;
9160
+ is_ruba_bot: boolean;
9161
9161
 
9162
9162
  color: string;
9163
9163
  };
@@ -13209,9 +13209,9 @@ interface components {
13209
13209
 
13210
13210
  PledgeState: 'initiated' | 'created' | 'pending' | 'refunded' | 'disputed' | 'charge_disputed' | 'cancelled';
13211
13211
 
13212
- PolarSelfPaymentMethodInUse: {
13212
+ RubaSelfPaymentMethodInUse: {
13213
13213
 
13214
- error: 'PolarSelfPaymentMethodInUse';
13214
+ error: 'RubaSelfPaymentMethodInUse';
13215
13215
 
13216
13216
  detail: string;
13217
13217
  };
@@ -18551,7 +18551,7 @@ interface operations {
18551
18551
  [name: string]: unknown;
18552
18552
  };
18553
18553
  content: {
18554
- 'application/json': components['schemas']['PolarSelfPaymentMethodInUse'];
18554
+ 'application/json': components['schemas']['RubaSelfPaymentMethodInUse'];
18555
18555
  };
18556
18556
  };
18557
18557
 
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,a=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})})(o,{EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM:()=>d,RubaEmbedPaymentMethod:()=>m}),module.exports=(e=o,((e,o,r,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let d of a(o))s.call(e,d)||d===r||t(e,d,{get:()=>o[d],enumerable:!(i=n(o,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r="RUBA_PAYMENT_METHOD",i="/embed/payment-method",d="ruba_payment_method_status",l=()=>{const e="http://127.0.0.1:3000".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},c=()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},m=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:r},t)}static create(t){const{sessionToken:n,theme:a,setAsDefault:s,returnUrl:o,locale:r,onLoaded:d}=t,m=document.createElement("style");m.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===a?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===a?"#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(i,l());b.searchParams.set("session_token",n),b.searchParams.set("embed","true"),b.searchParams.set("embed_origin",window.location.origin),b.searchParams.set("mode","modal"),b.searchParams.set("embed_return_url",o??window.location.href),a&&b.searchParams.set("theme",a),!1===s&&b.searchParams.set("set_default","false"),r&&b.searchParams.set("locale",r);const p=document.createElement("iframe");p.src=b.toString(),p.style.position="fixed",p.style.top="0",p.style.left="0",p.style.width="100%",p.style.height="100%",p.style.border="none",p.style.zIndex="2147483647",p.style.backgroundColor="rgba(0, 0, 0, 0.5)",p.style.colorScheme="auto",p.allow=c(),document.body.appendChild(p);const f=new e(p,"modal",h);return d&&f.addEventListener("loaded",d,{once:!0}),new Promise(e=>{f.addEventListener("loaded",()=>e(f),{once:!0})})}static createInline(t){const{sessionToken:n,element:a,theme:s,setAsDefault:o,locale:r,onLoaded:d}=t,m=new URL(i,l());m.searchParams.set("session_token",n),m.searchParams.set("embed","true"),m.searchParams.set("embed_origin",window.location.origin),m.searchParams.set("mode","inline"),s&&m.searchParams.set("theme",s),!1===o&&m.searchParams.set("set_default","false"),r&&m.searchParams.set("locale",r);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=c(),a.replaceChildren(h);const u=new e(h,"inline",null);return d&&u.addEventListener("loaded",d,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(d);if("succeeded"!==t&&"failed"!==t)return null;e.delete(d);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,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-payment-method");){if(!n.parentElement)return;n=n.parentElement}const a=n.getAttribute("data-ruba-payment-method");if(!a)return;const s=n.getAttribute("data-ruba-payment-method-theme"),o=n.getAttribute("data-ruba-payment-method-set-as-default"),r=n.getAttribute("data-ruba-payment-method-return-url"),i=n.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:a,theme:s??void 0,setAsDefault:null===o?void 0:"false"!==o,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:e,origin:t}){if(!"http://127.0.0.1:3000".split(",").includes(t))return;if(e.type!==r)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const n=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(e.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:m}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{m.init()})}
1
+ "use strict";var e,t=Object.defineProperty,a=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,s=Object.prototype.hasOwnProperty,o={};((e,a)=>{for(var n in a)t(e,n,{get:a[n],enumerable:!0})})(o,{EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM:()=>d,RubaEmbedPaymentMethod:()=>m}),module.exports=(e=o,((e,o,r,i)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let d of n(o))s.call(e,d)||d===r||t(e,d,{get:()=>o[d],enumerable:!(i=a(o,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var r="RUBA_PAYMENT_METHOD",i="/embed/payment-method",d="ruba_payment_method_status",l=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},c=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},m=class e{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(e,t){window.parent.postMessage({...e,type:r},t)}static create(t){const{sessionToken:a,theme:n,setAsDefault:s,returnUrl:o,locale:r,onLoaded:d}=t,m=document.createElement("style");m.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?"#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(i,l());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",o??window.location.href),n&&b.searchParams.set("theme",n),!1===s&&b.searchParams.set("set_default","false"),r&&b.searchParams.set("locale",r);const p=document.createElement("iframe");p.src=b.toString(),p.style.position="fixed",p.style.top="0",p.style.left="0",p.style.width="100%",p.style.height="100%",p.style.border="none",p.style.zIndex="2147483647",p.style.backgroundColor="rgba(0, 0, 0, 0.5)",p.style.colorScheme="auto",p.allow=c(),document.body.appendChild(p);const f=new e(p,"modal",h);return d&&f.addEventListener("loaded",d,{once:!0}),new Promise(e=>{f.addEventListener("loaded",()=>e(f),{once:!0})})}static createInline(t){const{sessionToken:a,element:n,theme:s,setAsDefault:o,locale:r,onLoaded:d}=t,m=new URL(i,l());m.searchParams.set("session_token",a),m.searchParams.set("embed","true"),m.searchParams.set("embed_origin",window.location.origin),m.searchParams.set("mode","inline"),s&&m.searchParams.set("theme",s),!1===o&&m.searchParams.set("set_default","false"),r&&m.searchParams.set("locale",r);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=c(),n.replaceChildren(h);const u=new e(h,"inline",null);return d&&u.addEventListener("loaded",d,{once:!0}),u}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(d);if("succeeded"!==t&&"failed"!==t)return null;e.delete(d);const a=e.toString();return window.history.replaceState({},"",`${window.location.pathname}${a?`?${a}`:""}${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(t){t.preventDefault();let a=t.target;for(;!a.hasAttribute("data-ruba-payment-method");){if(!a.parentElement)return;a=a.parentElement}const n=a.getAttribute("data-ruba-payment-method");if(!n)return;const s=a.getAttribute("data-ruba-payment-method-theme"),o=a.getAttribute("data-ruba-payment-method-set-as-default"),r=a.getAttribute("data-ruba-payment-method-return-url"),i=a.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:n,theme:s??void 0,setAsDefault:null===o?void 0:"false"!==o,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:e,origin:t}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(t))return;if(e.type!==r)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const a=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.defaultPrevented)switch(e.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:m}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{m.init()})}
@@ -1 +1 @@
1
- import{EmbedPaymentMethod as E,REDIRECT_STATUS_PARAM as A}from"./chunk-FSZEYAE6.js";export{A as EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM,E as RubaEmbedPaymentMethod};
1
+ import{EmbedPaymentMethod as E,REDIRECT_STATUS_PARAM as T}from"./chunk-B7RTOVF6.js";export{T as EMBED_PAYMENT_METHOD_REDIRECT_STATUS_PARAM,E as RubaEmbedPaymentMethod};
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { s as schemas, o as operations, C as Client } from '../index.d-DvLuMU7T.cjs';
3
+ import { s as schemas, o as operations, C as Client } from '../index.d-DPYkwmIv.cjs';
4
4
  import { A } from './config-oYrbe6vX.js';
5
5
  import { Stripe, StripeElements } from '@stripe/stripe-js';
6
6
  import { UseFormReturn } from 'react-hook-form';
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import * as react from 'react';
3
- import { s as schemas, o as operations, C as Client } from '../index.d-DvLuMU7T.js';
3
+ import { s as schemas, o as operations, C as Client } from '../index.d-DPYkwmIv.js';
4
4
  import { A } from './config-oYrbe6vX.js';
5
5
  import { Stripe, StripeElements } from '@stripe/stripe-js';
6
6
  import { UseFormReturn } from 'react-hook-form';
@@ -1 +1 @@
1
- "use client";import{b as I,c as y,d as _,e as M,i as N,n as O}from"../chunk-TS7YIDY3.js";import"../chunk-ZWRDP37E.js";import{createContext as ee,useCallback as S,useContext as te,useState as A}from"react";var R=(r,u,e=1,s)=>{r.forEach(d=>{let o=d.loc.slice(e);s&&s.includes(o[0])&&(o=o.slice(1)),u(o.join("."),{type:d.type,message:d.msg})})};import{createContext as G,useCallback as v,useContext as W,useEffect as Y,useMemo as $,useState as D}from"react";import{jsx as Z}from"react/jsx-runtime";var j=async(r,u)=>{try{return{ok:!0,value:await _(r.GET("/v1/checkouts/client/{client_secret}",{params:{path:u}}))}}catch(e){return e instanceof y?{ok:!1,error:e.error}:{ok:!1,error:null}}},H=async(r,u,e)=>{try{return{ok:!0,value:await _(r.POST("/v1/checkouts/client/{client_secret}/confirm",{params:{path:u},body:e}))}}catch(s){return s instanceof y?{ok:!1,error:s.error}:{ok:!1,error:null}}},z=async(r,u,e)=>{try{return{ok:!0,value:await _(r.PATCH("/v1/checkouts/client/{client_secret}",{params:{path:u},body:e}))}}catch(s){return s instanceof y?{ok:!1,error:s.error}:{ok:!1,error:null}}},Q=()=>{throw new Error("You forgot to wrap your component in <CheckoutProvider>.")},T=G(Q),X=({clientSecret:r,initialCheckout:u,serverURL:e,server:s,children:d})=>{let o=$(()=>{let n=(()=>{if(e)return e.replace(/\/v1\/?$/,"");switch(s){case"sandbox":return"https://sandbox-api.getruba.com";case"production":case void 0:return"https://api.getruba.com";default:throw new Error(`Unknown server: '${s}'`)}})();return I(n)},[s,e]),[f,c]=D(u??null);Y(()=>{u||j(o,{client_secret:r}).then(n=>{n.ok&&c(n.value)}).catch(n=>{throw n})},[o,r,u]);let g=v(async()=>{let n=await j(o,{client_secret:r});return n.ok&&c(n.value),n},[o,r]),k=v(async n=>{let p=await z(o,{client_secret:r},n);return p.ok&&c(p.value),p},[o,r]),P=v(async n=>{let p=await H(o,{client_secret:r},n);return p.ok&&c(p.value),p},[o,r]);return f?Z(T.Provider,{value:{checkout:f,refresh:g,update:k,confirm:P,client:o},children:d}):null},F=()=>W(T);import{jsx as ne}from"react/jsx-runtime";var oe=()=>{throw new Error("You forgot to wrap your component in <CheckoutFormProvider>.")},U=ee(oe),re=({children:r,locale:u=M})=>{let{checkout:e,update:s,confirm:d}=F(),o=N(u),[f,c]=A(!1),[g,k]=A(),[P,n]=A(!1),p=O({defaultValues:{...e,customer_billing_address:e.customer_billing_address,discount_code:e.discount?e.discount.code:void 0,allow_trial:void 0},shouldUnregister:!0}),{setError:l}=p,E=S(async i=>{n(!0);let{ok:m,value:h,error:t}=await s(i).finally(()=>{n(!1)});if(m)return h;if(t){if(Array.isArray(t.detail))throw R(t.detail,l),t;switch(t.error){case"AlreadyActiveSubscriptionError":case"NotOpenCheckout":case"PaymentNotReady":l("root",{message:t.detail});break;case"ResourceNotFound":case"ExpiredCheckoutError":break}}throw t},[s,l]),b=S(async i=>{let{ok:m,value:h,error:t}=await d(i);if(m)return h;if(t){if(Array.isArray(t.detail))throw R(t.detail,l),t;switch(t.error){case"PaymentError":case"AlreadyActiveSubscriptionError":case"NotOpenCheckout":case"PaymentNotReady":l("root",{message:t.detail});break;case"TrialAlreadyRedeemed":l("root",{message:t.detail}),await E({allow_trial:!1});break;case"ResourceNotFound":case"ExpiredCheckoutError":break}}throw t},[d,l,E]),q=S(async(i,m,h)=>{if(c(!0),!e.is_payment_form_required){k(o("checkout.loading.processingOrder"));try{return await b(i)}finally{c(!1)}}if(!m||!h)throw c(!1),new Error("Stripe elements not provided");k(o("checkout.loading.processingPayment"));let{error:t}=await h.submit();if(t)throw t.type!=="validation_error"&&l("root",{message:t.message}),c(!1),new Error(t.message);let w,C;try{let a=await m.createConfirmationToken({elements:h,params:{payment_method_data:{billing_details:{name:i.customer_name||null,email:i.customer_email,address:{line1:i.customer_billing_address?.line1||null,line2:i.customer_billing_address?.line2||null,postal_code:i.customer_billing_address?.postal_code||null,city:i.customer_billing_address?.city||null,state:i.customer_billing_address?.state||null,country:i.customer_billing_address?.country||null},phone:null}}}});w=a.confirmationToken,C=a.error}catch(a){throw c(!1),a}if(!w||C){let a=o("checkout.loading.confirmationTokenFailed");throw l("root",{message:C?.message||a}),c(!1),new Error(C?.message||a)}let x;try{x=await b({...i,confirmation_token_id:w.id})}catch(a){throw c(!1),a}k(o("checkout.loading.paymentSuccessful"));let{intent_status:V,intent_client_secret:K}=x.payment_processor_metadata,L=V;for(;L==="requires_action";){let{error:a,paymentIntent:B,setupIntent:J}=await m.handleNextAction({clientSecret:K});if(a)throw c(!1),l("root",{message:a.message}),new Error(a.message);L=B?.status||J?.status||V}return c(!1),x},[e,l,b,o]);return ne(U.Provider,{value:{checkout:e,form:p,update:E,confirm:q,loading:f,loadingLabel:g,isUpdatePending:P},children:r})},se=()=>te(U);export{T as CheckoutContext,U as CheckoutFormContext,re as CheckoutFormProvider,X as CheckoutProvider,F as useCheckout,se as useCheckoutForm};
1
+ "use client";import{b as I,c as y,d as _,e as M,i as N,n as O}from"../chunk-TS7YIDY3.js";import"../chunk-EK7ODJWE.js";import{createContext as ee,useCallback as S,useContext as te,useState as A}from"react";var R=(r,u,e=1,s)=>{r.forEach(d=>{let o=d.loc.slice(e);s&&s.includes(o[0])&&(o=o.slice(1)),u(o.join("."),{type:d.type,message:d.msg})})};import{createContext as G,useCallback as v,useContext as W,useEffect as Y,useMemo as $,useState as D}from"react";import{jsx as Z}from"react/jsx-runtime";var j=async(r,u)=>{try{return{ok:!0,value:await _(r.GET("/v1/checkouts/client/{client_secret}",{params:{path:u}}))}}catch(e){return e instanceof y?{ok:!1,error:e.error}:{ok:!1,error:null}}},H=async(r,u,e)=>{try{return{ok:!0,value:await _(r.POST("/v1/checkouts/client/{client_secret}/confirm",{params:{path:u},body:e}))}}catch(s){return s instanceof y?{ok:!1,error:s.error}:{ok:!1,error:null}}},z=async(r,u,e)=>{try{return{ok:!0,value:await _(r.PATCH("/v1/checkouts/client/{client_secret}",{params:{path:u},body:e}))}}catch(s){return s instanceof y?{ok:!1,error:s.error}:{ok:!1,error:null}}},Q=()=>{throw new Error("You forgot to wrap your component in <CheckoutProvider>.")},T=G(Q),X=({clientSecret:r,initialCheckout:u,serverURL:e,server:s,children:d})=>{let o=$(()=>{let n=(()=>{if(e)return e.replace(/\/v1\/?$/,"");switch(s){case"sandbox":return"https://sandbox-api.getruba.com";case"production":case void 0:return"https://api.getruba.com";default:throw new Error(`Unknown server: '${s}'`)}})();return I(n)},[s,e]),[f,c]=D(u??null);Y(()=>{u||j(o,{client_secret:r}).then(n=>{n.ok&&c(n.value)}).catch(n=>{throw n})},[o,r,u]);let g=v(async()=>{let n=await j(o,{client_secret:r});return n.ok&&c(n.value),n},[o,r]),k=v(async n=>{let p=await z(o,{client_secret:r},n);return p.ok&&c(p.value),p},[o,r]),P=v(async n=>{let p=await H(o,{client_secret:r},n);return p.ok&&c(p.value),p},[o,r]);return f?Z(T.Provider,{value:{checkout:f,refresh:g,update:k,confirm:P,client:o},children:d}):null},F=()=>W(T);import{jsx as ne}from"react/jsx-runtime";var oe=()=>{throw new Error("You forgot to wrap your component in <CheckoutFormProvider>.")},U=ee(oe),re=({children:r,locale:u=M})=>{let{checkout:e,update:s,confirm:d}=F(),o=N(u),[f,c]=A(!1),[g,k]=A(),[P,n]=A(!1),p=O({defaultValues:{...e,customer_billing_address:e.customer_billing_address,discount_code:e.discount?e.discount.code:void 0,allow_trial:void 0},shouldUnregister:!0}),{setError:l}=p,E=S(async i=>{n(!0);let{ok:m,value:h,error:t}=await s(i).finally(()=>{n(!1)});if(m)return h;if(t){if(Array.isArray(t.detail))throw R(t.detail,l),t;switch(t.error){case"AlreadyActiveSubscriptionError":case"NotOpenCheckout":case"PaymentNotReady":l("root",{message:t.detail});break;case"ResourceNotFound":case"ExpiredCheckoutError":break}}throw t},[s,l]),b=S(async i=>{let{ok:m,value:h,error:t}=await d(i);if(m)return h;if(t){if(Array.isArray(t.detail))throw R(t.detail,l),t;switch(t.error){case"PaymentError":case"AlreadyActiveSubscriptionError":case"NotOpenCheckout":case"PaymentNotReady":l("root",{message:t.detail});break;case"TrialAlreadyRedeemed":l("root",{message:t.detail}),await E({allow_trial:!1});break;case"ResourceNotFound":case"ExpiredCheckoutError":break}}throw t},[d,l,E]),q=S(async(i,m,h)=>{if(c(!0),!e.is_payment_form_required){k(o("checkout.loading.processingOrder"));try{return await b(i)}finally{c(!1)}}if(!m||!h)throw c(!1),new Error("Stripe elements not provided");k(o("checkout.loading.processingPayment"));let{error:t}=await h.submit();if(t)throw t.type!=="validation_error"&&l("root",{message:t.message}),c(!1),new Error(t.message);let w,C;try{let a=await m.createConfirmationToken({elements:h,params:{payment_method_data:{billing_details:{name:i.customer_name||null,email:i.customer_email,address:{line1:i.customer_billing_address?.line1||null,line2:i.customer_billing_address?.line2||null,postal_code:i.customer_billing_address?.postal_code||null,city:i.customer_billing_address?.city||null,state:i.customer_billing_address?.state||null,country:i.customer_billing_address?.country||null},phone:null}}}});w=a.confirmationToken,C=a.error}catch(a){throw c(!1),a}if(!w||C){let a=o("checkout.loading.confirmationTokenFailed");throw l("root",{message:C?.message||a}),c(!1),new Error(C?.message||a)}let x;try{x=await b({...i,confirmation_token_id:w.id})}catch(a){throw c(!1),a}k(o("checkout.loading.paymentSuccessful"));let{intent_status:V,intent_client_secret:K}=x.payment_processor_metadata,L=V;for(;L==="requires_action";){let{error:a,paymentIntent:B,setupIntent:J}=await m.handleNextAction({clientSecret:K});if(a)throw c(!1),l("root",{message:a.message}),new Error(a.message);L=B?.status||J?.status||V}return c(!1),x},[e,l,b,o]);return ne(U.Provider,{value:{checkout:e,form:p,update:E,confirm:q,loading:f,loadingLabel:g,isUpdatePending:P},children:r})},se=()=>te(U);export{T as CheckoutContext,U as CheckoutFormContext,re as CheckoutFormProvider,X as CheckoutProvider,F as useCheckout,se as useCheckoutForm};
@@ -1 +1 @@
1
- "use strict";var e,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,r={};((e,n)=>{for(var s in n)t(e,s,{get:n[s],enumerable:!0})})(r,{RubaPaymentMethod:()=>f,usePaymentMethodRedirectResult:()=>b}),module.exports=(e=r,((e,r,o,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let d of s(r))a.call(e,d)||d===o||t(e,d,{get:()=>r[d],enumerable:!(i=n(r,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var o=require("react"),i="RUBA_PAYMENT_METHOD",d="/embed/payment-method",l="ruba_payment_method_status",c=()=>{const e="http://127.0.0.1:3000".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},m=()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},u=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:i},t)}static create(t){const{sessionToken:n,theme:s,setAsDefault:a,returnUrl:r,locale:o,onLoaded:i}=t,l=document.createElement("style");l.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===s?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===s?"#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(l);const u=document.createElement("div");u.style.position="absolute",u.style.top="50%",u.style.left="50%",u.style.transform="translate(-50%, -50%)",u.style.zIndex="2147483647",u.style.colorScheme="auto";const h=document.createElement("div");h.className="ruba-loader-spinner",u.appendChild(h),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(u);const f=new URL(d,c());f.searchParams.set("session_token",n),f.searchParams.set("embed","true"),f.searchParams.set("embed_origin",window.location.origin),f.searchParams.set("mode","modal"),f.searchParams.set("embed_return_url",r??window.location.href),s&&f.searchParams.set("theme",s),!1===a&&f.searchParams.set("set_default","false"),o&&f.searchParams.set("locale",o);const b=document.createElement("iframe");b.src=f.toString(),b.style.position="fixed",b.style.top="0",b.style.left="0",b.style.width="100%",b.style.height="100%",b.style.border="none",b.style.zIndex="2147483647",b.style.backgroundColor="rgba(0, 0, 0, 0.5)",b.style.colorScheme="auto",b.allow=m(),document.body.appendChild(b);const p=new e(b,"modal",u);return i&&p.addEventListener("loaded",i,{once:!0}),new Promise(e=>{p.addEventListener("loaded",()=>e(p),{once:!0})})}static createInline(t){const{sessionToken:n,element:s,theme:a,setAsDefault:r,locale:o,onLoaded:i}=t,l=new URL(d,c());l.searchParams.set("session_token",n),l.searchParams.set("embed","true"),l.searchParams.set("embed_origin",window.location.origin),l.searchParams.set("mode","inline"),a&&l.searchParams.set("theme",a),!1===r&&l.searchParams.set("set_default","false"),o&&l.searchParams.set("locale",o);const u=document.createElement("iframe");u.src=l.toString(),u.style.display="block",u.style.width="100%",u.style.height="0",u.style.border="none",u.style.colorScheme="auto",u.allow=m(),s.replaceChildren(u);const h=new e(u,"inline",null);return i&&h.addEventListener("loaded",i,{once:!0}),h}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(l);if("succeeded"!==t&&"failed"!==t)return null;e.delete(l);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,n){this.eventTarget.addEventListener(e,t,n)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let n=t.target;for(;!n.hasAttribute("data-ruba-payment-method");){if(!n.parentElement)return;n=n.parentElement}const s=n.getAttribute("data-ruba-payment-method");if(!s)return;const a=n.getAttribute("data-ruba-payment-method-theme"),r=n.getAttribute("data-ruba-payment-method-set-as-default"),o=n.getAttribute("data-ruba-payment-method-return-url"),i=n.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:s,theme:a??void 0,setAsDefault:null===r?void 0:"false"!==r,returnUrl:o??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:e,origin:t}){if(!"http://127.0.0.1:3000".split(",").includes(t))return;if(e.type!==i)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const n=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(n),!n.defaultPrevented)switch(e.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:u}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{u.init()})}var h=require("react/jsx-runtime"),f=({sessionToken:e,theme:t,setAsDefault:n,locale:s,onLoaded:a,onConfirmed:r,onSuccess:i,onError:d,className:l,style:c})=>{const m=(0,o.useRef)(null),u=(0,o.useRef)({onLoaded:a,onConfirmed:r,onSuccess:i,onError:d});return(0,o.useEffect)(()=>{u.current={onLoaded:a,onConfirmed:r,onSuccess:i,onError:d}}),(0,o.useEffect)(()=>{const a=m.current;if(!a)return;const r=new URL("/embed/payment-method","http://127.0.0.1:3000".split(",")[0]);r.searchParams.set("session_token",e),r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),t&&r.searchParams.set("theme",t),!1===n&&r.searchParams.set("set_default","false"),s&&r.searchParams.set("locale",s);const o=document.createElement("iframe");o.src=r.toString(),o.style.display="block",o.style.width="100%",o.style.height="0",o.style.border="none",o.style.colorScheme="auto",o.allow=(()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`})(),a.replaceChildren(o);const i=({data:e,origin:t})=>{var n;if((e=>"http://127.0.0.1:3000".split(",").includes(e))(t)&&((n=e)&&"object"==typeof n&&"RUBA_PAYMENT_METHOD"===n.type))switch(e.event){case"loaded":u.current.onLoaded?.();break;case"confirmed":u.current.onConfirmed?.();break;case"success":u.current.onSuccess?.(e.paymentMethodId);break;case"error":u.current.onError?.(e.code);break;case"resize":o.style.height=`${Math.max(0,Math.ceil(e.height))}px`}};return window.addEventListener("message",i),()=>{window.removeEventListener("message",i),o.remove()}},[e,t,n,s]),(0,h.jsx)("div",{ref:m,className:l,style:c})},b=({onSuccess:e,onError:t,onResult:n})=>{const s=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(s.current)return;s.current=!0;const a=u.getRedirectResult();a&&(n?.(a),"succeeded"===a.status?e?.():t?.())},[e,t,n])};
1
+ "use strict";var e,t=Object.defineProperty,s=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,r={};((e,s)=>{for(var n in s)t(e,n,{get:s[n],enumerable:!0})})(r,{RubaPaymentMethod:()=>b,usePaymentMethodRedirectResult:()=>f}),module.exports=(e=r,((e,r,o,i)=>{if(r&&"object"==typeof r||"function"==typeof r)for(let d of n(r))a.call(e,d)||d===o||t(e,d,{get:()=>r[d],enumerable:!(i=s(r,d))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var o=require("react"),i="RUBA_PAYMENT_METHOD",d="/embed/payment-method",l="ruba_payment_method_status",c=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},m=()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},u=class e{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,s){this.iframe=e,this.mode=t,this.loader=s,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(e,t){window.parent.postMessage({...e,type:i},t)}static create(t){const{sessionToken:s,theme:n,setAsDefault:a,returnUrl:r,locale:o,onLoaded:i}=t,l=document.createElement("style");l.innerText=`\n .ruba-loader-spinner {\n width: 20px;\n aspect-ratio: 1;\n border-radius: 50%;\n background: ${"dark"===n?"#000":"#fff"};\n box-shadow: 0 0 0 0 ${"dark"===n?"#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(l);const u=document.createElement("div");u.style.position="absolute",u.style.top="50%",u.style.left="50%",u.style.transform="translate(-50%, -50%)",u.style.zIndex="2147483647",u.style.colorScheme="auto";const h=document.createElement("div");h.className="ruba-loader-spinner",u.appendChild(h),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(u);const b=new URL(d,c());b.searchParams.set("session_token",s),b.searchParams.set("embed","true"),b.searchParams.set("embed_origin",window.location.origin),b.searchParams.set("mode","modal"),b.searchParams.set("embed_return_url",r??window.location.href),n&&b.searchParams.set("theme",n),!1===a&&b.searchParams.set("set_default","false"),o&&b.searchParams.set("locale",o);const f=document.createElement("iframe");f.src=b.toString(),f.style.position="fixed",f.style.top="0",f.style.left="0",f.style.width="100%",f.style.height="100%",f.style.border="none",f.style.zIndex="2147483647",f.style.backgroundColor="rgba(0, 0, 0, 0.5)",f.style.colorScheme="auto",f.allow=m(),document.body.appendChild(f);const p=new e(f,"modal",u);return i&&p.addEventListener("loaded",i,{once:!0}),new Promise(e=>{p.addEventListener("loaded",()=>e(p),{once:!0})})}static createInline(t){const{sessionToken:s,element:n,theme:a,setAsDefault:r,locale:o,onLoaded:i}=t,l=new URL(d,c());l.searchParams.set("session_token",s),l.searchParams.set("embed","true"),l.searchParams.set("embed_origin",window.location.origin),l.searchParams.set("mode","inline"),a&&l.searchParams.set("theme",a),!1===r&&l.searchParams.set("set_default","false"),o&&l.searchParams.set("locale",o);const u=document.createElement("iframe");u.src=l.toString(),u.style.display="block",u.style.width="100%",u.style.height="0",u.style.border="none",u.style.colorScheme="auto",u.allow=m(),n.replaceChildren(u);const h=new e(u,"inline",null);return i&&h.addEventListener("loaded",i,{once:!0}),h}static init(){document.querySelectorAll("[data-ruba-payment-method]").forEach(t=>{t.removeEventListener("click",e.elementClickHandler),t.addEventListener("click",e.elementClickHandler)})}static getRedirectResult(){if("undefined"==typeof window)return null;const e=new URLSearchParams(window.location.search),t=e.get(l);if("succeeded"!==t&&"failed"!==t)return null;e.delete(l);const s=e.toString();return window.history.replaceState({},"",`${window.location.pathname}${s?`?${s}`:""}${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,s){this.eventTarget.addEventListener(e,t,s)}removeEventListener(e,t){this.eventTarget.removeEventListener(e,t)}static async elementClickHandler(t){t.preventDefault();let s=t.target;for(;!s.hasAttribute("data-ruba-payment-method");){if(!s.parentElement)return;s=s.parentElement}const n=s.getAttribute("data-ruba-payment-method");if(!n)return;const a=s.getAttribute("data-ruba-payment-method-theme"),r=s.getAttribute("data-ruba-payment-method-set-as-default"),o=s.getAttribute("data-ruba-payment-method-return-url"),i=s.getAttribute("data-ruba-payment-method-locale");e.create({sessionToken:n,theme:a??void 0,setAsDefault:null===r?void 0:"false"!==r,returnUrl:o??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:e,origin:t}){if(!"https://getruba.com,https://sandbox.getruba.com".split(",").includes(t))return;if(e.type!==i)return;if("resize"===e.event)return void("inline"===this.mode&&(this.iframe.style.height=`${Math.max(0,Math.ceil(e.height))}px`));const s=new CustomEvent(e.event,{detail:e,cancelable:!0});if(this.eventTarget.dispatchEvent(s),!s.defaultPrevented)switch(e.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:u}),"undefined"!=typeof document){const e=document.currentScript;e&&e.hasAttribute("data-auto-init")&&document.addEventListener("DOMContentLoaded",()=>{u.init()})}var h=require("react/jsx-runtime"),b=({sessionToken:e,theme:t,setAsDefault:s,locale:n,onLoaded:a,onConfirmed:r,onSuccess:i,onError:d,className:l,style:c})=>{const m=(0,o.useRef)(null),u=(0,o.useRef)({onLoaded:a,onConfirmed:r,onSuccess:i,onError:d});return(0,o.useEffect)(()=>{u.current={onLoaded:a,onConfirmed:r,onSuccess:i,onError:d}}),(0,o.useEffect)(()=>{const a=m.current;if(!a)return;const r=new URL("/embed/payment-method","https://getruba.com,https://sandbox.getruba.com".split(",")[0]);r.searchParams.set("session_token",e),r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),t&&r.searchParams.set("theme",t),!1===s&&r.searchParams.set("set_default","false"),n&&r.searchParams.set("locale",n);const o=document.createElement("iframe");o.src=r.toString(),o.style.display="block",o.style.width="100%",o.style.height="0",o.style.border="none",o.style.colorScheme="auto",o.allow=(()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`})(),a.replaceChildren(o);const i=({data:e,origin:t})=>{var s;if((e=>"https://getruba.com,https://sandbox.getruba.com".split(",").includes(e))(t)&&((s=e)&&"object"==typeof s&&"RUBA_PAYMENT_METHOD"===s.type))switch(e.event){case"loaded":u.current.onLoaded?.();break;case"confirmed":u.current.onConfirmed?.();break;case"success":u.current.onSuccess?.(e.paymentMethodId);break;case"error":u.current.onError?.(e.code);break;case"resize":o.style.height=`${Math.max(0,Math.ceil(e.height))}px`}};return window.addEventListener("message",i),()=>{window.removeEventListener("message",i),o.remove()}},[e,t,s,n]),(0,h.jsx)("div",{ref:m,className:l,style:c})},f=({onSuccess:e,onError:t,onResult:s})=>{const n=(0,o.useRef)(!1);(0,o.useEffect)(()=>{if(n.current)return;n.current=!0;const a=u.getRedirectResult();a&&(s?.(a),"succeeded"===a.status?e?.():t?.())},[e,t,s])};
@@ -1 +1 @@
1
- import{EmbedPaymentMethod as e}from"../chunk-FSZEYAE6.js";import{useEffect as r,useRef as t}from"react";import{jsx as s}from"react/jsx-runtime";var o=({sessionToken:e,theme:o,setAsDefault:n,locale:a,onLoaded:c,onConfirmed:i,onSuccess:d,onError:l,className:m,style:u})=>{const h=t(null),f=t({onLoaded:c,onConfirmed:i,onSuccess:d,onError:l});return r(()=>{f.current={onLoaded:c,onConfirmed:i,onSuccess:d,onError:l}}),r(()=>{const r=h.current;if(!r)return;const t=new URL("/embed/payment-method","http://127.0.0.1:3000".split(",")[0]);t.searchParams.set("session_token",e),t.searchParams.set("embed","true"),t.searchParams.set("embed_origin",window.location.origin),o&&t.searchParams.set("theme",o),!1===n&&t.searchParams.set("set_default","false"),a&&t.searchParams.set("locale",a);const s=document.createElement("iframe");s.src=t.toString(),s.style.display="block",s.style.width="100%",s.style.height="0",s.style.border="none",s.style.colorScheme="auto",s.allow=(()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`})(),r.replaceChildren(s);const c=({data:e,origin:r})=>{var t;if((e=>"http://127.0.0.1:3000".split(",").includes(e))(r)&&((t=e)&&"object"==typeof t&&"RUBA_PAYMENT_METHOD"===t.type))switch(e.event){case"loaded":f.current.onLoaded?.();break;case"confirmed":f.current.onConfirmed?.();break;case"success":f.current.onSuccess?.(e.paymentMethodId);break;case"error":f.current.onError?.(e.code);break;case"resize":s.style.height=`${Math.max(0,Math.ceil(e.height))}px`}};return window.addEventListener("message",c),()=>{window.removeEventListener("message",c),s.remove()}},[e,o,n,a]),s("div",{ref:h,className:m,style:u})},n=({onSuccess:s,onError:o,onResult:n})=>{const a=t(!1);r(()=>{if(a.current)return;a.current=!0;const r=e.getRedirectResult();r&&(n?.(r),"succeeded"===r.status?s?.():o?.())},[s,o,n])};export{o as RubaPaymentMethod,n as usePaymentMethodRedirectResult};
1
+ import{EmbedPaymentMethod as e}from"../chunk-B7RTOVF6.js";import{useEffect as t,useRef as r}from"react";import{jsx as s}from"react/jsx-runtime";var o=({sessionToken:e,theme:o,setAsDefault:n,locale:a,onLoaded:c,onConfirmed:i,onSuccess:m,onError:d,className:l,style:u})=>{const h=r(null),p=r({onLoaded:c,onConfirmed:i,onSuccess:m,onError:d});return t(()=>{p.current={onLoaded:c,onConfirmed:i,onSuccess:m,onError:d}}),t(()=>{const t=h.current;if(!t)return;const r=new URL("/embed/payment-method","https://getruba.com,https://sandbox.getruba.com".split(",")[0]);r.searchParams.set("session_token",e),r.searchParams.set("embed","true"),r.searchParams.set("embed_origin",window.location.origin),o&&r.searchParams.set("theme",o),!1===n&&r.searchParams.set("set_default","false"),a&&r.searchParams.set("locale",a);const s=document.createElement("iframe");s.src=r.toString(),s.style.display="block",s.style.width="100%",s.style.height="0",s.style.border="none",s.style.colorScheme="auto",s.allow=(()=>{const e="https://getruba.com,https://sandbox.getruba.com".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`})(),t.replaceChildren(s);const c=({data:e,origin:t})=>{var r;if((e=>"https://getruba.com,https://sandbox.getruba.com".split(",").includes(e))(t)&&((r=e)&&"object"==typeof r&&"RUBA_PAYMENT_METHOD"===r.type))switch(e.event){case"loaded":p.current.onLoaded?.();break;case"confirmed":p.current.onConfirmed?.();break;case"success":p.current.onSuccess?.(e.paymentMethodId);break;case"error":p.current.onError?.(e.code);break;case"resize":s.style.height=`${Math.max(0,Math.ceil(e.height))}px`}};return window.addEventListener("message",c),()=>{window.removeEventListener("message",c),s.remove()}},[e,o,n,a]),s("div",{ref:h,className:l,style:u})},n=({onSuccess:s,onError:o,onResult:n})=>{const a=r(!1);t(()=>{if(a.current)return;a.current=!0;const t=e.getRedirectResult();t&&(n?.(t),"succeeded"===t.status?s?.():o?.())},[s,o,n])};export{o as RubaPaymentMethod,n as usePaymentMethodRedirectResult};
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@getruba/checkout",
3
- "description": "Ruba Checkout SDK",
3
+ "description": "Embeddable checkout and payment components for Ruba integrations.",
4
4
  "author": "Ruba",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
- "version": "0.3.0",
7
+ "version": "0.3.2",
8
8
  "files": [
9
9
  "dist"
10
10
  ],
@@ -53,10 +53,11 @@
53
53
  "peerDependencies": {
54
54
  "@stripe/react-stripe-js": "^3.6.0 || ^4.0.2 || ^5.6.1",
55
55
  "@stripe/stripe-js": "^7.1.0 || ^8.11.0",
56
- "react": "^18 || ^19"
56
+ "react": "^18 || ^19",
57
+ "react-dom": "^18 || ^19"
57
58
  },
58
59
  "scripts": {
59
- "build": "rm -rf dist/ && tsup && node scripts/sanitize-public-build.mjs",
60
+ "build": "rm -rf dist/ && tsup && node scripts/sanitize-public-build.mjs && node scripts/verify-public-build-runtime.mjs",
60
61
  "lint": "oxfmt --check . && eslint --max-warnings 0 .",
61
62
  "test": "vitest run",
62
63
  "typecheck": "tsc --noEmit"
@@ -1 +0,0 @@
1
- var e="RUBA_PAYMENT_METHOD",t="/embed/payment-method",n="ruba_payment_method_status",a=()=>{const e="http://127.0.0.1:3000".split(",");return"undefined"!=typeof window&&e.includes(window.location.origin)?window.location.origin:e[0]},s=()=>{const e="http://127.0.0.1:3000".split(",").join(" ");return`payment 'self' ${e}; publickey-credentials-get 'self' ${e};`},o=class o{iframe;mode;loader;loaded;closable;eventTarget;windowMessageListener;constructor(e,t,n){this.iframe=e,this.mode=t,this.loader=n,this.loaded=!1,this.closable=!0,this.eventTarget=new EventTarget,this.windowMessageListener=this.handleWindowMessage.bind(this),window.addEventListener("message",this.windowMessageListener)}static postMessage(t,n){window.parent.postMessage({...t,type:e},n)}static create(e){const{sessionToken:n,theme:r,setAsDefault:i,returnUrl:d,locale:l,onLoaded:c}=e,h=document.createElement("style");h.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(h);const m=document.createElement("div");m.style.position="absolute",m.style.top="50%",m.style.left="50%",m.style.transform="translate(-50%, -50%)",m.style.zIndex="2147483647",m.style.colorScheme="auto";const u=document.createElement("div");u.className="ruba-loader-spinner",m.appendChild(u),document.body.classList.add("ruba-no-scroll"),document.body.appendChild(m);const b=new URL(t,a());b.searchParams.set("session_token",n),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 f=new o(w,"modal",m);return c&&f.addEventListener("loaded",c,{once:!0}),new Promise(e=>{f.addEventListener("loaded",()=>e(f),{once:!0})})}static createInline(e){const{sessionToken:n,element:r,theme:i,setAsDefault:d,locale:l,onLoaded:c}=e,h=new URL(t,a());h.searchParams.set("session_token",n),h.searchParams.set("embed","true"),h.searchParams.set("embed_origin",window.location.origin),h.searchParams.set("mode","inline"),i&&h.searchParams.set("theme",i),!1===d&&h.searchParams.set("set_default","false"),l&&h.searchParams.set("locale",l);const m=document.createElement("iframe");m.src=h.toString(),m.style.display="block",m.style.width="100%",m.style.height="0",m.style.border="none",m.style.colorScheme="auto",m.allow=s(),r.replaceChildren(m);const u=new o(m,"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(n);if("succeeded"!==t&&"failed"!==t)return null;e.delete(n);const a=e.toString();return window.history.replaceState({},"",`${window.location.pathname}${a?`?${a}`:""}${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,n){this.eventTarget.addEventListener(e,t,n)}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 n=t.getAttribute("data-ruba-payment-method");if(!n)return;const a=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:n,theme:a??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:n}){if(!"http://127.0.0.1:3000".split(",").includes(n))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 a=new CustomEvent(t.event,{detail:t,cancelable:!0});if(this.eventTarget.dispatchEvent(a),!a.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{n as REDIRECT_STATUS_PARAM,o as EmbedPaymentMethod};
@@ -1 +0,0 @@
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=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(b,c)=>(typeof require<"u"?require:b)[c]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});var n=(a,b)=>()=>(b||a((b={exports:{}}).exports,b),b.exports);var l=(a,b,c,e)=>{if(b&&typeof b=="object"||typeof b=="function")for(let d of i(b))!k.call(a,d)&&d!==c&&f(a,d,{get:()=>b[d],enumerable:!(e=h(b,d))||e.enumerable});return a};var o=(a,b,c)=>(c=a!=null?g(j(a)):{},l(b||!a||!a.__esModule?f(c,"default",{value:a,enumerable:!0}):c,a));export{m as a,n as b,o as c};