1import{r as o,j as e}from"./vendor-core-CA_KrXkh.js";import{s as m,Q as T,au as A,bc as L,a0 as U,f as v,a9 as M,e as b,bd as D,be as F,v as _}from"./forms-shared-Dc5lKFyO.js";import"./vendor-query-BOdIo_rz.js";import"./vendor-datefns-CjGiTsLL.js";import"./vendor-radix-CGmIVij6.js";import"./vendor-supabase-0zESqXVX.js";import"./vendor-office-n4PctmjL.js";import"./vendor-charts-JBu1_W-B.js";function G(){const[a,r]=o.useState("loading"),[x,u]=o.useState(""),[p,C]=o.useState(""),[f,h]=o.useState(3),[g,E]=o.useState("/v2/a/dashboard");o.useEffect(()=>{const s=Object.fromEntries(new URLSearchParams(window.location.search)),c=s.type,y=s.agency_id,P=s.plan_id,i=s.txn_id,n=(s.status||"").toUpperCase();if(C(i||s.transaction_id||""),!y||!i||!n){r("invalid");return}if(n==="EXPIRED"||n==="TIMEOUT"){r("expired");return}if(n==="FAILED"||n==="CANCELLED"||n==="FAILURE"){r("failed");return}if(n==="SUCCESS"){(async()=>{var j,N;try{const{data:t,error:d}=await m.functions.invoke("billing-payment-confirm",{body:{agency_id:y,plan_id:P,merchant_txn_id:i,gateway_txn_id:s.transaction_id||s.txnId||i,amount_paise:Math.round(parseFloat(s.paid_amount||"0")*100),payment_type:c,upgrade_to_plan_id:s.to_plan_id||void 0}});if(d||!(t!=null&&t.success)){u((t==null?void 0:t.error)||(d==null?void 0:d.message)||"Activation failed"),r("error");return}try{const{data:S}=await m.auth.getSession(),w=(N=(j=S.session)==null?void 0:j.user)==null?void 0:N.id;if(w){const{data:l}=await m.from("user_roles").select("role").eq("user_id",w),I=l==null?void 0:l.some(k=>k.role==="super_admin");E(I?"/v2/x/agencies":"/v2/a/dashboard")}}catch{}r("success")}catch(t){u((t==null?void 0:t.message)||"Network error"),r("error")}})();return}r("invalid")},[]),o.useEffect(()=>{if(a!=="success")return;let s=3;h(3);const c=setInterval(()=>{s-=1,h(s),s<=0&&(clearInterval(c),window.location.href=g)},1e3);return()=>clearInterval(c)},[a,g]);const R=async()=>{try{await F(p),_.success("Reference copied")}catch{_.error("Could not copy")}};return e.jsx("div",{className:"min-h-screen w-full flex items-center justify-center bg-card px-4",children:e.jsxs("div",{className:"w-full max-w-md text-center",children:[a==="loading"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(T,{className:"w-12 h-12 mx-auto animate-spin text-foreground"}),e.jsx("p",{className:"text-lg font-medium text-foreground",children:"Verifying your payment..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait, do not close this window."})]}),a==="success"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(A,{className:"w-20 h-20 mx-auto text-green-600"}),e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:"Payment successful!"}),e.jsx("p",{className:"text-muted-foreground",children:"Your plan is now active."}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Redirecting you to the dashboard in ",f,"s..."]}),e.jsx(L,{value:(3-f)/3*100,className:"h-2"})]}),a==="failed"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(U,{className:"w-20 h-20 mx-auto text-red-600"}),e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:"Payment was not completed"}),e.jsx("p",{className:"text-muted-foreground",children:"Your account has not been charged."}),e.jsxs("div",{className:"flex flex-col gap-2 pt-2",children:[e.jsx(v,{onClick:()=>window.history.back(),children:"Try again"}),e.jsx("a",{href:"mailto:[email protected]",className:"text-sm text-muted-foreground underline",children:"Contact support"})]})]}),a==="expired"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(M,{className:"w-20 h-20 mx-auto text-amber-500"}),e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:"Payment session expired"}),e.jsx("p",{className:"text-muted-foreground",children:"Please request a new payment link from your administrator."})]}),a==="error"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(b,{className:"w-20 h-20 mx-auto text-amber-500"}),e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:"Payment received but activation failed"}),e.jsx("p",{className:"text-muted-foreground",children:"Please contact support with this reference."}),e.jsxs("div",{className:"rounded-md border border-border bg-muted px-3 py-2 text-sm font-mono text-gray-800",children:["Reference: ",p||"â"]}
1),x&&e.jsx("p",{className:"text-xs text-muted-foreground",children:x}),e.jsxs(v,{variant:"outline",onClick:R,className:"gap-2",children:[e.jsx(D,{className:"w-4 h-4"})," Copy reference"]})]}),a==="invalid"&&e.jsxs("div",{className:"space-y-5",children:[e.jsx(b,{className:"w-20 h-20 mx-auto text-amber-500"}),e.jsx("h1",{className:"text-2xl font-semibold text-foreground",children:"Invalid payment return"}),e.jsx("p",{className:"text-muted-foreground",children:"Contact support."})]})]})})}export{G 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.