1import{S as T}from"./D0HDmefO.js";import{e as W,s as B,m as h,E as i,i as R,L as j,c,a as s,g as v,b as L,t as D,d as S,z as M,p as V,o as u}from"./D3mXZbvm.js";const K={class:"min-h-screen bg-gray-50 pt-20 pb-12 px-4 sm:px-6 lg:px-8"},$={class:"max-w-4xl mx-auto"},F={class:"bg-white shadow-sm rounded-2xl p-6 md:p-8 border border-gray-100"},H={key:0,class:"flex justify-center py-14"},X={key:1,class:"rounded-lg border border-red-200 bg-red-50 p-4 text-red-700"},G={key:2,class:"text-sm text-gray-500 space-y-2"},J={key:0},Q={key:1,class:"rounded-xl border border-red-200 bg-red-50 px-4 py-3 text-red-900"},Y={class:"flex items-start gap-3"},ne=W({__name:"pay",setup(Z){const d=B(),_=M(),b=h(!0),m=h(""),l=h(!1),w=i(()=>{const e=d.query._ptxn;return Array.isArray(e)?e[0]:e}),a=i(()=>{const e=d.query.paymentUrl;return Array.isArray(e)?e[0]:e}),k=i(()=>{const e=d.query.orderId;return Array.isArray(e)?e[0]:e}),y=i(()=>_.public?.paddleClientToken),E=i(()=>_.public?.paddleEnvironment),p=i(()=>{if(k.value)return`${window.location.origin}/order/${k.value}`}),P=()=>{window.location.reload()},x=()=>{const e=window.Paddle;if(!e||!w.value)return;const n=(Array.isArray(d.query.successUrl)?d.query.successUrl[0]:d.query.successUrl)||p.value;l.value=!1,e.Checkout.open({transactionId:w.value,settings:{displayMode:"overlay",...n?{successUrl:n}:{}}})},q=async()=>{window.Paddle||await new Promise((t,n)=>{const o=document.querySelector('script[data-paddle-script="true"]');if(o){o.addEventListener("load",()=>t(),{once:!0}),o.addEventListener("error",()=>n(new Error("Unable to load Paddle script.")),{once:!0});return}const r=document.createElement("script");r.src="https://cdn.paddle.com/paddle/v2/paddle.js",r.async=!0,r.dataset.paddleScript="true",r.onload=()=>t(),r.onerror=()=>n(new Error("Unable to load Paddle script.")),document.head.appendChild(r)})},z=async()=>{window.LemonSqueezy||await new Promise((t,n)=>{const o=document.querySelector('script[data-lemon-script="true"]');if(o){o.addEventListener("load",()=>t(),{once:!0}),o.addEventListener("error",()=>n(new Error("Unable to load Lemon.js script.")),{once:!0});return}const r=document.createElement("script");r.src="https://app.lemonsqueezy.com/js/lemon.js",r.async=!0,r.dataset.lemonScript="true",r.onload=()=>t(),r.onerror=()=>n(new Error("Unable to load Lemon.js script.")),document.head.appendChild(r)})},g=()=>{if(!a.value)return;const e=C(a.value),t=window;if(typeof t.createLemonSqueezy=="function"){t.createLemonSqueezy();const o=document.createElement("a");o.href=e,o.className="lemonsqueezy-button",o.style.display="none",document.body.appendChild(o),l.value=!1,o.click(),setTimeout(()=>o.remove(),0);return}const n=t.LemonSqueezy;if(n?.Url?.Open){l.value=!1,n.Url.Open(e);return}window.location.href=e},f=e=>{try{return new URL(e,window.location.origin).hostname.includes("lemonsqueezy.com")}catch{return!1}},C=e=>{try{const t=new URL(e,window.location.origin);return t.searchParams.set("embed","1"),t.toString()}catch{return e}},U=e=>{const t=f(e)?C(e):e;window.location.href=t},I=async()=>{if(!w.value)return!1;if(!y.value)throw new Error("Missing Paddle token. Set NUXT_PUBLIC_PADDLE_CLIENT_TOKEN.");if(y.value.startsWith("pdl_"))throw new Error("Invalid Paddle token type. Use a client-side token (test_/live_), not an API key (pdl_*).");try{await q();const e=window.Paddle;if(!e)throw new Error("Paddle SDK unavailable.");return(E.value||(y.value.startsWith("test_")?"sandbox":"production"))==="sandbox"&&e.Environment?.set("sandbox"),window.__rwPaddleInitialized||(e.Initialize({token:y.value,eventCallback:n=>{n?.name==="checkout.completed"&&p.value&&(window.location.href=p.value),n?.name==="checkout.closed"&&(l.value=!0)}}),window.__rwPaddleInitialized=!0),x(),!0}catch(e){throw e}},A=async()=>{if(!a.value||!f(a.value))return!1;await z(),window.createLemonSqueezy?.();const e=window.LemonSqueezy;return!window.__rwLemonInitialized&&e.Setup&&(e.Setup({eventHandler:t=>{const n=String(t?.event||t?.name||"").toLowerCase();n.includes("close")&&(l.value=!0),(n.includes("success")||n.includes("complete"))&&p.value&&(window.location.href=p.value)}}),window.__rwLemonInitialized=!0),g(),!0},N=()=>
1{if(w.value){x();return}if(a.value&&f(a.value)){g();return}if(a.value){U(a.value);return}},O=async()=>{try{if(await I()||await A())return;if(a.value){U(a.value);return}m.value="Missing payment data. Expected either _ptxn or paymentUrl query parameter."}catch(e){m.value=e?.message||"Failed to initialize checkout."}finally{b.value=!1}};return R(()=>{O()}),j(()=>{window.Paddle?.Checkout?.close?.(),window.LemonSqueezy?.Url?.Close?.()}),(e,t)=>{const n=V("font-awesome-icon");return u(),c("div",K,[s("div",$,[s("div",F,[t[3]||(t[3]=s("h1",{class:"text-2xl font-bold text-gray-900 mb-2"},"Secure Checkout",-1)),t[4]||(t[4]=s("div",{class:"mb-6"},null,-1)),v(b)?(u(),c("div",H,[L(T,{size:"lg",color:"primary"})])):v(m)?(u(),c("div",X,D(v(m)),1)):(u(),c("div",G,[v(l)?(u(),c("div",Q,[s("div",Y,[L(n,{icon:"times-circle",class:"w-5 h-5 mt-0.5 shrink-0 text-red-600"}),s("div",null,[t[2]||(t[2]=s("p",{class:"text-base font-semibold leading-tight"},"Payment was canceled",-1)),s("button",{type:"button",class:"mt-1 text-sm font-bold text-red-700 hover:text-red-800 underline underline-offset-2",onClick:N}," Reopen checkout ")])])])):(u(),c("p",J,[t[0]||(t[0]=S(" Checkout opened in overlay. If it does not appear, ",-1)),s("button",{type:"button",class:"text-primary hover:underline font-medium",onClick:P}," refresh this page "),t[1]||(t[1]=S(". ",-1))]))]))])])])}}});export{ne as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.