PageSourceSearch

https://coachpeterchinnappa.com/assets/PaymentLinkCheckout-BC4Q5JM5.js

js coachpeterchinnappa.com collected 2026-10-08 11:06:17 UTC 10,367 bytes, 1 lines download raw bytes

1import{u as q,r as i,j as e}from"./vendor-core-CA_KrXkh.js";import{a as P}from"./vendor-query-BOdIo_rz.js";import{s as _,v as x,au as S,a3 as D,a4 as R,aD as F,e as L,a5 as T,b5 as M,M as $}from"./forms-shared-Dc5lKFyO.js";import{e as A,a as f}from"./payment-orchestrator-D2B5824I.js";import{u as G}from"./useHeatmapCapture-BhybflP6.js";import{f as z}from"./useUniversalTracking-BqiAcC-k.js";import{g as B}from"./currency-data-bC_t28LN.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";import"./attributionSnapshot-B9HswrT3.js";import"./trackedParameters-B5xTCyu1.js";import"./razorpay-checkout-2cN3Xqsc.js";import"./calendar-payment-events-Dus9i-QQ.js";function U(n){return B(n)||n||"₹"}function g(n,r){return`${U(r)}${n.toLocaleString("en-IN",{minimumFractionDigits:2,maximumFractionDigits:2})}`}function le(){const{linkId:n}=q(),[r,h]=i.useState(()=>{const t=new URLSearchParams(window.location.search);return{name:t.get("name")||"",email:t.get("email")||"",phone:t.get("phone")||""}}),[l,u]=i.useState({}),[b,j]=i.useState(!1),[N,C]=i.useState(!1),[w,c]=i.useState(null),[m,v]=i.useState("razorpay"),{data:s,isLoading:E,error:I}=P({queryKey:["payment-link",n],queryFn:async()=>{if(!n)throw new Error("No link ID");const{data:t,error:a}=await _.from("finance_payment_links").select("*").eq("id",n).single();if(a)throw a;return t},enabled:!!n});G({subAccountId:(s==null?void 0:s.sub_account_id)??void 0});const{data:p}=P({queryKey:["payment-link-paid-proposal",n],queryFn:async()=>{const{data:t}=await _.from("agency_proposals").select("id").eq("body_json->payment_section->>payment_link_id",n).eq("body_json->payment_section->>payment_status","paid").maybeSingle();return t},enabled:!!n}),d=i.useMemo(()=>{const t=s==null?void 0:s.payment_gateway_preference;if(!t)return["razorpay"];const a=String(t).split(",").map(y=>y.trim()).filter(Boolean);return a.length>0?a:["razorpay"]},[s]);i.useEffect(()=>{d.length>0&&!d.includes(m)&&v(d[0])},[d]);const k=i.useCallback(async()=>{if(!s)return;if(p){c("This has already been paid.");return}const t={};if(r.name.trim()||(t.name="Required"),(!r.email.trim()||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(r.email))&&(t.email="Valid email required"),r.phone.trim()||(t.phone="Required"),Object.keys(t).length){u(t);return}j(!0),c(null);try{const a=s.sub_account_id||s.agency_id;if(!a)throw new Error("Payment link is not configured properly");const o=await A({gateway:m,tenantId:a,amount:s.amount,currency:s.currency||"INR",entityType:"payment_link",entityId:s.id,customerName:r.name,customerEmail:r.email,customerPhone:r.phone,productName:s.name||"Payment"});if(o.status==="redirecting"||o.status==="cancelled")return;if(o.status==="failed"){c(o.error||"Payment failed. Please try again."),x.error(o.error||"Payment failed");return}if(o.status==="timeout"){c("Payment timed out. Please try again."),x.error("Payment timed out. Please try again.");return}if(o.success){C(!0),x.success("Payment successful! 🎉");try{z({subAccountId:a,eventName:"purchase",sourceModule:"payment_link",sourceEntityId:s.id,value:Number(s.amount)||0,currency:s.currency||"INR",userData:{email:r.email,phone:r.phone,firstName:r.name},customData:{link_id:s.id,link_name:s.name}})}catch{}}else o.status==="not_connected"&&c("No payment gateway connected for this account. Please contact the seller.")}catch(a){a.message==="Payment cancelled by user"||a.failure_type==="modal_dismiss"||(c(a.message||"Payment failed. Please try again."),x.error(a.message||"Payment failed"))}finally{j(!1)}},[s,r,m,p]);return E?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-blue-50 flex items-center justify-center",children:e.jsx("div",{className:"h-8 w-8 border-4 border-blue-500 border-t-transparent rounded-full animate-spin"})}):I||!s?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-blue-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center max-w-md",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Link Not Found"}),e.jsx("p",{className:"text-gray-600",children:"This payment link may have expired or doesn't exist."})]})}):p&&!N?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-green-50 to-emerald-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center max-w-md bg-white rounded-2xl shadow-xl p-8",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(S,{className:"h-8 w-8 text-green-600"})}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Already paid"}),e.jsx("p",{className:"text-gray-600",children:"This proposal has already been paid for — no further payment is needed."})]})}):N?e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-green-50 to-emerald-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"text-center max-w-md bg-white rounded-2xl shadow-xl p-8",children:[e.jsx("div",{className:"w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4",children:e.jsx(S,{className:"h-8 w-8 text-green-600"})}),e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-2",children:"Payment Successful!"}),e.jsxs("p",{className:"text-gray-600 mb-1",children:["Thank you, ",r.name,"."]}),e.jsxs("p",{className:"text-gray-600",children:["Your payment of ",e.jsx("strong",{children:g(s.amount,s.currency||"INR")})," has been received."]})]})}):e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-slate-50 to-blue-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"w-full max-w-md bg-white rounded-2xl shadow-xl overflow-hidden",children:[e.jsxs("div",{className:"bg-gradient-to-r from-blue-600 to-indigo-700 text-white p-6",children:[e.jsx("h1",{className:"text-xl font-bold",children:s.name||"Payment"}),e.jsx("p",{className:"text-3xl font-bold mt-2",children:g(s.amount,s.currency||"INR")})]}),e.jsxs("div",{className:"p-6 space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:"Your Details"}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Full Name *"}),e.jsxs("div",{className:"relative",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx("input",{className:`w-full pl-10 pr-4 py-2.5 border rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none ${l.name?"border-red-400":"border-gray-300"}`,placeholder:"Enter your name",value:r.name,onChange:t=>{h(a=>({...a,name:t.target.value})),u(a=>({...a,name:""}))}})]}),l.name&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:l.name})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Email *"}),e.jsxs("div",{className:"relative",children:[e.jsx(R,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400"}),e.jsx("input",{className:`w-full pl-10 pr-4 py-2.5 border rounded-lg text-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500 outline-none ${l.email?"border-red-400":"border-gray-300"}`,placeholder:"[email protected]",type:"email",value:r.email,onChange:t=>{h(a=>({...a,email:t.target.value})),u(a=>({...a,email:""}))}})]}),l.email&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:l.email})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-700 mb-1",children:"Phone *"}),e.jsx(F,{hideLabel:!0,value:r.phone,onChange:t=>{h(a=>({...a,phone:t})),u(a=>({...a,phone:""}))},hasError:!!l.phone,placeholder:"Enter phone number",className:"space-y-0"}),l.phone&&e.jsx("p",{className:"text-xs text-red-500 mt-1",children:l.phone})]}),w&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-red-50 border border-red-200 rounded-lg",children:[e.jsx(L,{className:"h-4 w-4 text-red-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-red-700",children:w}),e.jsx("button",{onClick:()=>{c(null),k()},className:"text-xs text-red-600 underline mt-1",children:"Try again"})]})]}),d.length>1&&e.jsxs("div",{className:"w-full space-y-3 text-left",children:[e.jsxs("div",{children:[e.jsx("span",{className:"block text-sm font-medium text-gray-700 mb-2",children:"Pay with"}),e.jsx("div",{className:"flex flex-wrap gap-x-6 gap-y-2.5 items-center",children:d.map(t=>{const a=f(t);return e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm shrink-0",children:[e.jsx("input",{type:"radio",name:"link-checkout-gateway",checked:m===t,onChange:()=>v(t),className:"accent-blue-600 h-4 w-4 shrink-0 mt-px"}),e.jsx("span",{className:"font-medium text-gray-700 leading-none",children:a.label})]},t)})})]}),(()=>{const t=f(m);return e.jsxs("div",{className:"w-full border border-dashed border-green-400 rounded-lg p-4 text-left bg-green-50/30",children:[e.jsx("p",{className:"text-xs text-green-600 font-medium mb-1",children:"Completing payment with"}),e.jsx("p",{className:"text-xl sm:text-2xl font-bold",style:{color:t.brandColor||"#333"},children:t.poweredBy==="Demo"?"🧪 Demo":t.poweredBy||t.label})]})})()]}),e.jsx("button",{onClick:k,disabled:b,className:"w-full py-3 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-semibold rounded-xl hover:from-blue-700 hover:to-blue-800 transition-all shadow-lg shadow-blue-500/25 flex items-center justify-center gap-2 disabled:opacity-60",children:b?e.jsx("div",{className:"h-5 w-5 border-2 border-white border-t-transparent roun
1ded-full animate-spin"}):e.jsxs(e.Fragment,{children:[e.jsx(T,{className:"h-4 w-4"}),"Pay ",g(s.amount,s.currency||"INR")]})}),e.jsxs("div",{className:"flex items-center justify-start gap-2 text-xs text-gray-500 pt-2",children:[e.jsx(M,{className:"h-3.5 w-3.5 shrink-0"}),e.jsx("span",{children:"Secured with 256-bit SSL encryption"})]}),(()=>{const t=f(m);return e.jsx("div",{className:"flex items-center justify-start gap-x-4 gap-y-2 pt-1 flex-wrap",children:t.methods.slice(0,5).map(a=>e.jsxs("span",{className:"text-xs text-gray-400 flex items-center gap-1",children:[a==="Cards"&&e.jsx($,{className:"h-3.5 w-3.5 shrink-0"}),a]},a))})})()]})]})})}export{le 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.