dodopayments-checkout
Version:
A TypeScript library for embedding Dodo Payments checkout (overlay and inline).
48 lines (47 loc) • 49 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).DodoPaymentsCheckout={})}(this,function(e){"use strict";function t(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 n(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 o(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 i(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?o(Object(i),!0).forEach(function(t){n(e,t,i[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):o(Object(i)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))})}return e}function r(e,n){return function(e){if(Array.isArray(e))return e}(e)||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}}(e,n)||function(e,n){if(e){if("string"==typeof e)return t(e,n);var o={}.toString.call(e).slice(8,-1);return"Object"===o&&e.constructor&&(o=e.constructor.name),"Map"===o||"Set"===o?Array.from(e):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?t(e,n):void 0}}(e,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 a={test:"https://test.checkout.dodopayments.com",live:"https://checkout.dodopayments.com"},l="1.1.0",s={test:"https://sdk-v2.custom.hs.dodopayments.com",live:"https://sdk-v2.hs.dodopayments.com"},c={test:"https://api.custom.hs.dodopayments.com",live:"https://api.hs.dodopayments.com"},d="\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",u="\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",f=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 h(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 m(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 y(e){var t=function(e){return"".concat(s[e],"/").concat(l,"/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 w(e){if(!e.mode)throw new Error("Checkout mode is required");if(!Object.keys(a).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 v(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 g=null;function b(){var e;if(null!==(e=g)&&void 0!==e&&e.wrapperDiv){var t=g.walletElementContainer,n=!!t&&"hidden"!==t.style.visibility?t.offsetHeight||44:0;g.wrapperDiv.style.height="".concat(g.lastCheckoutIframeHeight+n,"px")}}function k(e){if(g&&e.origin===g.allowedOrigin)try{var t=e.data;if(!t||!t.event_type)return;if(!f.has(t.event_type))return void console.warn("Received message with invalid event_type: ".concat(t.event_type));if(z(t.event_type,t.data||{}),"checkout.closed"===t.event_type&&setTimeout(function(){return E(!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{v(o),window.location.href=o}catch(e){console.error("Invalid redirect URL:",e),z("checkout.error",{message:"Invalid redirect URL"})}}if(t.event_type,"checkout.keys_provided"===t.event_type&&"inline"===g.config.displayType){var i,r,a=null===(i=t.data)||void 0===i?void 0:i.message;if(!a||"string"!=typeof a.publishable_key||"string"!=typeof a.client_secret_key)return console.error("Invalid keys_provided payload:",a),void z("checkout.error",{message:"Wallet initialization failed - invalid key data"});(null!==(r=g.dodoScriptPromise)&&void 0!==r?r:Promise.resolve()).then(function(){try{!function(e,t,n){if(!g)throw new Error("Checkout not initialized");var o=window.DodoCheckoutWebSDK;if(!o)throw new Error("Dodo SDK not loaded");var i=g.config.mode,r=c[i],a="".concat(s[i],"/").concat(l);try{var d=o.loadDodoPayments(e,{apiUrl:r,baseUrl:a});g.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");g.walletElement=u,u.on("paymentresult",function(e){var t=e;if(t.paymentIntent){z("checkout.status",{status:t.paymentIntent.status,paymentIntent:t.paymentIntent});var o=n||t.paymentIntent.return_url;if(o){try{v(o)}catch(e){return console.error("Invalid wallet return URL:",o),void z("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),z("checkout.error",{message:"Wallet payment failed"}))}});var f=g.walletElementContainer;if(f){if(u.on("ready",function(){var e;if(null!==(e=g)&&void 0!==e&&e.walletElementContainer){var t=g.walletElementContainer;t.style.visibility="visible",t.style.height="auto",t.style.overflow="visible"}b()}),u.on("loaderror",function(){var e;if(null!==(e=g)&&void 0!==e&&e.walletElementContainer){var t=g.walletElementContainer;t.style.visibility="hidden",t.style.height="0",t.style.overflow="hidden"}b()}),"undefined"!=typeof ResizeObserver){var p=new ResizeObserver(function(){return b()});p.observe(f),g.walletResizeObserver=p}u.mount("#".concat(f.id))}}catch(e){throw console.error("Failed to initialize Dodo wallet:",e),g.walletElementContainer&&(g.walletElementContainer.style.display="none"),e}}(a.publishable_key,a.client_secret_key,a.return_url)}catch(e){console.error("Error initializing Dodo wallet:",e),z("checkout.error",{message:"Failed to initialize wallet"})}},function(){})}}catch(e){console.error("Error processing checkout message:",e),z("checkout.error",{message:"Failed to process message"})}}function z(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(g)if(f.has(e)){var o=i(i({},n),{},{products:g.currentProducts,timestamp:Date.now()});if(g.config.onEvent)try{g.config.onEvent({event_type:e,data:o})}catch(t){console.error("Error in onEvent handler for ".concat(e,":"),t)}null!==(t=g.eventListeners[e])&&void 0!==t&&t.length&&g.eventListeners[e].forEach(function(t){try{t(o)}catch(t){console.error("Error in ".concat(e," event handler:"),t)}})}else console.warn("Attempted to emit invalid event type: ".concat(e))}function E(){var e,t,n,o=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(null!==(e=g)&&void 0!==e&&e.container||null!==(t=g)&&void 0!==t&&t.iframe||null!==(n=g)&&void 0!==n&&n.wrapperDiv)try{if(g.container?(g.container.remove(),g.container=null):g.wrapperDiv?(g.wrapperDiv.remove(),g.wrapperDiv=null):g.iframe&&g.iframe.remove(),g.iframe=null,g.currentProducts=[],g.iframeResizerInstance&&g.iframeResizerInstance.length>0&&(g.iframeResizerInstance.forEach(function(e){e.iFrameResizer.close()}),g.iframeResizerInstance=null),g.walletResizeObserver&&(g.walletResizeObserver.disconnect(),g.walletResizeObserver=null),g.walletElement){try{g.walletElement.destroy()}catch(e){console.error("Error destroying wallet element:",e)}g.walletElement=null}g.walletElementContainer&&(g.walletElementContainer.remove(),g.walletElementContainer=null),g.dodoInstance=null,g.dodoScriptPromise=null,g.lastCheckoutIframeHeight=0,document.body.style.overflow="",document.body.style.contain="",o&&z("checkout.closed",{message:"Checkout closed manually"})}catch(e){throw console.error("Error closing checkout:",e),z("checkout.error",{message:"Failed to close checkout"}),e}}function I(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var T,R,x,O={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 j(){return T||(T=1,function(e,t){!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",f=Object.freeze({assert:!0,error:!0,warn:!0}),p={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={...p,expand:!e.collapsed||p.expanded,...e};let s="";function v(){a.length=0,s=""}function g(){delete l.event,v()}const E=()=>a.some(([e])=>e in f),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 C(e,...t){!0!==e&&P("assert",e,...t)}function D(e=c){r[e]?r[e]+=1:r[e]=1,P(u,`${e}: ${r[e]}`)}function S(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 _=e=>[e,(...t)=>P(e,...t)];return{...z(l,k(l)),...z(console,_),...z(h,b),assert:C,count:D,countReset:S,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"}})}(t)}(0,O.exports)),O.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 P=function(){if(x)return R;x=1;const e=j(),t="5.5.7",n="iframeResizer",o=":",i="autoResize",r="init",a="iframeReady",l="load",s="message",c="onload",d="pageInfo",u="parentInfo",f="reset",p="resize",h="scroll",m="child",y="parent",w="string",v="object",g="function",b="auto",k="none",z="vertical",E="horizontal",I="[iFrameSizer]",T=Object.freeze({max:1,scroll:1,bodyScroll:1,documentElementScroll:1}),O=Object.freeze({[c]:1,[r]:1,[a]:1}),P="expanded",L="collapsed",C=Object.freeze({[P]:1,[L]:1}),D=(e,t,n,o)=>e.addEventListener(t,n,o||!1),S=(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"],_=["<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."],N=["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(_[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>","[31;1m").replaceAll("</>","[m").replaceAll("<b>","[1m").replaceAll("<i>","[3m").replaceAll("<u>","[4m")):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(N),me(W),$("onResized",N)}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,p,r)}function s(){ne(c,`stop${t}`),a(0,S),d.disconnect(),u.disconnect(),S(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,D(q[c].iframe,l,s),a(0,D),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=N.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}=N,{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 pe(),{x:Number(t.left)+Number(se.position.x),y:Number(t.top)+Number(se.position.y)}}function P(t){const n=t?j(N.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,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 C(e){let t={};if(0===N.width&&0===N.height){const e=v(9).split(o);t={x:e[1],y:e[0]}}else t={x:N.width,y:N.height};$(e,{iframe:N.iframe,screenX:Number(t.x),screenY:Number(t.y),type:N.type})}const $=(e,t)=>de(W,e,t);function A(){const{height:n,iframe:o,msg:l,type:c,width:p}=N;switch(q[W]?.firstRun&&(q[W]&&(Ee(W,N.mode),q[W].firstRun=!1)),c){case"close":fe(o);break;case s:m=v(6),$("onMessage",{iframe:N.iframe,message:JSON.parse(m)});break;case"mouseenter":C("onMouseEnter");break;case"mouseleave":C("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=N.width,n=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 f:ye(N);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===p&&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===p||0===n)return;if(document.hidden)return;a()}var h,m}let U=n.data;if("[iFrameResizerChild]Ready"===U)return _=n.source,void Object.values(q).forEach((e=>({initChild:t,postMessageTarget:n})=>{e===n&&t()})(_));var _;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 N=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}=N,W=H;W?(ne(W,M),ie(W,function(e){(function(e){if(!q[e])throw new Error(`${N.type} No settings for ${e}. Message was: ${U}`)})(W),N.type in{true:1,false:1,undefined:1}||(null!==N.iframe||(ee(W,`The iframe (${N.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 ${N.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 fe(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 pe(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){pe(e.id),we(e),ge(f,f,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 O?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 O?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(N[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,p)}const Te=(e=>{let t=!1;return function(){return t?void 0:(t=!0,Reflect.apply(e,this,arguments))}})(()=>{D(window,s,ce),D(document,"visibilitychange",Ie),window.iframeParentListener=e=>setTimeout(()=>ce({data:e,sameOrigin:!0}))});return R=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[R]?.heightCalculationMethod in T&&ye({iframe:d,height:1,width:1,type:r})},{iframe:o}=q[e];q[e].initChild=n(a),function(e,t){D(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 f(e){return e?(("sizeWidth"in e||"sizeHeight"in e||i in e)&&re(R,`<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[R],e)&&(re(R,`<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[R][t]=q[R][e],delete q[R][e])}const g=e=>G(e,"onMouseEnter")||G(e,"onMouseLeave");function I(t){var n,o;q[R]={...q[R],iframe:d,remoteHost:d?.src.split("/").slice(0,3).join("/"),...le,...f(t),mouseEvents:g(t),mode:W(t),syncTitle:h(R)},y("offset","offsetSize"),y("onClose","onBeforeClose"),y("onClosed","onAfterClose"),ne(R,"setup"),function(){const{direction:e}=q[R];switch(e){case z:break;case E:q[R].sizeHeight=!1;case"both":q[R].sizeWidth=!0;break;case k:q[R].sizeWidth=!1,q[R].sizeHeight=!1,q[R].autoResize=!1;break;default:throw new TypeError(R,`Direction value of "${e}" is not valid`)}}(),(n=t?.offsetSize||t?.offset)&&(q[R].direction===z?q[R].offsetHeight=n:q[R].offsetWidth=n),function(e){e?.offset&&re(R,"<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[R].warningTimeout||Q(R,"warningTimeout:%c disabled",e.HIGHLIGHT),null===q[R].postMessageTarget&&(q[R].postMessageTarget=d.contentWindow),q[R].targetOrigin=!0===q[R].checkOrigin?""===(o=q[R].remoteHost)||null!==o.match(/^(about:blank|javascript:|file:\/\/)/)?"*":o:"*"}const R=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 C)&&te(e,'Invalid value for options.log: Accepted values are "expanded" and "collapsed"'),t.log=i}(R,t),ie(R,function(e){n in d?ee(R,`Ignored iframe (${R}), already setup.`):(I(e),function(){if(ke)return;const{mode:e}=q[R];-1!==e&&Ee(R,e)}(),Te(),function(){switch(d.style.overflow=!1===q[R]?.scrolling?"hidden":b,q[R]?.scrolling){case"omit":break;case!0:d.scrolling="yes";break;case!1:d.scrolling="no";break;default:d.scrolling=q[R]?q[R].scrolling:"no"}}(),function(){const{bodyMargin:e}=q[R];"number"!=typeof e&&"0"!==e||(q[R].bodyMargin=`${e}px`)}(),u(R,function(e){const{autoResize:t,bodyBackground:n,bodyMargin:i,bodyPadding:r,heightCalculationMethod:a,inPageLinks:l,license:s,log:c,logExpand:d,mouseEvents:u,offsetHeight:f,offsetWidth:p,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,f,p,y,s,se.version,h,"",d].join(o)}(R)),function(){if(q[R]){const{iframe:e}=q[R],t={close:fe.bind(null,e),disconnect:ue.bind(null,e),removeListeners(){re(R,"<rb>Deprecated Method Name</>\n\nThe [removeListeners()</> method has been renamed to [disconnect()</>.\n"),this.disconnect()},resize(){re(R,"<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",p,R)},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}`,R)},sendMessage(e){e=JSON.stringify(e),ge(s,`${s}:${e}`,R)}};e.iframeResizer=t,e.iFrameResizer=t}}())})(t),d?.iframeResizer}}(),L=I(P);
/*!
* @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 C="undefined",D="[iframeResizer] ";const S=function(){function e(e){switch(!0){case!e:throw new TypeError(`${D}iframe is not defined`);case!e.tagName:throw new TypeError(`${D}Not a valid DOM element`);case"IFRAME"!==e.tagName.toUpperCase():throw new TypeError(`${D}Expected <IFRAME> tag, found <${e.tagName}>`);default:t(e),n.push(e)}}let t,n;return function(o,i){if(typeof window===C)return[];switch(t=L(o),n=[],typeof i){case C:case"string":document.querySelectorAll(i||"iframe").forEach(e);break;case"object":e(i);break;default:throw new TypeError(`${D}Unexpected data type (${typeof i})`)}return Object.freeze(n)}}();var $=null;function A(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 U(e){var t,n=e.products,o=e.paymentLink,i=e.queryParams,a=e.redirectUrl,c=e.checkoutUrl,f=e.elementId,p=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."),i&&console.warn("⚠️ DEPRECATION WARNING: 'queryParams' option is deprecated and will be removed in v2.0.0. Please include query parameters in your 'checkoutUrl' instead."),a&&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)),!$)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,$.config.displayType),$.iframe||$.container)console.warn("Checkout is already open");else{if(a&&v(a),c&&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")}}(c),"session"===$.config.linkType){if(!c)throw new Error("checkoutUrl is required for session checkout")}else if("static"===$.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"===$.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),$.currentProducts=n||[];try{!function(e,t,n,o,i,a,c){if(!$)return;var f,p=$.config.displayType||"overlay";if("session"===$.config.linkType&&i){var h=N(i,p,c);f=new URL(h)}else if("static"===$.config.linkType&&null!=e&&e[0])f=function(e,t,n){if(!$)throw new Error("Checkout not initialized");if(!$.config.displayType)throw new Error("Display type not specified");var o="inline"===$.config.displayType?"inline":"overlay",i=new URL("".concat($.baseUrl,"/").concat(o,"/buy/").concat(e.productId),window.location.origin);t&&Object.entries(t).forEach(function(e){var t=r(e,2),n=t[0],o=t[1];i.searchParams.append(n,o)});n&&i.searchParams.append("redirect_url",n);i.searchParams.append("quantity",e.quantity.toString()),$.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 i.searchParams.append("theme",$.config.theme||"light"),i}(e[0],n,o);else{if("dynamic"!==$.config.linkType||!t)throw new Error("Invalid checkout configuration");f=function(e){if(!$)throw new Error("Checkout not initialized");if(!$.config.displayType)throw new Error("Display type not specified");var t="inline"===$.config.displayType?"inline":"overlay",n=new URL("".concat($.baseUrl,"/").concat(t,"/").concat(e),window.location.origin);$.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",$.config.theme||"light"),n}(t)}var m=document.createElement("iframe");if(m.id=$.iframeId,m.src=f.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"===p){var y=a?document.getElementById(a):null;if(!y)throw new Error('Target element with ID "'.concat(a,'" not found for inline checkout.'));var w=function(){if(!$)return Promise.reject(new Error("Checkout not initialized"));var e="".concat(s[$.config.mode],"/").concat(l,"/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"))}),A(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 A(e,t)},n.onerror=function(){t(new Error("Failed to load Dodo SDK script"))},document.head.appendChild(n)})}();$.dodoScriptPromise=w,w.catch(function(e){var t;console.error("Failed to inject Dodo SDK:",e),null!==(t=$)&&void 0!==t&&t.walletElementContainer&&($.walletElementContainer.style.display="none"),z("checkout.error",{message:"Wallet initialization failed"})});var v=document.createElement("div"),g="dodo-wallet-".concat(Date.now());v.id=g,v.style.cssText=u+" visibility: hidden; height: 0; overflow: hidden;",$.walletElementContainer=v;var k=document.createElement("div");k.style.cssText="\n display: flex;\n flex-direction: column;\n height: 0px;\n overflow-y: auto;\n transition: height 0.2s ease-out;\n ",$.wrapperDiv=k,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 ",k.appendChild(v),k.appendChild(m),y.appendChild(k),$.iframe=m,$.container=null;var E={license:"GPLv3",checkOrigin:[$.allowedOrigin],direction:"vertical",log:!1,warningTimeout:15e3,onResized:function(e){$&&($.lastCheckoutIframeHeight=e.height,b())}};$.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=d,x.appendChild(m),R.appendChild(x),document.body.style.overflow="hidden",document.body.style.contain="initial",document.body.appendChild(R),$.iframe=m,$.container=R}}(n,t,i,a,c,f,p)}catch(e){throw console.error("Error creating checkout:",e),z("checkout.error",{message:"Failed to create checkout"}),e}}}function _(e,t,n){t&&Object.entries(t).forEach(function(t){var o=r(t,2),i=o[0],a=o[1];a&&e.searchParams.append("".concat(n,"_").concat(i),String(a))})}function N(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 f=o.themeConfig;_(t,f.light,"theme"),_(t,f.dark,"theme_dark"),f.radius&&t.searchParams.append("theme_radius",f.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 p=t.toString();if(!p.includes("/".concat(r,"/")))throw new Error("Internal error: Failed to build overlay URL");return p}var H={Initialize:function(e){if(w(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."),$)!function(e){if(!$)throw new Error("Checkout not initialized");w(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||$.config.onEvent;$.config=i(i({linkType:"session"},e),{},{onEvent:t}),$.baseUrl!==a[e.mode]&&($.baseUrl=a[e.mode],$.allowedOrigin=new URL($.baseUrl).origin)}(e);else{var t=a[e.mode],n=new URL(t).origin;$={iframe:null,container:null,config:i({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},g=$,window.addEventListener("message",k),function(e){var t=e.mode,n=e.displayType;try{var o=new URL(a[t]);if(h(o.origin),m(o.origin),"inline"===n){var i=new URL(s[t]),r=new URL(c[t]);h(i.origin,!1),m(i.origin),h(r.origin),m(r.origin)}}catch(e){console.warn("Failed to inject resource hints:",e)}}({mode:e.mode,displayType:e.displayType}),"inline"===e.displayType&&y(e.mode)}},Checkout:{open:function(e){U(e)},close:E,isOpen:function(){var e,t;return!!(null!==(e=$)&&void 0!==e&&e.iframe||null!==(t=$)&&void 0!==t&&t.container)},buildUrl:N}};e.DodoPayments=H,Object.defineProperty(e,"__esModule",{value:!0})});