UNPKG

dodopayments-checkout

Version:

A TypeScript library for embedding Dodo Payments checkout (overlay and inline).

48 lines (47 loc) 48.6 kB
function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,o=Array(t);n<t;n++)o[n]=e[n];return o}function t(e,t,n){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var o=n.call(e,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function o(e){for(var o=1;o<arguments.length;o++){var i=null!=arguments[o]?arguments[o]:{};o%2?n(Object(i),!0).forEach(function(n){t(e,n,i[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):n(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function i(t,n){return function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var o,i,r,a,l=[],s=!0,c=!1;try{if(r=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;s=!1}else for(;!(s=(o=r.call(n)).done)&&(l.push(o.value),l.length!==t);s=!0);}catch(e){c=!0,i=e}finally{try{if(!s&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw i}}return l}}(t,n)||function(t,n){if(t){if("string"==typeof t)return e(t,n);var o={}.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?e(t,n):void 0}}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var r={test:"https://test.checkout.dodopayments.com",live:"https://checkout.dodopayments.com"},a="1.1.0",l={test:"https://sdk-v2.custom.hs.dodopayments.com",live:"https://sdk-v2.hs.dodopayments.com"},s={test:"https://api.custom.hs.dodopayments.com",live:"https://api.hs.dodopayments.com"},c="\n width: 100dvw;\n height: 100dvh;\n position: fixed;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n border: none;\n background: transparent;\n z-index: 1000;\n",d="\n width: 100%;\n max-width: 500px;\n margin: 0 auto;\n padding-left: 5px;\n padding-right: 5px;\n box-sizing: border-box;\n line-height: 0;\n",u=new Set(["checkout.opened","checkout.payment_page_opened","checkout.customer_details_submitted","checkout.closed","checkout.error","checkout.redirect","checkout.resize","checkout.breakdown","checkout.link_expired","checkout.status","checkout.redirect_requested","checkout.pay_button_clicked","checkout.keys_provided","checkout.form_ready"]);function p(e,t){return!!document.querySelector('link[rel="'.concat(e,'"][href="').concat(t,'"]'))}function f(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if(!p("preconnect",e)&&document.head){var n=document.createElement("link");n.rel="preconnect",n.href=e,t&&(n.crossOrigin="anonymous"),document.head.appendChild(n)}}function h(e){if(!p("dns-prefetch",e)&&document.head){var t=document.createElement("link");t.rel="dns-prefetch",t.href=e,document.head.appendChild(t)}}function m(e){var t=function(e){return"".concat(l[e],"/").concat(a,"/sdk.js")}(e);if(!p("preload",t)&&!document.querySelector('script[src="'.concat(t,'"]'))&&document.head){var n=document.createElement("link");n.rel="preload",n.as="script",n.href=t,document.head.appendChild(n)}}function y(e){if(!e.mode)throw new Error("Checkout mode is required");if(!Object.keys(r).includes(e.mode))throw new Error("Invalid checkout mode");if(e.displayType&&!["overlay","inline"].includes(e.displayType))throw new Error("Invalid display type. Must be 'overlay' or 'inline'")}function w(e){try{var t=new URL(e);if("https:"!==t.protocol&&"http:"!==t.protocol)throw new Error("Invalid redirect URL protocol");if(e.length>2048)throw new Error("Redirect URL exceeds maximum length")}catch(e){throw new Error("Invalid redirect URL format")}}var v=null;function g(){var e;if(null!==(e=v)&&void 0!==e&&e.wrapperDiv){var t=v.walletElementContainer,n=!!t&&"hidden"!==t.style.visibility?t.offsetHeight||44:0;v.wrapperDiv.style.height="".concat(v.lastCheckoutIframeHeight+n,"px")}}function b(e){if(v&&e.origin===v.allowedOrigin)try{var t=e.data;if(!t||!t.event_type)return;if(!u.has(t.event_type))return void console.warn("Received message with invalid event_type: ".concat(t.event_type));if(k(t.event_type,t.data||{}),"checkout.closed"===t.event_type&&setTimeout(function(){return z(!1)},100),"checkout.redirect"===t.event_type){var n,o=null===(n=t.data)||void 0===n||null===(n=n.message)||void 0===n?void 0:n.redirect_to;if(o)try{w(o),window.location.href=o}catch(e){console.error("Invalid redirect URL:",e),k("checkout.error",{message:"Invalid redirect URL"})}}if(t.event_type,"checkout.keys_provided"===t.event_type&&"inline"===v.config.displayType){var i,r,c=null===(i=t.data)||void 0===i?void 0:i.message;if(!c||"string"!=typeof c.publishable_key||"string"!=typeof c.client_secret_key)return console.error("Invalid keys_provided payload:",c),void k("checkout.error",{message:"Wallet initialization failed - invalid key data"});(null!==(r=v.dodoScriptPromise)&&void 0!==r?r:Promise.resolve()).then(function(){try{!function(e,t,n){if(!v)throw new Error("Checkout not initialized");var o=window.DodoCheckoutWebSDK;if(!o)throw new Error("Dodo SDK not loaded");var i=v.config.mode,r=s[i],c="".concat(l[i],"/").concat(a);try{var d=o.loadDodoPayments(e,{apiUrl:r,baseUrl:c});v.dodoInstance=d;var u=d.elements({clientSecret:t,appearance:{theme:"default"},walletReturnUrl:n||window.location.href,wallets:{applePay:"auto",googlePay:"never"},allowedPaymentMethods:["apple_pay"],displaySavedPaymentMethods:!1}).create("wallet");v.walletElement=u,u.on("paymentresult",function(e){var t=e;if(t.paymentIntent){k("checkout.status",{status:t.paymentIntent.status,paymentIntent:t.paymentIntent});var o=n||t.paymentIntent.return_url;if(o){try{w(o)}catch(e){return console.error("Invalid wallet return URL:",o),void k("checkout.error",{message:"Invalid wallet return URL"})}try{window.top.location.replace(o)}catch(e){window.location.replace(o)}}}else{var i,r=null===(i=t.error)||void 0===i?void 0:i.code;if(r&&["apple_pay_cancelled","apple_pay_validation_failed"].includes(r))return;t.error&&(console.error("Wallet payment error:",t.error),k("checkout.error",{message:"Wallet payment failed"}))}});var p=v.walletElementContainer;if(p){if(u.on("ready",function(){var e;if(null!==(e=v)&&void 0!==e&&e.walletElementContainer){var t=v.walletElementContainer;t.style.visibility="visible",t.style.height="auto",t.style.overflow="visible"}g()}),u.on("loaderror",function(){var e;if(null!==(e=v)&&void 0!==e&&e.walletElementContainer){var t=v.walletElementContainer;t.style.visibility="hidden",t.style.height="0",t.style.overflow="hidden"}g()}),"undefined"!=typeof ResizeObserver){var f=new ResizeObserver(function(){return g()});f.observe(p),v.walletResizeObserver=f}u.mount("#".concat(p.id))}}catch(e){throw console.error("Failed to initialize Dodo wallet:",e),v.walletElementContainer&&(v.walletElementContainer.style.display="none"),e}}(c.publishable_key,c.client_secret_key,c.return_url)}catch(e){console.error("Error initializing Dodo wallet:",e),k("checkout.error",{message:"Failed to initialize wallet"})}},function(){})}}catch(e){console.error("Error processing checkout message:",e),k("checkout.error",{message:"Failed to process message"})}}function k(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(v)if(u.has(e)){var i=o(o({},n),{},{products:v.currentProducts,timestamp:Date.now()});if(v.config.onEvent)try{v.config.onEvent({event_type:e,data:i})}catch(t){console.error("Error in onEvent handler for ".concat(e,":"),t)}null!==(t=v.eventListeners[e])&&void 0!==t&&t.length&&v.eventListeners[e].forEach(function(t){try{t(i)}catch(t){console.error("Error in ".concat(e," event handler:"),t)}})}else console.warn("Attempted to emit invalid event type: ".concat(e))}function z(){var e,t,n,o=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(null!==(e=v)&&void 0!==e&&e.container||null!==(t=v)&&void 0!==t&&t.iframe||null!==(n=v)&&void 0!==n&&n.wrapperDiv)try{if(v.container?(v.container.remove(),v.container=null):v.wrapperDiv?(v.wrapperDiv.remove(),v.wrapperDiv=null):v.iframe&&v.iframe.remove(),v.iframe=null,v.currentProducts=[],v.iframeResizerInstance&&v.iframeResizerInstance.length>0&&(v.iframeResizerInstance.forEach(function(e){e.iFrameResizer.close()}),v.iframeResizerInstance=null),v.walletResizeObserver&&(v.walletResizeObserver.disconnect(),v.walletResizeObserver=null),v.walletElement){try{v.walletElement.destroy()}catch(e){console.error("Error destroying wallet element:",e)}v.walletElement=null}v.walletElementContainer&&(v.walletElementContainer.remove(),v.walletElementContainer=null),v.dodoInstance=null,v.dodoScriptPromise=null,v.lastCheckoutIframeHeight=0,document.body.style.overflow="",document.body.style.contain="",o&&k("checkout.closed",{message:"Checkout closed manually"})}catch(e){throw console.error("Error closing checkout:",e),k("checkout.error",{message:"Failed to close checkout"}),e}}function E(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var I,T,R,x={exports:{}}; /*! * @module auto-console-group v1.2.11 * * @description Automagically group console logs in the browser console. * * @author David J. Bradshaw <info@iframe-resizer.com> * @see {@link https://github.com/davidjbradshaw/auto-console-group#readme} * @license MIT * * @copyright (c) 2025, David J. Bradshaw. All rights reserved. */function O(){return I||(I=1,function(e){const t="font-weight: normal;",n="font-weight: bold;",o="font-style: italic;",i=t+o,r="color: #135CD2;",a="color: #A9C7FB;",l="color: #1F1F1F;",s="color: #E3E3E3;",c="default",d="error",u="log",p=Object.freeze({assert:!0,error:!0,warn:!0}),f={expand:!1,defaultEvent:void 0,event:void 0,label:"AutoConsoleGroup",showTime:!0},h={profile:0,profileEnd:0,timeStamp:0,trace:0},m=e=>{const t=e.event||e.defaultEvent;return t?`${t}`:""},y=Object.assign(console);function w(){const e=new Date,t=(t,n)=>e[t]().toString().padStart(n,"0");return`@ ${t("getHours",2)}:${t("getMinutes",2)}:${t("getSeconds",2)}.${t("getMilliseconds",3)}`}const{fromEntries:v,keys:g}=Object,b=e=>[e,y[e]],k=e=>t=>[t,function(n){e[t]=n}],z=(e,t)=>v(g(e).map(t));function E(e={}){const o={},r={},a=[],l={...f,expand:!e.collapsed||f.expanded,...e};let s="";function v(){a.length=0,s=""}function g(){delete l.event,v()}const E=()=>a.some(([e])=>e in p),I=()=>!!E()||!!l.expand,T=()=>l.showTime?s:"";function R(){if(0!==a.length){y[I()?"group":"groupCollapsed"](`%c${l.label}%c ${m(l)} %c${T()}`,t,n,i);for(const[e,...t]of a)y.assert(e in y,`Unknown console method: ${e}`),e in y&&y[e](...t);y.groupEnd(),g()}else g()}function x(){""===s&&(s=w())}function O(e){x(),l.event=e}function j(){x(),queueMicrotask(()=>queueMicrotask(R))}function P(e,...t){0===a.length&&j(),a.push([e,...t])}const L=e=>(...t)=>{let n;try{n=e(...t)}catch(e){if(!Error.prototype.isPrototypeOf(e))throw e;P(d,e),R()}return n};function S(e,...t){!0!==e&&P("assert",e,...t)}function C(e=c){r[e]?r[e]+=1:r[e]=1,P(u,`${e}: ${r[e]}`)}function D(e=c){delete r[e]}function $(e=c){x(),o[e]=performance.now()}function A(e=c,...t){if(!o[e])return void P("timeLog",e,...t);const n=performance.now()-o[e];P(u,`${e}: ${n} ms`,...t)}function U(e=c){A(e),delete o[e]}const N=e=>[e,(...t)=>P(e,...t)];return{...z(l,k(l)),...z(console,N),...z(h,b),assert:S,count:C,countReset:D,endAutoGroup:R,errorBoundary:L,event:O,purge:v,time:$,timeEnd:U,timeLog:A,touch:x}}const I=!(typeof window>"u"||"function"!=typeof window.matchMedia)&&window.matchMedia("(prefers-color-scheme: dark)").matches,T=I?a:r,R=I?s:l;e.BOLD=n,e.FOREGROUND=R,e.HIGHLIGHT=T,e.ITALIC=o,e.NORMAL=t,e.default=E,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}(x.exports)),x.exports} /*! * @preserve * * @module iframe-resizer/core 5.5.7 (cjs) - 2025-09-23 * * @license GPL-3.0 for non-commercial use only. * For commercial use, you must purchase a license from * https://iframe-resizer.com/pricing * * @description Keep same and cross domain iFrames sized to their content * * @author David J. Bradshaw <info@iframe-resizer.com> * * @see {@link https://iframe-resizer.com} * * @copyright (c) 2013 - 2025, David J. Bradshaw. All rights reserved. */var j=E(function(){if(R)return T;R=1;const e=O(),t="5.5.7",n="iframeResizer",o=":",i="autoResize",r="init",a="iframeReady",l="load",s="message",c="onload",d="pageInfo",u="parentInfo",p="reset",f="resize",h="scroll",m="child",y="parent",w="string",v="object",g="function",b="auto",k="none",z="vertical",E="horizontal",I="[iFrameSizer]",x=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),j=Object.freeze({[c]:1,[r]:1,[a]:1}),P="expanded",L="collapsed",S=Object.freeze({[P]:1,[L]:1}),C=(e,t,n,o)=>e.addEventListener(t,n,o||!1),D=(e,t,n)=>e.removeEventListener(t,n,!1),$=e=>{if(!e)return"";let t=-559038744,n=1103547984;for(let o,i=0;i<e.length;i++)o=e.codePointAt(i),t=Math.imul(t^o,2246822519),n=Math.imul(n^o,3266489917);return t^=Math.imul(t^n>>>15,1935289751),n^=Math.imul(n^t>>>15,3405138345),t^=n>>>16,n^=t>>>16,(2097152*(n>>>0)+(t>>>11)).toString(36)},A=e=>e.replace(/[A-Za-z]/g,e=>String.fromCodePoint((e<="Z"?90:122)>=(e=e.codePointAt(0)+19)?e:e-26)),U=["spjluzl","rlf","clyzpvu"],N=["<yi>Puchspk Spjluzl Rlf</><iy><iy>","<yi>Tpzzpun Spjluzl Rlf</><iy><iy>","Aopz spiyhyf pz hchpshisl dpao ivao Jvttlyjphs huk Vwlu-Zvbyjl spjluzlz.<iy><iy><i>Jvttlyjphs Spjluzl</><iy>Mvy jvttlyjphs bzl, <p>pmyhtl-ylzpgly</> ylxbpylz h svd jvza vul aptl spjluzl mll. Mvy tvyl pumvythapvu cpzpa <b>oaawz://pmyhtl-ylzpgly.jvt/wypjpun</>.<iy><iy><i>Vwlu Zvbyjl Spjluzl</><iy>Pm fvb hyl bzpun aopz spiyhyf pu h uvu-jvttlyjphs vwlu zvbyjl wyvqlja aolu fvb jhu bzl pa mvy myll bukly aol alytz vm aol NWS C3 Spjluzl. Av jvumpyt fvb hjjlwa aolzl alytz, wslhzl zla aol <i>spjluzl</> rlf pu <p>pmyhtl-ylzpgly</> vwapvuz av <i>NWSc3</>.<iy><iy>Mvy tvyl pumvythapvu wslhzl zll: <b>oaawz://pmyhtl-ylzpgly.jvt/nws</>","<i>NWSc3 Spjluzl Clyzpvu</><iy><iy>Aopz clyzpvu vm <p>pmyhtl-ylzpgly</> pz ilpun bzlk bukly aol alytz vm aol <i>NWS C3</> spjluzl. Aopz spjluzl hssvdz fvb av bzl <p>pmyhtl-ylzpgly</> pu Vwlu Zvbyjl wyvqljaz, iba pa ylxbpylz fvby wyvqlja av il wbispj, wyvcpkl haaypibapvu huk il spjluzlk bukly clyzpvu 3 vy shaly vm aol NUB Nlulyhs Wbispj Spjluzl.<iy><iy>Pm fvb hyl bzpun aopz spiyhyf pu h uvu-vwlu zvbyjl wyvqlja vy dlizpal, fvb dpss ullk av wbyjohzl h svd jvza vul aptl jvttlyjphs spjluzl.<iy><iy>Mvy tvyl pumvythapvu cpzpa <b>oaawz://pmyhtl-ylzpgly.jvt/wypjpun</>.","<iy><yi>Zvsv spjluzl kvlz uva zbwwvya jyvzz-kvthpu</><iy><iy>Av bzl <p>pmyhtl-ylzpgly</> dpao jyvzz kvthpu pmyhtlz fvb ullk lpaoly aol Wyvmlzzpvuhs vy Ibzpulzz spjluzlz. Mvy klahpsz vu bwnyhkl wypjpun wslhzl jvuahja pumv@pmyhtl-ylzpgly.jvt.","Pu whnl spurpun ylxbpylz h Wyvmlzzpvuhs vy Ibzpulzz spjluzl. Wslhzl zll <b>oaawz://pmyhtl-ylzpgly.jvt/wypjpun</> mvy tvyl klahpsz."],_=["NWSc3","zvsv","wyv","ibzpulzz","vlt"],H=Object.fromEntries(["2cgs7fdf4xb","1c9ctcccr4z","1q2pc4eebgb","ueokt0969w","w2zxchhgqz","1umuxblj2e5"].map((e,t)=>[e,Math.max(0,t-1)])),M=e=>A(N[e]),W=e=>{const t=e[A(U[0])]||e[A(U[1])]||e[A(U[2])];if(!t)return-1;const n=t.split("-");let o=function(e=""){let t=-2;const n=$(A(e));return n in H&&(t=H[n]),t}(n[0]);return 0===o||(e=>e[2]===$(e[0]+e[1]))(n)||(o=-2),o},G=Object.hasOwn||((e,t)=>Object.prototype.hasOwnProperty.call(e,t)),F=e=>e,B=e=>t=>window.chrome?e(t.replaceAll("<br>","\n").replaceAll("<rb>","").replaceAll("</>","").replaceAll("<b>","").replaceAll("<i>","").replaceAll("<u>","")):e((e=>e.replaceAll("<br>","\n").replaceAll(/<[/a-z]+>/gi,""))(t)),q={},Z=(K=e,K?.__esModule?K.default:K);var K;let J=!0;const V=Z({expand:!1,label:y}),X=e=>window.top===window.self?`parent(${e})`:`nested parent(${e})`,Y=e=>(t,...n)=>q[t]?q[t].console[e](...n):V[e](...n),Q=(e,...t)=>!0===(e=>q[e]?q[e].log:J)(e)?Y("log")(e,...t):null,ee=Y("warn"),te=Y("error"),ne=Y("event"),oe=Y("purge"),ie=Y("errorBoundary"),re=(e,...t)=>q[e]?q[e].console.warn(B(F)(...t)):queueMicrotask(()=>console?.warn(B((e=>(...t)=>[`${n}(${e})`,...t].join(" "))(e))(...t))),ae=(e=>(t,n="renamed to")=>(o,i,r="",a="")=>e(a,`<rb>Deprecated ${t}(${o.replace("()","")})</>\n\nThe <b>${o}</> ${t.toLowerCase()} has been ${n} <b>${i}</>. ${r}Use of the old ${t.toLowerCase()} will be removed in a future version of <i>iframe-resizer</>.`))(re)("Option"),le=Object.freeze({autoResize:!0,bodyBackground:null,bodyMargin:null,bodyPadding:null,checkOrigin:!0,direction:z,firstRun:!0,inPageLinks:!1,heightCalculationMethod:b,id:"iFrameResizer",log:!1,logExpand:!1,license:void 0,mouseEvents:!0,offsetHeight:null,offsetWidth:null,postMessageTarget:null,sameDomain:!1,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,waitForLoad:!1,warningTimeout:5e3,widthCalculationMethod:b,onBeforeClose:()=>!0,onAfterClose(){},onInit:!1,onMessage:null,onMouseEnter(){},onMouseLeave(){},onReady:e=>{typeof q[e.id].onInit===g&&(ae("init()","onReady()","",e.id),q[e.id].onInit(e))},onResized(){},onScroll:()=>!0}),se={position:null,version:t};function ce(n){function a(){we(_),me(W),$("onResized",_)}function c(e){return"border-box"!==e.boxSizing?0:(e.paddingTop?parseInt(e.paddingTop,10):0)+(e.paddingBottom?parseInt(e.paddingBottom,10):0)}function m(e){return"border-box"!==e.boxSizing?0:(e.borderTopWidth?parseInt(e.borderTopWidth,10):0)+(e.borderBottomWidth?parseInt(e.borderBottomWidth,10):0)}const v=e=>U.slice(U.indexOf(o)+7+e),g=(e,t)=>(n,o)=>{const i={};var r,a;r=function(){ge(`${n} (${e})`,`${e}:${t()}`,o)},i[a=o]||(r(),i[a]=requestAnimationFrame(()=>{i[a]=null}))},b=(e,t)=>()=>{let n=!1;const o=t=>()=>{q[c]?n&&n!==t||(e(t,c),n=t,requestAnimationFrame(()=>{n=!1})):s()},i=o(h),r=o("resize window");function a(e,t){t(window,h,i),t(window,f,r)}function s(){ne(c,`stop${t}`),a(0,D),d.disconnect(),u.disconnect(),D(q[c].iframe,l,s)}const c=W,d=new ResizeObserver(o("pageObserver")),u=new ResizeObserver(o("iframeObserver"));q[c]&&(q[c][`stop${t}`]=s,C(q[c].iframe,l,s),a(0,C),d.observe(document.body,{attributes:!0,childList:!0,subtree:!0}),u.observe(q[c].iframe,{attributes:!0,childList:!1,subtree:!1}))},k=e=>()=>{e in q[W]&&(q[W][e](),delete q[W][e])},z=g(d,function(){const e=document.body.getBoundingClientRect(),t=_.iframe.getBoundingClientRect(),{scrollY:n,scrollX:o,innerHeight:i,innerWidth:r}=window,{clientHeight:a,clientWidth:l}=document.documentElement;return JSON.stringify({iframeHeight:t.height,iframeWidth:t.width,clientHeight:Math.max(a,i||0),clientWidth:Math.max(l,r||0),offsetTop:parseInt(t.top-e.top,10),offsetLeft:parseInt(t.left-e.left,10),scrollTop:n,scrollLeft:o,documentHeight:a,documentWidth:l,windowHeight:i,windowWidth:r})}),E=g(u,function(){const{iframe:e}=_,{scrollWidth:t,scrollHeight:n}=document.documentElement,{width:o,height:i,offsetLeft:r,offsetTop:a,pageLeft:l,pageTop:s,scale:c}=window.visualViewport;return JSON.stringify({iframe:e.getBoundingClientRect(),document:{scrollWidth:t,scrollHeight:n},viewport:{width:o,height:i,offsetLeft:r,offsetTop:a,pageLeft:l,pageTop:s,scale:c}})}),T=b(z,"PageInfo"),R=b(E,"ParentInfo"),x=k("stopPageInfo"),O=k("stopParentInfo");function j(e){const t=e.getBoundingClientRect();return fe(),{x:Number(t.left)+Number(se.position.x),y:Number(t.top)+Number(se.position.y)}}function P(t){const n=t?j(_.iframe):{x:0,y:0};Q(W,`Reposition requested (offset x:%c${n.x}%c y:%c${n.y})`,e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT);const o=((e,t)=>({x:e.width+t.x,y:e.height+t.y}))(_,n),i=window.parentIframe||window.parentIFrame;i?function(e,n){setTimeout(()=>e["scrollTo"+(t?"Offset":"")](n.x,n.y))}(i,o):function(e){se.position=e,L(W)}(o)}function L(e){const{x:t,y:n}=se.position,o=q[e]?.iframe;!1!==$("onScroll",{iframe:o,top:n,left:t,x:t,y:n})?me(e):he()}function S(e){let t={};if(0===_.width&&0===_.height){const e=v(9).split(o);t={x:e[1],y:e[0]}}else t={x:_.width,y:_.height};$(e,{iframe:_.iframe,screenX:Number(t.x),screenY:Number(t.y),type:_.type})}const $=(e,t)=>de(W,e,t);function A(){const{height:n,iframe:o,msg:l,type:c,width:f}=_;switch(q[W]?.firstRun&&(q[W]&&(Ee(W,_.mode),q[W].firstRun=!1)),c){case"close":pe(o);break;case s:m=v(6),$("onMessage",{iframe:_.iframe,message:JSON.parse(m)});break;case"mouseenter":S("onMouseEnter");break;case"mouseleave":S("onMouseLeave");break;case"beforeUnload":Q(W,"Ready state reset"),q[W].initialised=!1;break;case i:q[W].autoResize=JSON.parse(v(9));break;case"scrollBy":!function(){const t=_.width,n=_.height,o=window.parentIframe||window.parentIFrame||window;Q(W,`scrollBy: x: %c${t}%c y: %c${n}`,e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT),o.scrollBy(t,n)}();break;case"scrollTo":P(!1);break;case"scrollToOffset":P(!0);break;case d:T();break;case u:R();break;case"pageInfoStop":x();break;case"parentInfoStop":O();break;case"inPageLink":!function(t){const n=t.split("#")[1]||"",o=decodeURIComponent(n);let i=document.getElementById(o)||document.getElementsByName(o)[0];i?function(){const t=j(i);Q(W,`Moving to in page link: %c#${n}`,e.HIGHLIGHT),se.position={x:t.x,y:t.y},L(W),window.location.hash=n}():window.top!==window.self&&function(){const e=window.parentIframe||window.parentIFrame;e&&e.moveToAnchor(n)}()}(v(9));break;case"title":!function(t,n){q[n]?.syncTitle&&(q[n].iframe.title=t,Q(n,`Set iframe title attribute: %c${t}`,e.HIGHLIGHT))}(l,W);break;case p:ye(_);break;case r:a(),function(e){try{q[e].sameOrigin=!!q[e]?.iframe?.contentWindow?.iframeChildListener}catch(t){q[e].sameOrigin=!1}}(W),(h=l)!==t&&(void 0!==h||re(W,"<rb>Legacy version detected in iframe</>\n\nDetected legacy version of child page script. It is recommended to update the page in the iframe to use <b>@iframe-resizer/child</>.\n\nSee <u>https://iframe-resizer.com/setup/#child-page-setup</> for more details.\n")),q[W].initialised=!0,$("onReady",o);break;default:if(0===f&&0===n)return void ee(W,`Unsupported message received (${c}), this is likely due to the iframe containing a later version of iframe-resizer than the parent page`);if(0===f||0===n)return;if(document.hidden)return;a()}var h,m}let U=n.data;if("[iFrameResizerChild]Ready"===U)return N=n.source,void Object.values(q).forEach((e=>({initChild:t,postMessageTarget:n})=>{e===n&&t()})(N));var N;if(!(e=>I===`${e}`.slice(0,13)&&e.slice(13).split(o)[0]in q)(U)){if(typeof U!==w)return;return void ne(y,"ignoredMessage")}const _=function(e){const t=e.slice(13).split(o),n=t[1]?Number(t[1]):0,i=q[t[0]]?.iframe,r=getComputedStyle(i),a={iframe:i,id:t[0],height:n+c(r)+m(r),width:Number(t[2]),type:t[3],msg:t[4]};return t[5]&&(a.mode=t[5]),a}(U),{id:H,type:M}=_,W=H;W?(ne(W,M),ie(W,function(e){(function(e){if(!q[e])throw new Error(`${_.type} No settings for ${e}. Message was: ${U}`)})(W),_.type in{true:1,false:1,undefined:1}||(null!==_.iframe||(ee(W,`The iframe (${_.id}) was not found.`),0))&&function(){const{origin:e,sameOrigin:t}=n;if(t)return!0;let o=q[W]?.checkOrigin;if(o&&"null"!=`${e}`&&!(o.constructor===Array?function(){let t=0,n=!1;for(;t<o.length;t++)if(o[t]===e){n=!0;break}return n}():function(){const t=q[W]?.remoteHost;return e===t}()))throw new Error(`Unexpected message received from: ${e} for ${_.iframe.id}. Message was: ${n.data}. This error can be disabled by setting the checkOrigin: false option or by providing of array of trusted domains.`);return!0}()&&A()})(U)):ee("","iframeResizer received messageData without id, message was: ",U)}function de(e,t,n){let o=null,i=null;if(q[e]){if(o=q[e][t],typeof o!==g)throw new TypeError(`${t} on iFrame[${e}] is not a function`);if("onBeforeClose"===t||"onScroll"===t)try{i=o(n)}catch(n){console.error(n),ee(e,`Error in ${t} callback`)}else((e,...t)=>{setTimeout(()=>e(...t),0)})(o,n)}return i}function ue(e){const{id:t}=e;delete q[t],delete e.iframeResizer}function pe(e){const{id:t}=e;if(!1!==de(t,"onBeforeClose",t)){try{e.parentNode&&e.remove()}catch(e){ee(t,e)}de(t,"onAfterClose",t),ue(e)}}function fe(e){null===se.position&&(se.position={x:window.scrollX,y:window.scrollY})}function he(){se.position=null}function me(t){null!==se.position&&(window.scrollTo(se.position.x,se.position.y),Q(t,`Set page position: %c${se.position.x}%c, %c${se.position.y}`,e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT),he())}function ye(e){fe(e.id),we(e),ge(p,p,e.id)}function we(t){function n(n){const i=`${t[n]}px`;t.iframe.style[n]=i,Q(o,`Set ${n}: %c${i}`,e.HIGHLIGHT)}const{id:o}=t,{sizeHeight:i,sizeWidth:r}=q[o];i&&n("height"),r&&n("width")}const ve=e=>e.split(o).filter((e,t)=>19!==t).join(o);function ge(t,n,o){function i(i){const r=t in j?ve(n):n;Q(o,i,e.HIGHLIGHT,e.FOREGROUND,e.HIGHLIGHT),Q(o,`Message data: %c${r}`,e.HIGHLIGHT)}ne(o,t),q[o]&&(q[o]?.postMessageTarget?function(){const{iframe:e,postMessageTarget:r,sameOrigin:a,targetOrigin:l}=q[o];if(a)try{return e.contentWindow.iframeChildListener(I+n),void i(`Sending message to iframe %c${o}%c via same origin%c`)}catch(e){t in j?q[o].sameOrigin=!1:ee(o,"Same origin messaging failed, falling back to postMessage")}i(`Sending message to iframe: %c${o}%c targetOrigin: %c${l}`),r.postMessage(I+n,l)}():ee(o,`Iframe(${o}) not found`))}let be=0,ke=!1,ze=!1;function Ee(n,o=-3){if(ke)return;const i=Math.max(q[n].mode,o);if(i>q[n].mode&&(q[n].mode=i),i<0)throw oe(n),q[n].vAdvised||re(n||"Parent",`${M(i+2)}${M(2)}`),q[n].vAdvised=!0,M(i+2).replace(/<\/?[a-z][^>]*>|<\/>/gi,"");i>0&&ze||function(t,n){queueMicrotask(()=>console.info(`%ciframe-resizer ${t}`,J||n<1?"font-weight: bold;":e.NORMAL))}(`v${t} (${(e=>A(_[e]))(i)})`,i),i<1&&re("Parent",M(3)),ke=!0}function Ie(){!0!==document.hidden&&((e,t)=>{Object.values(q).filter(({autoResize:e,firstRun:t})=>e&&!t).forEach(({iframe:e})=>ge("tabVisible",t,e.id))})(0,f)}const Te=(e=>{let t=!1;return function(){return t?void 0:(t=!0,Reflect.apply(e,this,arguments))}})(()=>{C(window,s,ce),C(document,"visibilitychange",Ie),window.iframeParentListener=e=>setTimeout(()=>ce({data:e,sameOrigin:!0}))});return T=t=>d=>{function u(e,t){const n=n=>()=>{if(!q[e])return;const{firstRun:o,iframe:i}=q[e];ge(n,t,e),(e=>e===r)(n)&&(e=>"lazy"===e.loading)(i)||function(e,t){const{msgTimeout:n,warningTimeout:o}=t[e];o&&(n&&clearTimeout(n),t[e].msgTimeout=setTimeout(function(){if(void 0===t[e])return;const{initialised:n,loadErrorShown:o}=t[e];t[e].msgTimeout=void 0,n||o||(t[e].loadErrorShown=!0,function(e,t){const{iframe:n,waitForLoad:o}=t[e],{sandbox:i}=n,r=typeof i===v&&i.length>0&&!(i.contains("allow-scripts")&&i.contains("allow-same-origin"));ne(e,"noResponse"),re(e,`<rb>No response from iframe</>\n \nThe iframe (<i>${e}</>) has not responded within ${t[e].warningTimeout/1e3} seconds. Check <b>@iframe-resizer/child</> package has been loaded in the iframe.\n${o?"\nThe <b>waitForLoad</> option is currently set to <b>'true'</>. If the iframe loads before <i>iframe-resizer</> runs, this option will prevent <i>iframe-resizer</> initialising. To disable this option, set <b>waitForLoad</> to <b>'false'</>. \n":""}${r?"\nThe iframe has the <b>sandbox</> attribute, please ensure it contains both the <i>'allow-same-origin'</> and <i>'allow-scripts'</> values.\n":""}\nThis message can be ignored if everything is working, or you can set the <b>warningTimeout</> option to a higher value or zero to suppress this warning.\n`)}(e,t))},o))}(e,q),o||q[T]?.heightCalculationMethod in x&&ye({iframe:d,height:1,width:1,type:r})},{iframe:o}=q[e];q[e].initChild=n(a),function(e,t){C(e,l,()=>setTimeout(t,1))}(o,n(c)),function(e,t){const{iframe:n,waitForLoad:o}=q[e];!0!==o&&((e=>{const{src:t,srcdoc:n}=e;return!n&&(null==t||""===t||"about:blank"===t)})(n)?setTimeout(()=>{ne(e,"noContent"),Q(e,"No content detected in the iframe, delaying initialisation")}):setTimeout(t))}(e,n(r))}function p(e){return e?(("sizeWidth"in e||"sizeHeight"in e||i in e)&&re(T,`<rb>Deprecated Option</>\n\nThe <b>sizeWidth</>, <b>sizeHeight</> and <b>autoResize</> options have been replaced with new <b>direction</> option which expects values of <i>"${z}"</>, <i>"${E}"</> or <i>"${k}"</>.\n`),e):{}}function h(e){const t=q[e]?.iframe?.title;return""===t||void 0===t}function y(e,t){G(q[T],e)&&(re(T,`<rb>Deprecated option</>\n\nThe <b>${e}</> option has been renamed to <b>${t}</>. Use of the old name will be removed in a future version of <i>iframe-resizer</>.`),q[T][t]=q[T][e],delete q[T][e])}const g=e=>G(e,"onMouseEnter")||G(e,"onMouseLeave");function I(t){var n,o;q[T]={...q[T],iframe:d,remoteHost:d?.src.split("/").slice(0,3).join("/"),...le,...p(t),mouseEvents:g(t),mode:W(t),syncTitle:h(T)},y("offset","offsetSize"),y("onClose","onBeforeClose"),y("onClosed","onAfterClose"),ne(T,"setup"),function(){const{direction:e}=q[T];switch(e){case z:break;case E:q[T].sizeHeight=!1;case"both":q[T].sizeWidth=!0;break;case k:q[T].sizeWidth=!1,q[T].sizeHeight=!1,q[T].autoResize=!1;break;default:throw new TypeError(T,`Direction value of "${e}" is not valid`)}}(),(n=t?.offsetSize||t?.offset)&&(q[T].direction===z?q[T].offsetHeight=n:q[T].offsetWidth=n),function(e){e?.offset&&re(T,"<rb>Deprecated option</>\n\n The <b>offset</> option has been renamed to <b>offsetSize</>. Use of the old name will be removed in a future version of <i>iframe-resizer</>.")}(t),q[T].warningTimeout||Q(T,"warningTimeout:%c disabled",e.HIGHLIGHT),null===q[T].postMessageTarget&&(q[T].postMessageTarget=d.contentWindow),q[T].targetOrigin=!0===q[T].checkOrigin?""===(o=q[T].remoteHost)||null!==o.match(/^(about:blank|javascript:|file:\/\/)/)?"*":o:"*"}const T=function(e){if(e&&typeof e!==w)throw new TypeError("Invalid id for iFrame. Expected String");return""!==e&&e||(e=function(){let e=t?.id||le.id+be++;return null!==document.getElementById(e)&&(e+=be++),e}(),d.id=e,ne(e,"assignId")),e}(d.id);if(typeof t!==v)throw new TypeError("Options is not an object");return function(e){const{search:t}=window.location;t.includes("ifrlog")&&(e.log=L,e.logExpand=t.includes("ifrlog=expanded"))}(t),function(e,t){const n=G(t,"log"),o=typeof t.log===w,i=n?!!o||t.log:le.log;G(t,"logExpand")||(t.logExpand=n&&o?t.log===P:le.logExpand),function(e){-1===e?.log&&(e.log=!1,ze=!0)}(t),function({enabled:e,expand:t,iframeId:n}){const o=Z({expand:t,label:X(n)});J=e,q[n]||(q[n]={console:o})}({enabled:i,expand:t.logExpand,iframeId:e}),o&&!(t.log in S)&&te(e,'Invalid value for options.log: Accepted values are "expanded" and "collapsed"'),t.log=i}(T,t),ie(T,function(e){n in d?ee(T,`Ignored iframe (${T}), already setup.`):(I(e),function(){if(ke)return;const{mode:e}=q[T];-1!==e&&Ee(T,e)}(),Te(),function(){switch(d.style.overflow=!1===q[T]?.scrolling?"hidden":b,q[T]?.scrolling){case"omit":break;case!0:d.scrolling="yes";break;case!1:d.scrolling="no";break;default:d.scrolling=q[T]?q[T].scrolling:"no"}}(),function(){const{bodyMargin:e}=q[T];"number"!=typeof e&&"0"!==e||(q[T].bodyMargin=`${e}px`)}(),u(T,function(e){const{autoResize:t,bodyBackground:n,bodyMargin:i,bodyPadding:r,heightCalculationMethod:a,inPageLinks:l,license:s,log:c,logExpand:d,mouseEvents:u,offsetHeight:p,offsetWidth:f,mode:h,sizeHeight:y,sizeWidth:w,tolerance:v,widthCalculationMethod:g}=q[e];return[e,"8",w,c,"32",!0,t,i,a,n,r,v,l,m,g,u,p,f,y,s,se.version,h,"",d].join(o)}(T)),function(){if(q[T]){const{iframe:e}=q[T],t={close:pe.bind(null,e),disconnect:ue.bind(null,e),removeListeners(){re(T,"<rb>Deprecated Method Name</>\n\nThe emoveListeners()</> method has been renamed to isconnect()</>.\n"),this.disconnect()},resize(){re(T,"<rb>Deprecated Method</>\n \nUse of the <b>resize()</> method from the parent page is deprecated and will be removed in a future version of <i>iframe-resizer</>. As their are no longer any edge cases that require triggering a resize from the parent page, it is recommended to remove this method from your code."),ge.bind(null,"Window resize",f,T)},moveToAnchor(e){((e,t)=>{if(typeof e!==t)throw new TypeError(`moveToAnchor(anchor) anchor is not a ${n=t,n.charAt(0).toUpperCase()+n.slice(1)}`);var n})(e,w),ge("Move to anchor",`moveToAnchor:${e}`,T)},sendMessage(e){e=JSON.stringify(e),ge(s,`${s}:${e}`,T)}};e.iframeResizer=t,e.iFrameResizer=t}}())})(t),d?.iframeResizer}}()); /*! * @preserve * * @module iframe-resizer/parent 5.5.7 (esm) - 2025-09-23 * * @license GPL-3.0 for non-commercial use only. * For commercial use, you must purchase a license from * https://iframe-resizer.com/pricing * * @description Keep same and cross domain iFrames sized to their content * * @author David J. Bradshaw <info@iframe-resizer.com> * * @see {@link https://iframe-resizer.com} * * @copyright (c) 2013 - 2025, David J. Bradshaw. All rights reserved. */ const P="undefined",L="[iframeResizer] ";const S=function(){function e(e){switch(!0){case!e:throw new TypeError(`${L}iframe is not defined`);case!e.tagName:throw new TypeError(`${L}Not a valid DOM element`);case"IFRAME"!==e.tagName.toUpperCase():throw new TypeError(`${L}Expected <IFRAME> tag, found <${e.tagName}>`);default:t(e),n.push(e)}}let t,n;return function(o,i){if(typeof window===P)return[];switch(t=j(o),n=[],typeof i){case P:case"string":document.querySelectorAll(i||"iframe").forEach(e);break;case"object":e(i);break;default:throw new TypeError(`${L}Unexpected data type (${typeof i})`)}return Object.freeze(n)}}();var C=null;function D(e,t){var n=Date.now(),o=function(){void 0!==window.DodoCheckoutWebSDK?e():Date.now()-n>1e4?t(new Error("Dodo SDK script loaded but window.DodoCheckoutWebSDK not available")):setTimeout(o,50)};o()}function $(e){var t,n=e.products,o=e.paymentLink,r=e.queryParams,s=e.redirectUrl,u=e.checkoutUrl,p=e.elementId,f=e.options;if(n&&n.length>0&&console.warn("⚠️ DEPRECATION WARNING: 'products' option is deprecated and will be removed in v2.0.0. Please use 'checkoutUrl' with session linkType instead."),o&&console.warn("⚠️ DEPRECATION WARNING: 'paymentLink' option is deprecated and will be removed in v2.0.0. Please use 'checkoutUrl' with session linkType instead."),r&&console.warn("⚠️ DEPRECATION WARNING: 'queryParams' option is deprecated and will be removed in v2.0.0. Please include query parameters in your 'checkoutUrl' instead."),s&&console.warn("⚠️ DEPRECATION WARNING: 'redirectUrl' option is deprecated and will be removed in v2.0.0. Please include redirect URL in your checkout session configuration instead."),o&&(!function(e){try{var t=new URL(e);if("https:"!==t.protocol&&"http:"!==t.protocol)throw new Error("Invalid payment URL protocol");if(e.length>2048)throw new Error("Payment URL exceeds maximum length")}catch(e){throw new Error("Invalid payment URL format")}}(o),t=o.slice(-8)),!C)throw new Error("Checkout not initialized");if(function(e,t){if("inline"===t&&!e.elementId)throw new Error("elementId is required for inline checkout display type");if(e.elementId&&"string"!=typeof e.elementId)throw new Error("elementId must be a string")}(e,C.config.displayType),C.iframe||C.container)console.warn("Checkout is already open");else{if(s&&w(s),u&&function(e){try{var t=new URL(e);if("https:"!==t.protocol&&"http:"!==t.protocol)throw new Error("Invalid checkout URL protocol");if(e.length>2048)throw new Error("Checkout URL exceeds maximum length");if("test.checkout.dodopayments.com"===t.hostname||"checkout.dodopayments.com"===t.hostname){var n=t.pathname.split("/").filter(function(e){return e.length>0});if(0===n.length)throw new Error("Checkout URL must contain a session ID or payment link ID");if("session"===n[0]){if(2!==n.length)throw new Error("Session URL must have format: /session/cks_sessionId");var o=n[1];if(!o.startsWith("cks_"))throw new Error("Session ID must start with 'cks_' prefix");if(25!==o.length)throw new Error("Session ID must be exactly 25 characters including 'cks_' prefix");if(!/^cks_[a-zA-Z0-9_-]+$/.test(o))throw new Error("Session ID contains invalid characters")}else if(1===n.length){var i=n[0];if(8!==i.length)throw new Error("Payment link ID must be exactly 8 characters");if(!/^[a-zA-Z0-9_-]+$/.test(i))throw new Error("Payment link ID contains invalid characters")}else{if("overlay"!==n[0])throw new Error("Invalid checkout URL format. Expected /session/cks_id or /paymentLinkId");if(2===n.length){var r=n[1];if(8!==r.length||!/^[a-zA-Z0-9_-]{8}$/.test(r))throw new Error("Invalid payment link ID in overlay URL")}else{if(3!==n.length||"session"!==n[1])throw new Error("Invalid overlay URL format. Expected /overlay/paymentLinkId or /overlay/session/sessionId");var a=n[2];if(!a.startsWith("cks_")||25!==a.length||!/^cks_[a-zA-Z0-9_-]{21}$/.test(a))throw new Error("Invalid session ID in overlay URL")}}}}catch(e){if(e instanceof Error)throw e;throw new Error("Invalid checkout URL format")}}(u),"session"===C.config.linkType){if(!u)throw new Error("checkoutUrl is required for session checkout")}else if("static"===C.config.linkType){if(console.warn("⚠️ DEPRECATION WARNING: 'static' linkType is deprecated and will be removed in v2.0.0. Please migrate to 'session' linkType with checkoutUrl."),null==n||!n.length)throw new Error("Products are required for static checkout");if(n.length>1)throw new Error("Only one product is supported for checkout at the moment");!function(e){if(!e||"string"!=typeof e)throw new Error("Invalid product ID");if(e.length>50)throw new Error("Product ID exceeds maximum length");if(!/^[a-zA-Z0-9_-]+$/.test(e))throw new Error("Product ID contains invalid characters")}(n[0].productId)}else if("dynamic"===C.config.linkType&&(console.warn("⚠️ DEPRECATION WARNING: 'dynamic' linkType is deprecated and will be removed in v2.0.0. Please migrate to 'session' linkType with checkoutUrl."),!t))throw new Error("Payment link ID is required for dynamic checkout");t&&function(e){if(!e||"string"!=typeof e)throw new Error("Invalid payment link ID");if(e.length>10)throw new Error("Payment link ID exceeds maximum length");if(!/^[a-zA-Z0-9_-]+$/.test(e))throw new Error("Payment link ID contains invalid characters")}(t),C.currentProducts=n||[];try{!function(e,t,n,o,r,s,u){if(!C)return;var p,f=C.config.displayType||"overlay";if("session"===C.config.linkType&&r){var h=U(r,f,u);p=new URL(h)}else if("static"===C.config.linkType&&null!=e&&e[0])p=function(e,t,n){if(!C)throw new Error("Checkout not initialized");if(!C.config.displayType)throw new Error("Display type not specified");var o="inline"===C.config.displayType?"inline":"overlay",r=new URL("".concat(C.baseUrl,"/").concat(o,"/buy/").concat(e.productId),window.location.origin);t&&Object.entries(t).forEach(function(e){var t=i(e,2),n=t[0],o=t[1];r.searchParams.append(n,o)});n&&r.searchParams.append("redirect_url",n);r.searchParams.append("quantity",e.quantity.toString()),C.config.theme&&console.warn("⚠️ DEPRECATION WARNING: Using 'theme' in static checkout is deprecated and will be removed in v2.0.0. Please configure theme in your checkout session instead.");return r.searchParams.append("theme",C.config.theme||"light"),r}(e[0],n,o);else{if("dynamic"!==C.config.linkType||!t)throw new Error("Invalid checkout configuration");p=function(e){if(!C)throw new Error("Checkout not initialized");if(!C.config.displayType)throw new Error("Display type not specified");var t="inline"===C.config.displayType?"inline":"overlay",n=new URL("".concat(C.baseUrl,"/").concat(t,"/").concat(e),window.location.origin);C.config.theme&&console.warn("⚠️ DEPRECATION WARNING: Using 'theme' in dynamic checkout is deprecated and will be removed in v2.0.0. Please configure theme in your checkout session instead.");return n.searchParams.append("theme",C.config.theme||"light"),n}(t)}var m=document.createElement("iframe");if(m.id=C.iframeId,m.src=p.toString(),function(e){e.setAttribute("allowtransparency","true"),e.setAttribute("frameBorder","0"),e.allow="payment keyboard-map *",e.setAttribute("sandbox","allow-same-origin allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox"),e.setAttribute("referrerpolicy","strict-origin-when-cross-origin"),e.setAttribute("fetchpriority","high")}(m),"inline"===f){var y=s?document.getElementById(s):null;if(!y)throw new Error('Target element with ID "'.concat(s,'" not found for inline checkout.'));var w=function(){if(!C)return Promise.reject(new Error("Checkout not initialized"));var e="".concat(l[C.config.mode],"/").concat(a,"/sdk.js"),t=document.querySelector('script[src="'.concat(e,'"]'));if(t)return new Promise(function(e,n){t.addEventListener("error",function(){return n(new Error("Failed to load Dodo SDK script"))}),D(e,n)});if(!document.head)return Promise.reject(new Error("Document head not found, cannot inject Dodo SDK script"));var n=document.createElement("script");return n.async=!0,n.src=e,new Promise(function(e,t){n.onload=function(){return D(e,t)},n.onerror=function(){t(new Error("Failed to load Dodo SDK script"))},document.head.appendChild(n)})}();C.dodoScriptPromise=w,w.catch(function(e){var t;console.error("Failed to inject Dodo SDK:",e),null!==(t=C)&&void 0!==t&&t.walletElementContainer&&(C.walletElementContainer.style.display="none"),k("checkout.error",{message:"Wallet initialization failed"})});var v=document.createElement("div"),b="dodo-wallet-".concat(Date.now());v.id=b,v.style.cssText=d+" visibility: hidden; height: 0; overflow: hidden;",C.walletElementContainer=v;var z=document.createElement("div");z.style.cssText="\n display: flex;\n flex-direction: column;\n height: 0px;\n overflow-y: auto;\n transition: height 0.2s ease-out;\n ",C.wrapperDiv=z,m.style.cssText="\n width: 100%;\n height: 100%;\n border: none;\n background: transparent;\n overflow: hidden;\n transition: height 0.2s ease-out;\n ",z.appendChild(v),z.appendChild(m),y.appendChild(z),C.iframe=m,C.container=null;var E={license:"GPLv3",checkOrigin:[C.allowedOrigin],direction:"vertical",log:!1,warningTimeout:15e3,onResized:function(e){C&&(C.lastCheckoutIframeHeight=e.height,g())}};C.iframeResizerInstance=S(E,m)}else{var I="z-index: 6859456; position: fixed; top: 0px; display: block; left: 0px; height: 100%; width: 100%; max-height: 100dvh; backface-visibility: hidden; overflow-y: visible;",T="min-height: 100%; transition: 0.3s ease-out; position: fixed; top: 0px; left: 0px; width: 100%; height: 100%; background: transparent;",R=document.createElement("div");R.style.cssText=I,R.id="dodo-checkout-outer-div";var x=document.createElement("div");x.style.cssText=T,x.id="dodo-checkout-inner-div",m.style.cssText=c,x.appendChild(m),R.appendChild(x),document.body.style.overflow="hidden",document.body.style.contain="initial",document.body.appendChild(R),C.iframe=m,C.container=R}}(n,t,r,s,u,p,f)}catch(e){throw console.error("Error creating checkout:",e),k("checkout.error",{message:"Failed to create checkout"}),e}}}function A(e,t,n){t&&Object.entries(t).forEach(function(t){var o=i(t,2),r=o[0],a=o[1];a&&e.searchParams.append("".concat(n,"_").concat(r),String(a))})}function U(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"overlay",o=arguments.length>2?arguments[2]:void 0;if(!e||"string"!=typeof e)throw new Error("URL must be a non-empty string");if(e.trim()!==e)throw new Error("URL cannot have leading or trailing whitespace");try{t=new URL(e.trim())}catch(e){throw new Error("Invalid URL format")}if("https:"!==t.protocol&&"http:"!==t.protocol)throw new Error("URL must use HTTP or HTTPS protocol");var i=["test.checkout.dodopayments.com","checkout.dodopayments.com"];if(!i.includes(t.hostname))throw new Error("URL must be a Dodo Payments checkout domain. Expected: ".concat(i.join(" or ")));var r="inline"===n?"inline":"overlay",a=t.pathname.split("/").filter(function(e){return e.length>0});if(0===a.length)throw new Error("URL must contain a session ID or payment link ID");if("session"===a[0]){if(2!==a.length)throw new Error("Session URL must have exactly 2 path segments: /session/sessionId");var l=a[1];if(!l.startsWith("cks_"))throw new Error("Session ID must start with 'cks_' prefix");if(25!==l.length)throw new Error("Session ID must be exactly 25 characters including 'cks_' prefix");if(!/^cks_[a-zA-Z0-9_-]{21}$/.test(l))throw new Error("Session ID contains invalid characters. Only alphanumeric, underscore, and dash allowed after 'cks_' prefix");t.pathname="/".concat(r,"/session/").concat(l)}else if(1===a.length){var s=a[0];if(8!==s.length)throw new Error("Payment link ID must be exactly 8 characters");if(!/^[a-zA-Z0-9_-]{8}$/.test(s))throw new Error("Payment link ID contains invalid characters. Only alphanumeric, underscore, and dash allowed");t.pathname="/".concat(r,"/").concat(s)}else{if("overlay"!==a[0]&&"inline"!==a[0])throw new Error("Invalid URL format. Expected formats:\n - /session/cks_sessionId (25 chars total)\n - /paymentLinkId (8 chars)\n - /overlay/id or /inline/id (already processed)\n \n Got: /".concat(a.join("/")));var c=a[0];if(2===a.length){var d=a[1];if(8!==d.length||!/^[a-zA-Z0-9_-]{8}$/.test(d))throw new Error("Invalid payment link ID in ".concat(c," URL"))}else{if(3!==a.length||"session"!==a[1])throw new Error("".concat(c," URL must have format: /").concat(c,"/paymentLinkId or /").concat(c,"/session/sessionId"));var u=a[2];if(!u.startsWith("cks_")||25!==u.length||!/^cks_[a-zA-Z0-9_-]{21}$/.test(u))throw new Error("Invalid session ID in ".concat(c," URL"))}}if(o){if(void 0!==o.showTimer&&t.searchParams.append("showTimer",String(o.showTimer)),void 0!==o.showSecurityBadge&&t.searchParams.append("showSecurityBadge",String(o.showSecurityBadge)),void 0!==o.manualRedirect&&t.searchParams.append("manualRedirect",String(o.manualRedirect)),void 0!==o.themeConfig){var p=o.themeConfig;A(t,p.light,"theme"),A(t,p.dark,"theme_dark"),p.radius&&t.searchParams.append("theme_radius",p.radius)}void 0!==o.payButtonText&&t.searchParams.append("payButtonText",o.payButtonText),void 0!==o.fontSize&&t.searchParams.append("fontSize",o.fontSize),void 0!==o.fontWeight&&t.searchParams.append("fontWeight",o.fontWeight)}var f=t.toString();if(!f.includes("/".concat(r,"/")))throw new Error("Internal error: Failed to build overlay URL");return f}var N={Initialize:function(e){if(y(e),e.theme&&console.warn("⚠️ DEPRECATION WARNING: 'theme' option is deprecated and will be removed in v2.0.0. Please configure theme in your checkout session instead."),e.linkType&&"session"!==e.linkType&&console.warn("⚠️ DEPRECATION WARNING: 'linkType' option with value '"+e.linkType+"' is deprecated and will be removed in v2.0.0. Please use 'session' linkType with checkoutUrl instead."),C)!function(e){if(!C)throw new Error("Checkout not initialized");y(e),e.theme&&console.warn("⚠️ DEPRECATION WARNING: 'theme' option is deprecated and will be removed in v2.0.0. Please configure theme in your checkout session instead.");e.linkType&&"session"!==e.linkType&&console.warn("⚠️ DEPRECATION WARNING: 'linkType' option with value '"+e.linkType+"' is deprecated and will be removed in v2.0.0. Please use 'session' linkType with checkoutUrl instead.");var t=e.onEvent||C.config.onEvent;C.config=o(o({linkType:"session"},e),{},{onEvent:t}),C.baseUrl!==r[e.mode]&&(C.baseUrl=r[e.mode],C.allowedOrigin=new URL(C.baseUrl).origin)}(e);else{var t=r[e.mode],n=new URL(t).origin;C={iframe:null,container:null,config:o({linkType:"session"},e),currentProducts:[],baseUrl:t,allowedOrigin:n,iframeId:"dodo-checkout-iframe",eventListeners:{},dodoInstance:null,walletElement:null,walletElementContainer:null,walletResizeObserver:null,lastCheckoutIframeHeight:0,dodoScriptPromise:null,wrapperDiv:null,iframeResizerInstance:null},v=C,window.addEventListener("message",b),function(e){var t=e.mode,n=e.displayType;try{var o=new URL(r[t]);if(f(o.origin),h(o.origin),"inline"===n){var i=new URL(l[t]),a=new URL(s[t]);f(i.origin,!1),h(i.origin),f(a.origin),h(a.origin)}}catch(e){console.warn("Failed to inject resource hints:",e)}}({mode:e.mode,displayType:e.displayType}),"inline"===e.displayType&&m(e.mode)}},Checkout:{open:function(e){$(e)},close:z,isOpen:function(){var e,t;return!!(null!==(e=C)&&void 0!==e&&e.iframe||null!==(t=C)&&void 0!==t&&t.container)},buildUrl:U}};export{N as DodoPayments};