1import{_ as ue}from"./LOQAt6Ef.js";import{H as ye,aX as Y,d as pe,u as fe,o as me,c as he,e as ve,g as f,h as i,i as r,k as l,j as e,m as J,n as _,J as ke,F as z,r as K,B as b,_ as ge,C as be,K as N,f as d,l as h,t as v,y as _e,E as we,s as xe,A as Se}from"./DufS8oyg.js";import{_ as Te}from"./C_-eUgIg.js";import{_ as $e}from"./CTCvHFiE.js";import{_ as Ue}from"./kVmPcdun.js";import{_ as Ve}from"./Bza2XkxC.js";import{u as ze}from"./CcVBiKIk.js";import{u as Ce}from"./RLOZnqxs.js";function Ie(){const O=ye(),k=Y();function g(){return{Authorization:`Bearer ${O.token}`}}async function C(){return(await $fetch(`${k}/settings/payments`,{headers:g()})).settings}async function I(y){return(await $fetch(`${k}/settings/payments`,{method:"PUT",headers:g(),body:y})).settings}async function P(y){return(await $fetch(`${k}/settings/payments/test-connection`,{method:"POST",headers:g(),body:{mode:y}})).settings}async function X(y){return(await $fetch(`${k}/settings/payments/test-order`,{method:"POST",headers:g(),body:{mode:y}})).order}async function B(y){return(await $fetch(`${k}/settings/payments/verify`,{method:"POST",headers:g(),body:y})).settings}return{fetchSettings:C,saveSettings:I,testConnection:P,createTestOrder:X,verifyTestPayment:B}}const Pe={class:"space-y-5 pb-2"},Xe={class:"flex flex-wrap items-center justify-between gap-4"},Be={key:1,class:"rounded-lg border border-default bg-default p-8 text-center text-sm text-muted"},Me={class:"space-y-4"},Re={class:"flex flex-wrap items-center gap-2"},Ee={class:"flex-1 truncate rounded-md bg-elevated/50 px-3 py-2 font-mono text-sm text-highlighted"},Ae={class:"mt-1.5 flex flex-wrap gap-1.5"},We={class:"font-mono text-xs"},Le={class:"grid gap-2 sm:grid-cols-2"},Fe={class:"text-sm text-highlighted"},Ke={key:0,class:"text-xs text-warning"},Ne={class:"flex items-center gap-2"},Oe={class:"space-y-5"},De={class:"flex items-center justify-between gap-3 rounded-md bg-elevated/50 px-3 py-2"},He={class:"grid gap-3.5 sm:grid-cols-2"},je={key:0,class:"text-xs text-muted"},qe={class:"flex flex-wrap items-center gap-3 border-t border-default pt-4"},Ge={key:0,class:"text-xs text-muted"},ot=pe({__name:"payments",setup(O){fe({title:"Payment Gateway Settings - Admin - Universal CodeBox"});const{setPageHeader:k,clearPageHeader:g}=ze(),C=k({title:"Payment Gateway Settings",description:"Razorpay test & live credentials, active mode, and â¹1 payment verification."});me(()=>{g(C)});const I=[{label:"Settings",to:"/admin/settings",icon:"i-lucide-settings"},{label:"Payment Gateway",icon:"i-lucide-credit-card"}],{openCheckout:P}=Ce(),{fetchSettings:X,saveSettings:B,testConnection:y,createTestOrder:w,verifyTestPayment:Q}=Ie(),M=he(),o=b(null),R=b(!0),x=b(!1),T=b(""),u=b(""),S=b(!1),E=N({test:!1,live:!1}),A=N({test:!1,live:!1}),n=N({activeMode:"test",test:{keyId:"",keySecret:"",webhookSecret:"",enabled:!1},live:{keyId:"",keySecret:"",webhookSecret:"",enabled:!1}}),D=[{key:"test",title:"Test mode",hint:"Sandbox keys (rzp_test_â¦). No real money moves â safe for the â¹1 check."},{key:"live",title:"Live mode",hint:"Production keys (rzp_live_â¦). Real charges. A â¹1 test here bills a real rupee."}],Z=[{label:"Test mode",value:"test"},{label:"Live mode",value:"live"}];function H(s){if(s){n.activeMode=s.activeMode;for(const a of["test","live"])n[a].keyId=s[a].keyId,n[a].keySecret="",n[a].webhookSecret="",n[a].enabled=s[a].enabled}}function $(s,a){return s?.data?.message||(s instanceof Error?s.message:a)}function j(s){switch(s?.lastTestStatus){case"valid":return{color:"success",label:"Verified"};case"invalid":return{color:"error",label:"Failed"};default:return{color:"neutral",label:"Not tested"}}}function ee(s,a){return s?.hasKeySecret?"******** (stored â leave blank to keep)":a}async function te(){R.value=!0,T.value="";try{o.value=await X(),H(o.value)}catch(s){T.value=$(s,"Failed to load payment settings.")}finally{R.value=!1}}ve(te);function q(s){const a=n[s];return{keyId:a.keyId.trim(),keySecret:a.keySecret.trim()||void 0,webhookSecret:a.webhookSecret.trim()||void 0,enabled:a.enabled}}
1async function se(){x.value=!0,u.value="",S.value=!1;try{o.value=await B({activeMode:n.activeMode,test:q("test"),live:q("live")}),H(o.value),S.value=!0,M.add({title:"Payment settings saved",color:"success",icon:"i-lucide-check"})}catch(s){u.value=$(s,"Failed to save settings.")}finally{x.value=!1}}async function ae(s){E[s]=!0,u.value="",S.value=!1;try{o.value=await y(s);const a=o.value[s];a.lastTestStatus==="valid"?M.add({title:`${s} keys verified`,description:"Razorpay accepted these credentials.",color:"success",icon:"i-lucide-badge-check"}):u.value=a.lastTestError||"Connection failed."}catch(a){u.value=$(a,"Connection test failed.")}finally{E[s]=!1}}const G=Se(()=>{const s=Y();return s.startsWith("http")?`${s}/payments/razorpay/webhook`:`${window.location.origin}${s}/payments/razorpay/webhook`}),U=b(!1);async function oe(){try{await navigator.clipboard.writeText(G.value),U.value=!0,setTimeout(()=>{U.value=!1},2e3)}catch{u.value="Could not copy â select the URL and copy it manually."}}const ne=["payment.captured","payment.failed","refund.processed"];async function re(s){if(!o.value?.[s]?.configured){u.value=`Save ${s}-mode credentials before running a test payment.`;return}if(!(s==="live"&&!window.confirm("This charges a REAL â¹1 to your live account. You must refund it manually in the Razorpay dashboard. Continue?"))){A[s]=!0,u.value="",S.value=!1;try{const p=await w(s),c=await P({handle:{orderId:p.orderId,keyId:p.keyId,amount:p.amount,currency:p.currency,mode:s,paymentOrderId:""},description:`â¹1 payment gateway test (${s} mode)`});if(c.result==="dismissed")return;if(c.result==="failed"){u.value=c.message;return}o.value=await Q({mode:s,orderId:c.response.razorpay_order_id,paymentId:c.response.razorpay_payment_id,signature:c.response.razorpay_signature}),M.add({title:"Test payment verified",description:`Payment ${c.response.razorpay_payment_id} captured and signature verified.`,color:"success",icon:"i-lucide-circle-check"})}catch(p){u.value=$(p,"Could not start the test payment.")}finally{A[s]=!1}}}return(s,a)=>{const p=ue,c=ge,ie=be,le=Te,W=$e,V=_e,ce=Ue,L=xe,F=we,de=Ve;return d(),f("section",Pe,[i("div",Xe,[r(p,{items:I}),r(c,{to:"/admin/settings",color:"neutral",variant:"soft",icon:"i-lucide-arrow-left"},{default:l(()=>[...a[1]||(a[1]=[h(" Back to Settings ",-1)])]),_:1})]),e(T)?(d(),J(ie,{key:0,color:"error",variant:"soft",icon:"i-lucide-circle-alert",title:e(T)},null,8,["title"])):_("",!0),e(R)?(d(),f("div",Be," Loading... ")):(d(),f("form",{key:2,id:"payment-settings-form",class:"space-y-5",onSubmit:ke(se,["prevent"])},[r(W,{title:"Active mode on the live site",description:"The storefront collects payments through this credential set. It must be configured and enabled below.",icon:"ucb:status",accent:"text-primary","accent-border":"border-t-primary/60"},{default:l(()=>[r(le,{modelValue:e(n).activeMode,"onUpdate:modelValue":a[0]||(a[0]=t=>e(n).activeMode=t),items:Z,orientation:"horizontal"},null,8,["modelValue"])]),_:1}),r(W,{title:"Webhook",description:"Register this URL in the Razorpay dashboard so payments still reach the ledger when a student closes the tab mid-payment. Without it, only payments completed in the browser are recorded.",icon:"ucb:webhook",accent:"text-info","accent-border":"border-t-info/60"},{default:l(()=>[i("div",Me,[i("div",Re,[i("code",Ee,v(e(G)),1),r(c,{color:"neutral",variant:"soft",icon:e(U)?"i-lucide-check":"i-lucide-copy",onClick:oe},{default:l(()=>[h(v(e(U)?"Copied":"Copy"),1)]),_:1},8,["icon"])]),i("div",null,[a[2]||(a[2]=i("p",{class:"text-xs font-medium text-muted"},"Subscribe to these events",-1)),i("div",Ae,[(d(),f(z,null,K(ne,t=>r(V,{key:t,color:"neutral",variant:"soft"},{default:l(()=>[i("span",We,v(t),1)]),_:2},1024)),64))])]),i("div",Le,[(d(),f(z,null,K(D,t=>i("div",{key:t.key,class:"flex items-center justify-between gap-2 rounded-md border border-default px-3 py-2"},[i("span",Fe,v(t.title)+" secret",1),r(V,{color:e(o)?.[t.key].hasWebhookSecret?"success":"neutral",variant:"soft",size:"sm"},{default:l(()=>[h(v(e(o)?.[t.key].hasWebhookSecret?"Saved":"Not set"),1)]),_:2},1032,["color"])])),64))]),e(o)&&!e(o)[e(n).activeMode].hasWebhookSecret?(d(),f("p",Ke," The active mode has no webhook secret saved, so webhook deliveries will be rejected. Paste the dashboard's signing secret into the "+v(e(n).activeMode)+" credential set below. ",1)):_("",!0)])]),_:1}),(d(),f(z,null,K(D,t=>
1r(W,{key:t.key,title:t.title,description:t.hint,icon:"ucb:gateway",accent:t.key==="live"?"text-warning":"text-success","accent-border":t.key==="live"?"border-t-warning/60":"border-t-success/60"},{actions:l(()=>[i("div",Ne,[e(o)&&e(n).activeMode===t.key?(d(),J(V,{key:0,color:"primary",variant:"soft",size:"sm"},{default:l(()=>[...a[3]||(a[3]=[h(" Active ",-1)])]),_:1})):_("",!0),r(V,{color:j(e(o)?.[t.key]).color,variant:"soft",size:"sm"},{default:l(()=>[h(v(j(e(o)?.[t.key]).label),1)]),_:2},1032,["color"])])]),default:l(()=>[i("div",Oe,[i("div",De,[a[4]||(a[4]=i("div",null,[i("p",{class:"text-sm font-medium text-highlighted"},"Enable this mode"),i("p",{class:"text-xs text-muted"},"Disabled sets are kept but never used.")],-1)),r(ce,{modelValue:e(n)[t.key].enabled,"onUpdate:modelValue":m=>e(n)[t.key].enabled=m},null,8,["modelValue","onUpdate:modelValue"])]),i("div",He,[r(F,{label:"Key ID",required:e(n)[t.key].enabled},{default:l(()=>[r(L,{modelValue:e(n)[t.key].keyId,"onUpdate:modelValue":m=>e(n)[t.key].keyId=m,placeholder:t.key==="test"?"rzp_test_XXXXXXXX":"rzp_live_XXXXXXXX",class:"w-full font-mono"},null,8,["modelValue","onUpdate:modelValue","placeholder"])]),_:2},1032,["required"]),r(F,{label:"Key Secret",required:!e(o)?.[t.key].hasKeySecret},{default:l(()=>[r(L,{modelValue:e(n)[t.key].keySecret,"onUpdate:modelValue":m=>e(n)[t.key].keySecret=m,type:"password",placeholder:ee(e(o)?.[t.key],"Razorpay Key Secret"),class:"w-full font-mono"},null,8,["modelValue","onUpdate:modelValue","placeholder"])]),_:2},1032,["required"]),r(F,{label:"Webhook Secret",help:"The signing secret from this mode's webhook in the Razorpay dashboard. Required for webhook deliveries to be accepted.",class:"sm:col-span-2",ui:{help:"text-xs"}},{default:l(()=>[r(L,{modelValue:e(n)[t.key].webhookSecret,"onUpdate:modelValue":m=>e(n)[t.key].webhookSecret=m,type:"password",placeholder:e(o)?.[t.key].hasWebhookSecret?"******** (stored â leave blank to keep)":"Webhook signing secret",class:"w-full font-mono"},null,8,["modelValue","onUpdate:modelValue","placeholder"])]),_:2},1024)]),e(o)?.[t.key].lastTestedAt?(d(),f("p",je,[h(" Last tested "+v(new Date(e(o)[t.key].lastTestedAt).toLocaleString())+" ",1),e(o)[t.key].lastTestStatus==="invalid"&&e(o)[t.key].lastTestError?(d(),f(z,{key:0},[h(" â "+v(e(o)[t.key].lastTestError),1)],64)):_("",!0)])):_("",!0),i("div",qe,[r(c,{color:"neutral",variant:"outline",icon:"i-lucide-plug-zap",loading:e(E)[t.key],disabled:e(x)||!e(o)?.[t.key].configured,onClick:m=>ae(t.key)},{default:l(()=>[...a[5]||(a[5]=[h(" Test connection ",-1)])]),_:1},8,["loading","disabled","onClick"]),r(c,{color:t.key==="live"?"warning":"primary",variant:"soft",icon:"i-lucide-indian-rupee",loading:e(A)[t.key],disabled:e(x)||!e(o)?.[t.key].configured,onClick:m=>re(t.key)},{default:l(()=>[...a[6]||(a[6]=[h(" Test â¹1 payment ",-1)])]),_:1},8,["color","loading","disabled","onClick"]),e(o)?.[t.key].configured?_("",!0):(d(),f("span",Ge," Save Key ID & Secret to enable tests. "))])])]),_:2},1032,["title","description","accent","accent-border"])),64))],32)),r(de,{form:"payment-settings-form",loading:e(x),error:e(u),success:e(S),"success-message":"Payment gateway settings saved."},null,8,["loading","error","success"])])}}});export{ot 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.