1import{r,a0 as e,a_ as ee,bv as fe,br as ae,aZ as De,bc as E,c4 as ye,c1 as $,bu as re,a6 as ge,ay as S,cP as ne,cw as oe,bo as We,bW as $e,cx as Oe,b9 as be,R as Ee,c5 as Le,c6 as Ue,be as Be}from"./vendor-BoZeCkxh.js";import{b as Ke,g as je,c as y,A as j,B as i,j as Ge,n as Fe,I as O,f as Ve}from"./index-5vXX_dOL.js";import{B as H}from"./badge-DWq-h8R0.js";const He=[{code:"7372",desc:"Computer Programming / Software"},{code:"5912",desc:"Drug Stores / Pharmacies"},{code:"5411",desc:"Grocery / Supermarkets"},{code:"5812",desc:"Restaurants / Food"},{code:"7011",desc:"Hotels and Motels"},{code:"5045",desc:"Computers / Software"},{code:"8099",desc:"Health Services"},{code:"5999",desc:"Miscellaneous Retail"},{code:"5311",desc:"Department Stores"},{code:"5699",desc:"Apparel / Accessories"},{code:"7399",desc:"Business Services"},{code:"8049",desc:"Medical / Healthcare"},{code:"0000",desc:"Test MCC (sandbox only)"}],J={razorpay:{label:"Razorpay",color:"bg-blue-500",webhookPath:"razorpay"},payu:{label:"PayU",color:"bg-orange-500",webhookPath:"payu"},upi_vpa:{label:"UPI VPA",color:"bg-emerald-500"},stripe:{label:"Stripe",color:"bg-violet-500",webhookPath:"stripe"},cashfree:{label:"Cashfree",color:"bg-sky-500",webhookPath:"cashfree"},phonepe:{label:"PhonePe",color:"bg-purple-500",webhookPath:"phonepe"},juspay:{label:"Juspay",color:"bg-teal-500",webhookPath:"juspay"},ccavenue:{label:"CCAvenue",color:"bg-rose-500",webhookPath:"ccavenue"},billdesk:{label:"BillDesk",color:"bg-slate-500",webhookPath:"billdesk"},easebuzz:{label:"Easebuzz",color:"bg-yellow-500",webhookPath:"easebuzz"},instamojo:{label:"Instamojo",color:"bg-pink-500",webhookPath:"instamojo"},paytm:{label:"Paytm",color:"bg-indigo-500",webhookPath:"paytm"}},Je={razorpay:"RZ",payu:"PU",upi_vpa:"UPI",stripe:"ST",cashfree:"CF",phonepe:"PP",juspay:"JP",ccavenue:"CC",billdesk:"BD",easebuzz:"EB",instamojo:"IM",paytm:"PT"},Ze=typeof window<"u"?"https://api.wazappy.com/api".replace(/\/api$/,"")||window.location.origin.replace(/:\d+/,":5000"):"https://api.wazappy.com";function _(s){const t=J[s?.toLowerCase()];return t?.webhookPath?`${Ze}/api/payments/webhook/${t.webhookPath}`:""}function se(s){return s?new Date(s*1e3).toLocaleString("en-IN",{timeZone:Ve(),day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}):"â"}const te="w-full h-9 px-3 rounded-md border border-input bg-background text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring cursor-pointer";function Ye({status:s}){return s==="Active"?e.jsxs(H,{className:"bg-emerald-500/10 text-emerald-600 border-emerald-200 dark:border-emerald-800 gap-1 font-semibold",children:[e.jsx(E,{className:"h-3 w-3"}),"Active"]}):s==="Needs Connecting"?e.jsxs(H,{className:"bg-amber-500/10 text-amber-600 border-amber-200 dark:border-amber-800 gap-1 font-semibold",children:[e.jsx(oe,{className:"h-3 w-3"}),"Needs Connecting"]}):s==="Needs Testing"?e.jsxs(H,{className:"bg-blue-500/10 text-blue-600 border-blue-200 dark:border-blue-800 gap-1 font-semibold",children:[e.jsx(Be,{className:"h-3 w-3"}),"Needs Testing"]}):e.jsxs(H,{variant:"destructive",className:"gap-1",children:[e.jsx(ye,{className:"h-3 w-3"}),s]})}function qe({providerKey:s,size:t="md"}){const m=J[s?.toLowerCase()||""]??{color:"bg-muted"},b=Je[s?.toLowerCase()||""]||(s||"?").slice(0,2).toUpperCase(),p=t==="sm"?"w-8 h-8 text-[10px]":"w-10 h-10 text-xs";return e.jsx("div",{className:`${p} rounded-lg ${m.color} flex items-center justify-center text-white font-bold shrink-0`,children:b})}const Xe=/^[â¢*·â\s]+$/,ve=s=>typeof s=="string"&&s.trim().length>0&&Xe.test(s);function Qe(s){return Object.fromEntries(Object.entries(s||{}).filter(([,t])=>!ve(t)))}function u({fields:s,secrets:t,onChange:m}){const[b,p]=Ee.useState({});return e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:s.map(d=>{const v=t[d.key]||"",w=ve(v);return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:d.label}),d.secret&&e.jsxs("span",{className:"text-[10px] text-muted-foreground flex items-center gap-0.5",children:[e.jsx(ne,{className:"h-2.5 w-2.5"}),"encrypted"]}),w&&e.jsxs("span",{className:"text-[10px] text-emerald-600 font-semibold flex items-center gap-0.5",children:[e.jsx(E,{className:"h-2.5 w-2.5"}),"saved"]})]}),e.jsxs("div",{className:"relative",children:[e.jsx(O,{type:d.secret&&!b[d.key]?"password":"text",value:w?"":v,onChange:c=>m(d.key,c.target.value),placeholder:w?"Leave blank to keep existing":d.ph,className:`h-9 text-sm font-mono ${d.secret?"pr-9"
1:""}`}),d.secret&&e.jsx("button",{type:"button",onClick:()=>p(c=>({...c,[d.key]:!c[d.key]})),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors",children:b[d.key]?e.jsx(Le,{className:"h-3.5 w-3.5"}):e.jsx(Ue,{className:"h-3.5 w-3.5"})})]})]},d.key)})})}const ea={upi_vpa:{gatewayWebhook:!1,summary:"No gateway webhook. Money moves over UPI and Meta reports the result on your existing WhatsApp webhook â nothing extra to configure anywhere.",steps:["Customer taps Review and Pay on the order_details card and pays over UPI.","Meta posts a `payments` change to your WhatsApp webhook.","reference_id on that payload is the order number we sent â that is how it is matched.","status: completed â the order is confirmed, the paid receipt goes out, and the card in the chat flips to Payment Successful.","status: failed / pending â the order stays open and nothing is sent to the customer."],payload:`"payments": [{ 2 "reference_id": "ORD-20260802-0001", 3 "status": "completed", // completed | pending | failed 4 "transaction_id": "4712â¦", 5 "amount": { "value": 21240, "offset": 100 } 6}]`},gateway:{gatewayWebhook:!0,summary:"Two callbacks. Meta tells us the customer completed the flow; the gateway tells us the money actually settled and signs it so it can be trusted.",steps:["Paste the webhook URL above into your gateway dashboard.","The gateway signs each call â the signing secret you save here is what verifies it.","Meta also posts a `payments` change to the WhatsApp webhook, matched on reference_id.","On success the order is confirmed, the receipt is sent, and the payment card updates.","An unsigned or wrongly-signed call is rejected â that is the point of the secret."]}};function aa({config:s,wabaId:t,open:m,onToggle:b,onDelete:p,onOauth:d,onEndpoint:v,onRefresh:w,inUse:c,inUseSource:P}){const[N,R]=r.useState(""),[T,L]=r.useState(!1),[U,B]=r.useState(!1),[k,K]=r.useState(!1);je();const g=s.provider_name?.toLowerCase()||"",A=J[g]??{label:s.provider_name||"â"},Z=t?`https://business.facebook.com/latest/whatsapp_manager/india?asset_id=${t}`:"https://business.facebook.com/latest/whatsapp_manager/india",I=s.status==="Active",G=s.status==="Needs Connecting",D=s.status==="Needs Testing",F=!!s.merchant_vpa&&!s.provider_name;return e.jsxs("div",{className:`rounded-xl border bg-card overflow-hidden transition-all ${I?"border-emerald-200 dark:border-emerald-800":"border-border"}`,children:[I&&e.jsx("div",{className:"h-0.5 bg-gradient-to-r from-emerald-500 to-emerald-400"}),e.jsxs("div",{className:"p-4 flex items-start gap-3",children:[e.jsx(qe,{providerKey:g}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-1",children:[e.jsx("p",{className:"text-sm font-bold text-foreground truncate",children:s.configuration_name}),e.jsx(Ye,{status:s.status}),c&&e.jsxs("span",{className:`inline-flex items-center gap-1 text-[10px] font-semibold px-1.5 py-0.5 rounded-full 7 bg-emerald-100 text-emerald-700 dark:bg-emerald-950/40 dark:text-emerald-400`,title:P?`Selected in ${P}`:"Currently used for orders",children:[e.jsx(E,{className:"h-2.5 w-2.5"})," In use"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-x-3 gap-y-0.5 text-xs text-muted-foreground",children:[e.jsx("span",{className:"font-medium",children:A.label}),s.merchant_vpa&&e.jsxs("span",{children:["VPA: ",e.jsx("code",{className:"text-foreground font-mono text-[10px] bg-muted px-1 py-0.5 rounded",children:s.merchant_vpa})]}),s.provider_mid&&e.jsxs("span",{children:["MID: ",e.jsx("code",{className:"text-foreground font-mono text-[10px] bg-muted px-1 py-0.5 rounded",children:s.provider_mid})]}),s.merchant_category_code?.code&&e.jsxs("span",{children:["MCC ",s.merchant_category_code.code]}),e.jsxs("span",{children:["Created ",se(s.created_timestamp)]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0 flex-wrap justify-end",children:[D&&e.jsxs("a",{href:Z,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 h-8 px-2.5 rounded-md border border-blue-200 dark:border-blue-800 bg-blue-500/10 text-blue-600 text-xs font-semibold hover:bg-blue-500/20 transition-colors no-u
7nderline",children:[e.jsx(re,{className:"h-3 w-3"})," Test on Facebook"]}),D&&e.jsxs(i,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5",onClick:async()=>{K(!0),await w(s.configuration_name),K(!1)},disabled:k,children:[k?e.jsx(S,{className:"h-3 w-3 animate-spin"}):e.jsx(fe,{className:"h-3 w-3"}),"Refresh"]}),G&&e.jsxs(i,{variant:"outline",size:"sm",className:"h-8 text-xs gap-1.5 border-amber-200 text-amber-600 hover:bg-amber-500/10",onClick:async()=>{B(!0),await d(s.configuration_name),B(!1)},disabled:U,children:[U?e.jsx(S,{className:"h-3 w-3 animate-spin"}):e.jsx(oe,{className:"h-3 w-3"}),"OAuth Link"]}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:b,children:m?e.jsx(We,{className:"h-3.5 w-3.5"}):e.jsx($e,{className:"h-3.5 w-3.5"})}),e.jsx(i,{variant:"ghost",size:"icon",className:`h-8 w-8 ${c?"text-muted-foreground/40":"text-destructive hover:text-destructive hover:bg-destructive/10"}`,title:c?"This configuration is in use â switch to another one first":"Delete",onClick:()=>{c&&!confirm(`"${s.configuration_name}" is the configuration your orders charge through${P?` (selected in ${P})`:""}. 8 9Deleting it will make online payments fail until you pick another one. Continue?`)||p(s.configuration_name)},children:e.jsx(Oe,{className:"h-3.5 w-3.5"})})]})]}),D&&e.jsxs("div",{className:"mx-4 mb-3 rounded-lg bg-blue-500/10 border border-blue-200 dark:border-blue-800 p-3",children:[e.jsx("p",{className:"text-xs font-bold text-blue-700 dark:text-blue-400 mb-1",children:"Testing required to activate"}),e.jsxs("p",{className:"text-xs text-blue-600 dark:text-blue-500 leading-relaxed mb-2",children:["Open WhatsApp Manager â India Payments â find ",e.jsx("strong",{children:s.configuration_name})," â click Test. Then click ",e.jsx("strong",{children:"Refresh"})," above."]}),e.jsxs("a",{href:Z,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 h-7 px-3 rounded-md bg-blue-600 text-white text-xs font-semibold hover:bg-blue-700 transition-colors no-underline",children:[e.jsx(re,{className:"h-3 w-3"})," Open WhatsApp Manager"]})]}),m&&e.jsxs("div",{className:"border-t border-border bg-muted/30 p-4 space-y-4",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3",children:[["Config Name",s.configuration_name],["Provider",A.label],["Status",s.status],["MCC",`${s.merchant_category_code?.code||"â"} â ${s.merchant_category_code?.description||"â"}`],["Purpose Code",`${s.purpose_code?.code||"â"} â ${s.purpose_code?.description||"â"}`],["Provider MID",s.provider_mid||"â"],["Merchant VPA",s.merchant_vpa||"â"],["Created",se(s.created_timestamp)],["Last Updated",se(s.updated_timestamp)]].map(([z,C])=>e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-[10px] font-bold uppercase tracking-widest text-muted-foreground",children:z}),e.jsx("p",{className:"text-xs text-foreground break-all",children:C})]},z))}),F?e.jsxs("div",{className:"rounded-lg border border-border bg-muted/20 p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:"No webhook for merchant VPA"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed",children:["Money moves bank-to-bank over UPI with no gateway in between, so there is nothing for Meta to call back and no automatic payment confirmation. Set how these orders get confirmed in ",e.jsx("strong",{children:"Commerce Setup â Checkout & Orders â Payment"}),"."]})]}):e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(be,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:"PG Webhook URL (Data Endpoint)"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground leading-relaxed",children:["Register this URL in your payment gateway dashboard so it notifies your server on payment completion, then click ",e.jsx("strong",{children:"Save to Meta"}),"."]}),_(g)&&!N&&e.jsxs("div",{className:"flex items-center gap-2 p-2.5 bg-primary/5 rounded-md border border-primary/20",children:[e.jsx("code",{className:"text-xs text-primary flex-1 break-all",children:_(g)}),e.jsxs(i,{variant:"outline",size:"sm",className:"h-7 text-xs gap-1 shrink-0",onClick:()=>{R(_(g)),navigator.clipboard.writeText(_(g))},children:[e.jsx($,{className:"h-2.5 w-2.5"})," Copy & Use"]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(O,{value:N,onChange:z=>R(z.target.value),placeholder:_(g)||`https://yourserver.com/api/payments/webhook/${g||"razorpay"}`,className:"flex-1 h-9 text-xs font-mono"}),e.jsxs(i,{size:"sm",className:"h-9 gap-1.5 wa-gradient border-0 text-primary-foreground hover:opacity-90 shrink-0",onClick:async()=>{L(!0),await v(s.configuration_name,N),L(!1),R("")},disabled:T||!N,children:[T?e.jsx(S,{className:"h-3 w-3 animate-spin"}):e.jsx(oe,{className:"h-3 w-3"}),"Save to Meta"]})]}),e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Also register in gateway dashboard: ",e.jsxs("strong",{children:[A.label," â Webhooks / Notifications â Payment Events"]})]})]})]})]})}function na(){const{activeNumberId:s}=Ke(),{toast:t}=je(),[m,b]=r.useState([]),[p,d]=r.useState(""),[v,w]=r.useState(""),[c,P]=r.useState(""),[N,R]=r.useState([]),[T,L]=r.useState(!1),[U,B]=r.useState(!1),[k,K]=r.useState(""),[g,A]=r.useState(!1),I=`${"https://api.wazappy.com/api".replace(/\/api\/?$/,"")||window.location.origin.replace(/:\d+$/,"")}/api/whatsapp/webhook`,G=[`curl -X POST ${I} \\`," -H 'Content-Type: application/json' \\"," -d '{",' "object": "whatsapp_business_account",',' "entry": [{ "changes": [{ "field": "messages", "value": {',' "messaging_product": "whatsapp",',` "metadata": { "phone_number_id": "${s||"<phoneId>"}" },`,' "payments": [{',' "reference_id": "ORD-20260802-0001",',' "status": "completed",',' "transaction_id": "TEST123",',' "amount": { "value": 21240, "offset": 100 }'," }]"," }}]}]"," }'"].join(` 10`),[D,F]=r.useState(!0),[z,C]=r.useState(!1),[Y,le]=r.useState(!1),[Ne,we]=r.useState(),[M,q]=r.useState(null),[ke,Ce]=r.useState(null),[o,ie]=r.useState({configuration_name:"",provider_name:"razorpay",merchant_category_code:"7372",purpose_code:"00",redirect_url:typeof window<"u"?`${window.location.origin}/payment-callback`:"",merchant_vpa:""}),W=(a,n)=>ie(f=>({...f,[a]:n})),[x,de]=r.useState({}),[l,ce]=r.useState("razorpay"),[pe,xe]=r.useState(!1),[X,he]=r.useState(!1),[_e,me]=r.useState(!1),h=(a,n)=>de(f=>({...f,[a]:n})),ue=r.useCallback(async()=>
10{if(s){me(!0);try{const{data:a}=await y.get(`${j.payments.setup}?phoneId=${s}`);d(a.inUseConfiguration||""),w(a.inUseSource||""),P(a.storedConfiguration||""),R(Array.isArray(a.liveConfigurations)?a.liveConfigurations:[]),L(!!a.configurationStale),B(!!a.configurationChecked),de(a||{}),a.paymentGateway&&ce(a.paymentGateway)}catch{}finally{me(!1)}}},[s]);r.useEffect(()=>{ue()},[ue]);const Se=async()=>{if(s){he(!0);try{await y.post(j.payments.setup,{phoneId:s,paymentGateway:l,...Qe(x)}),xe(!0),setTimeout(()=>xe(!1),3e3),t({title:"Gateway credentials saved â
"})}catch(a){t({title:"Save failed",description:a.response?.data?.error||a.message,variant:"destructive"})}finally{he(!1)}}},V=r.useCallback(async()=>{if(s){F(!0);try{const{data:a}=await y.get(`${j.payments.configurations}?phoneId=${s}`);b(a.configurations||[]),a.wabaId&&we(a.wabaId)}catch(a){t({title:"Failed to load",description:a.response?.data?.error||a.message,variant:"destructive"})}finally{F(!1)}}},[s]);r.useEffect(()=>{V()},[V]);const Pe=async()=>{if(o.configuration_name){le(!0);try{const{data:a}=await y.post(j.payments.configurations,{phoneId:s,configuration_name:o.configuration_name,provider_name:o.provider_name,merchant_category_code:o.merchant_category_code,purpose_code:o.purpose_code,redirect_url:o.provider_name!=="upi_vpa"?o.redirect_url:void 0,merchant_vpa:o.provider_name==="upi_vpa"?o.merchant_vpa:void 0});t({title:"Configuration created â
"}),C(!1),ie(n=>({...n,configuration_name:"",merchant_vpa:""})),a.oauth_url&&q({name:o.configuration_name,url:a.oauth_url,expiry:a.expiration}),V()}catch(a){t({title:"Failed",description:a.response?.data?.error||a.message,variant:"destructive"})}finally{le(!1)}}},Ae=async a=>{if(confirm(`Delete "${a}"?`))try{await y.delete(`${j.payments.configurationsBy(a)}?phoneId=${s}`),b(n=>n.filter(f=>f.configuration_name!==a)),t({title:"Deleted"})}catch{t({title:"Failed",variant:"destructive"})}},Ie=async a=>{try{const{data:n}=await y.post(j.payments.configurationsByOauth(a),{phoneId:s,redirect_url:o.redirect_url});q({name:a,url:n.oauth_url,expiry:n.expiration})}catch{t({title:"Failed to get OAuth link",variant:"destructive"})}},ze=async(a,n)=>{try{await y.post(j.payments.configurationsByLink(a),{phoneId:s,data_endpoint_url:n}),t({title:"Endpoint saved â
"})}catch{t({title:"Failed",variant:"destructive"})}},Me=async a=>{try{const{data:n}=await y.get(`${j.payments.configurationsByRefresh(a)}?phoneId=${s}`);n.config&&(b(f=>f.map(Q=>Q.configuration_name===a?{...Q,...n.config}:Q)),t({title:n.config.status==="Active"?"â
Now Active!":`Status: ${n.config.status}`,description:n.config.status==="Active"?`${a} has been validated by Meta.`:"Not validated yet â complete the test on Facebook first."}))}catch(n){t({title:"Refresh failed",description:n.response?.data?.error||n.message,variant:"destructive"})}},Re=m.filter(a=>a.status==="Active").length,Te=m.filter(a=>a.status!=="Active").length;return e.jsxs("div",{className:"flex flex-col bg-background min-h-[calc(100vh-64px)] xl:h-[calc(100vh-64px)] xl:overflow-hidden",children:[e.jsx("div",{className:"border-b border-border bg-card px-4 sm:px-6 py-4 shrink-0",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("div",{className:"w-9 h-9 rounded-lg wa-gradient flex items-center justify-center shrink-0",children:e.jsx(ee,{className:"h-4.5 w-4.5 text-white"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-base font-bold text-foreground leading-tight",children:"Payment Configurations"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage WhatsApp India payment gateways linked to your WABA"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 w-full sm:w-auto shrink-0",children:[e.jsxs(i,{variant:"outline",size:"sm",className:"h-8 gap-1.5 text-xs flex-1 sm:flex-none whitespace-nowrap",onClick:V,children:[e.jsx(fe,{className:"h-3 w-3 shrink-0"})," Refresh"]}),e.jsxs(i,{size:"sm",className:"h-8 gap-1.5 text-xs flex-1 sm:flex-none whitespace-nowrap wa-gradient border-0 text-primary-foreground hover:opacity-90",onClick:()=>C(a=>!a),children:[e.jsx(ae,{className:"h-3 w-3 shrink-0"})," New Config"]})]})]})}),e.jsxs("div",{className:"flex-1 xl:overflow-y-auto p-4 sm:p-6 space-y-5",children:[e.jsx("div",{className:"grid grid-cols-3 gap-2 sm:gap-3",children:[{label:"Total Configs",value:m.length,icon:e.jsx(De,{className:"h-4 w-4"}),accent:"#2563eb"},{label:"Active",value:Re,icon:e.jsx(E,{className:"h-4 w-4"}),accent:"#10b981"},{label:"Needs Action",value:Te,icon:e.jsx(ye,{className:"h-4 w-4"}),accent:"#f97316"}].map(a=>e.jsxs("div",{className:"relative overflow-hidden rounded-2xl border border-border/70 bg-card p-3 shadow-sm flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3",children:[e.jsx(Ge,{accent:a.accent,size:"sm"}),e.jsx(Fe,{accent:a.accent,size:"sm",children:a.icon}),e.jsxs("div",{className:"relative z-10 min-w-0",children:[e.jsx("p",{className:"text-xl font-bold leading-none text-foreground",children:a.value}),e.jsx("p",{className:"text-[10px] text-muted-foreground font-semibold uppercase tracking-wider mt-0.5 leading-tight",children:a.label})]})]},a.label))}),M&&e.jsx("div",{className:"rounded-xl border border-amber-200 dark:border-amber-800 bg-amber-500/10 p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex-1 min-w-0 space-y-2",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-bold text-amber-800 dark:text-amber-400",children:['OAuth Link â "',M.name,'"']}),e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-500 mt-0.5",children:["Share with your merchant to authorize the payment gateway. E
10xpires: ",e.jsx("strong",{children:new Date(M.expiry*1e3).toLocaleString("en-IN")})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-2",children:[e.jsx("code",{className:"flex-1 text-xs bg-amber-100 dark:bg-amber-900/30 border border-amber-200 dark:border-amber-800 rounded-md px-3 py-2 break-all text-amber-800 dark:text-amber-300",children:M.url}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(i,{variant:"outline",size:"sm",className:"h-9 gap-1.5 border-amber-300 text-amber-700 hover:bg-amber-100",onClick:()=>{navigator.clipboard.writeText(M.url),t({title:"Copied!"})},children:[e.jsx($,{className:"h-3 w-3"})," Copy"]}),e.jsxs("a",{href:M.url,target:"_blank",rel:"noreferrer",className:"h-9 px-3 rounded-md bg-foreground text-background text-xs font-semibold flex items-center gap-1.5 hover:opacity-90 transition-opacity no-underline",children:[e.jsx(re,{className:"h-3 w-3"})," Open"]})]})]})]}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-7 w-7 shrink-0",onClick:()=>q(null),children:e.jsx(ge,{className:"h-3.5 w-3.5"})})]})}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-3 gap-5",children:[e.jsxs("div",{className:"xl:col-span-2 space-y-4",children:[z&&e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-bold text-foreground",children:"New Payment Configuration"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"Creates the config on Meta and returns an OAuth link."})]}),e.jsx(i,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>C(!1),children:e.jsx(ge,{className:"h-3.5 w-3.5"})})]}),e.jsxs("div",{className:"p-4 grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"sm:col-span-2 space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Configuration Name *"}),e.jsx(O,{value:o.configuration_name,onChange:a=>W("configuration_name",a.target.value.toLowerCase().replace(/[^a-z0-9_-]/g,"_")),placeholder:"razorpay_prod or upi_main",className:"h-9 text-sm font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Lowercase, numbers, underscores, hyphens only. Used in flow nodes."})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Provider *"}),e.jsxs("select",{value:o.provider_name,onChange:a=>W("provider_name",a.target.value),className:te,children:[e.jsxs("optgroup",{label:"â Meta WhatsApp Payments India â",children:[e.jsx("option",{value:"razorpay",children:"Razorpay"}),e.jsx("option",{value:"payu",children:"PayU"}),e.jsx("option",{value:"upi_vpa",children:"UPI VPA Direct"}),e.jsx("option",{value:"juspay",children:"Juspay (WhatsApp Pay India)"})]}),e.jsx("optgroup",{label:"â Meta WhatsApp Payments Global â",children:e.jsx("option",{value:"stripe",children:"Stripe (Mexico / International)"})}),e.jsxs("optgroup",{label:"â Additional Gateways â",children:[e.jsx("option",{value:"cashfree",children:"Cashfree"}),e.jsx("option",{value:"phonepe",children:"PhonePe"}),e.jsx("option",{value:"ccavenue",children:"CCAvenue"}),e.jsx("option",{value:"billdesk",children:"BillDesk"}),e.jsx("option",{value:"easebuzz",children:"Easebuzz"}),e.jsx("option",{value:"instamojo",children:"Instamojo"}),e.jsx("option",{value:"paytm",children:"Paytm"})]})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Merchant Category Code"}),e.jsx("select",{value:o.merchant_category_code,onChange:a=>W("merchant_category_code",a.target.value),className:te,children:He.map(a=>e.jsxs("option",{value:a.code,children:[a.code," â ",a.desc]},a.code))})]}),o.provider_name==="upi_vpa"?e.jsxs("div",{className:"sm:col-span-2 space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Merchant VPA *"}),e.jsx(O,{value:o.merchant_vpa,onChange:a=>W("merchant_vpa",a.target.value),placeholder:"yourbusiness@upi",className:"h-9 text-sm font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Your UPI VPA. No OAuth needed â activates directly."})]}):e.jsxs("div",{className:"sm:col-span-2 space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"OAuth Redirect URL"}),e.jsx(O,{value:o.redirect_url,onChange:a=>W("redirect_url",a.target.value),placeholder:"https://your-app.com/payment-callback",className:"h-9 text-sm font-mono"}),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"Where Meta redirects the merchant after authorization."})]})]}),e.jsxs("div",{className:"flex gap-2 px-4 py-3 border-t border-border bg-muted/20",children:[e.jsx(i,{variant:"outline",size:"sm",className:"h-8",onClick:()=>C(!1),children:"Cancel"}),e.jsxs(i,{size:"sm",className:"h-8 gap-1.5 wa-gradient border-0 text-primary-foreground hover:opacity-90",onClick:Pe,disabled:Y||!o.configuration_name||o.provider_name==="upi_vpa"&&!o.merchant_vpa,children:[Y?e.jsx(S,{className:"h-3 w-3 animate-spin"}):e.jsx(ae,{className:"h-3 w-3"}),Y?"Creatingâ¦":"Create Configuration"]})]})]}),D?e.jsx("div",{className:"space-y-3",children:[1,2].map(a=>e.jsx("div",{className:"h-20 rounded-xl border border-border bg-card animate-pulse"},a))}):m.length===0?e.jsxs("div",{className:"rounded-xl border-2 border-dashed border-border bg-card flex flex-col items-center justify-center py-16 text-center px-6",children:[e.jsx("div",{className:"w-12 h-12 rounded-xl bg-muted flex items-center justify-center mb-3",children:e.jsx(ee,{className:"h-5 w-5 text-muted-foreground"})}),e.jsx("p",{className:"text-sm font-bold text-foreground mb-1",children:"No configurations yet"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Create a configuration to start accepting WhatsApp payments."}),e.jsxs(i,{size:"sm",className:"h-8 gap-1.5 wa-gradient border-0 text-primary-foreground hover:opacity-90",onClick:()=>C(!0),children:[e.jsx(ae,{className:"h-3 w-3"})," Create First Configuration"]})]}):e.jsx("div",{className:"space-y-3",children:m.map(a=>e.jsx(aa,{config:a,wabaId:Ne,inUse:!!p&&a.configuration_name===p,inUseSource:v,open:ke===a.configuration_name,onToggle:()=>Ce(n=>n===a.configuration_name?null:a.configuration_name),onDelete:Ae,onOauth:Ie,onEndpoint:ze,onRefresh:Me},a.configuration_name))})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-4 py-3 border-b border-border bg-muted/30",children:[e.jsx(ee,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:"Charged through"})]}),e.jsxs("div",{className:"p-4 space-y-3",children:[p?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500 shrink-0"}),e.jsx("code",{className:"text-xs font-semibold text-foreground",children:p}),v&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["· from ",v]})]}):e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"No configuration selected. Online payments cannot be sent until one is."}),T&&e.jsxs("div",{className:"rounded-md bg-amber-50 dark:bg-amber-950/20 border border-amber-200 dark:border-amber-800 p-2.5 space-y-1",children:[e.jsx("p",{className:"text-[11px] font-semibold text-amber-800 dark:text-amber-300",children:"A deleted configuration was stored"}),e.jsxs("p",{className:"text-[11px] leading-relaxed text-amber-800/90 dark:text-amber-300/90",children:[c?e.jsx("code",{className:"font-semibold",children:c}):"The saved name"," no longer exists on this WhatsApp Business Account.",p?e.jsxs(e.Fragment,{children:[" It has been replaced with ",e.jsx("code",{className:"font-semibold",children:p}),", so payments work again."]}):e.jsx(e.Fragment,{children:" There is nothing live to replace it with â create a configuration first."})]})]}),c&&c!==p&&!T&&e.jsxs("p",{className:"text-[11px] text-muted-foreground",children:["Saved on this page: ",e.jsx("code",{children:c})," â overridden by Checkout settings."]}),U&&e.jsxs("div",{className:"space-y-1",children:[e.jsxs("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-muted-foreground",children:["Live on this WABA (",N.length,")"]}),N.length===0?e.jsx("p",{className:"text-[11px] text-muted-foreground",children:"None. Create one in WhatsApp Manager â Payment Settings."}):N.map(a=>e.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[e.jsx("code",{className:a.name===p?"text-foreground font-semibold":"text-muted-foreground",children:a.name}),a.provider&&e.jsx("span",{className:"text-[10px] text-muted-foreground",children:a.provider}),a.status&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["· ",a.status]})]},a.name))]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-muted/30",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ne,{className:"h-3.5 w-3.5 text-muted-foreground"}),e.jsx("p",{className:"text-xs font-bold text-foreground",children:"Gateway Credentials"})]}),_e&&e.jsx(S,{className:"h-3 w-3 animate-spin text-muted-foreground"})]}),e.jsxs("div",{className:"p-4 space-y-4",children:[e.jsxs("p",{className:"text-[11px] text-muted-foreground leading-relaxed",children:["Each user has their own gateway keys â stored securely and ",e.jsx("strong",{className:"text-foreground",children:"never shared between accounts"}),"."]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("label",{className:"text-xs font-semibold text-foreground",children:"Payment Gateway"}
10),e.jsxs("select",{value:l,onChange:a=>{ce(a.target.value),h("paymentGateway",a.target.value)},className:te,children:[e.jsxs("optgroup",{label:"â Meta WhatsApp Payments India â",children:[e.jsx("option",{value:"razorpay",children:"Razorpay"}),e.jsx("option",{value:"payu",children:"PayU"}),e.jsx("option",{value:"upi_vpa",children:"UPI VPA Direct"}),e.jsx("option",{value:"juspay",children:"Juspay"})]}),e.jsx("optgroup",{label:"â Meta WhatsApp Payments Global â",children:e.jsx("option",{value:"stripe",children:"Stripe"})}),e.jsxs("optgroup",{label:"â Additional Gateways â",children:[e.jsx("option",{value:"cashfree",children:"Cashfree"}),e.jsx("option",{value:"phonepe",children:"PhonePe"}),e.jsx("option",{value:"ccavenue",children:"CCAvenue"}),e.jsx("option",{value:"billdesk",children:"BillDesk"}),e.jsx("option",{value:"easebuzz",children:"Easebuzz"}),e.jsx("option",{value:"instamojo",children:"Instamojo"}),e.jsx("option",{value:"paytm",children:"Paytm"})]})]})]}),l!=="upi_vpa"&&J[l]?.webhookPath&&e.jsxs("div",{className:"rounded-md bg-primary/5 border border-primary/20 p-2.5 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-[10px] font-bold text-primary uppercase tracking-wider",children:"Webhook URL"}),e.jsxs(i,{variant:"ghost",size:"sm",className:"h-6 text-[10px] gap-0.5 px-2",onClick:()=>{navigator.clipboard.writeText(_(l)),t({title:"Copied!"})},children:[e.jsx($,{className:"h-2.5 w-2.5"})," Copy"]})]}),e.jsx("code",{className:"text-[10px] text-primary break-all block leading-relaxed",children:_(l)})]}),e.jsxs("div",{children:[l==="razorpay"&&e.jsx(u,{fields:[{key:"razorpayKeyId",label:"Key ID",ph:"rzp_live_xxxxxxxxxx",secret:!1},{key:"razorpayWebhookSecret",label:"Webhook Secret",ph:"Signing secret",secret:!0}],secrets:x,onChange:h}),(l==="payu"||l==="br")&&e.jsx(u,{fields:[{key:"payuKey",label:"Merchant Key",ph:"Your PayU key",secret:!0},{key:"payuSalt",label:"Salt",ph:"v1 or v2 salt",secret:!0}],secrets:x,onChange:h}),l==="cashfree"&&e.jsx(u,{fields:[{key:"cashfreeAppId",label:"App ID",ph:"Cashfree App ID",secret:!1},{key:"cashfreeSecret",label:"Secret Key",ph:"Webhook secret",secret:!0}],secrets:x,onChange:h}),l==="ccavenue"&&e.jsx(u,{fields:[{key:"ccavenueMerchantId",label:"Merchant ID",ph:"CCAvenue ID",secret:!1},{key:"ccavenueWorkingKey",label:"Working Key",ph:"Working key",secret:!0}],secrets:x,onChange:h}),l==="billdesk"&&e.jsx(u,{fields:[{key:"billDeskMerchantId",label:"Merchant ID",ph:"BillDesk ID",secret:!1},{key:"billDeskSecret",label:"Secret Key",ph:"BillDesk secret",secret:!0}],secrets:x,onChange:h}),l==="stripe"&&e.jsx(u,{fields:[{key:"stripePublishableKey",label:"Publishable Key",ph:"pk_live_xxxxxxxxxx",secret:!1},{key:"stripeSecretKey",label:"Secret Key",ph:"sk_live_xxxxxxxxxx",secret:!0},{key:"stripeWebhookSecret",label:"Webhook Secret",ph:"whsec_xxxxxxxxxx",secret:!0}],secrets:x,onChange:h}),l==="phonepe"&&e.jsx(u,{fields:[{key:"phonePeMerchantId",label:"Merchant ID",ph:"MERCHANTID",secret:!1},{key:"phonePeSalt",label:"Salt Key",ph:"PhonePe salt",secret:!0},{key:"phonePeSaltIndex",label:"Salt Index",ph:"1",secret:!1}],secrets:x,onChange:h}),l==="juspay"&&e.jsx(u,{fields:[{key:"juspayMerchantId",label:"Merchant ID",ph:"your_merchant_id",secret:!1},{key:"juspayApiKey",label:"API Key",ph:"Juspay API key",secret:!0}],secrets:x,onChange:h}),l==="easebuzz"&&e.jsx(u,{fields:[{key:"easebuzzKey",label:"Merchant Key",ph:"Easebuzz key",secret:!0},{key:"easebuzzSalt",label:"Salt",ph:"Easebuzz salt",secret:!0}],secrets:x,onChange:h}),l==="instamojo"&&e.jsx(u,{fields:[{key:"instamojoApiKey",label:"API Key",ph:"API key",secret:!0},{key:"instamojoSalt",label:"Salt",ph:"Salt",secret:!0}],secrets:x,onChange:h}),l==="paytm"&&e.jsx(u,{fields:[{key:"paytmMerchantId",label:"Merchant ID",ph:"PAYTM_MERCHANT_ID",secret:!1},{key:"paytmMerchantKey",label:"Merchant Key",ph:"Merchant key",secret:!0}],secrets:x,onChange:h}),l==="upi_vpa"&&e.jsx(u,{fields:[{key:"upiVpa",label:"Merchant VPA",ph:"yourbusiness@upi",secret:!1}],secrets:x,onChange:h})]}),(()=>{const a=ea[l==="upi_vpa"?"upi_vpa":"gateway"];return e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-3 space-y-2",children:[e.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"On success â what happens"}),e.jsx("p",{className:"text-[11px] leading-relaxed text-foreground",children:a.summary}),e.jsx("ol",{className:"space-y-1 list-decimal list-inside",children:a.steps.map((n,f)=>e.jsx("li",{className:"text-[11px] leading-relaxed text-muted-foreground",children:n},f))}),a.payload&&e.jsxs("div",{children:[e.jsx("p",{className:"text-[10px] font-semibold text-muted-foreground mb-1",children:"Payload we receive"}),e.jsx("pre",{className:"text-[10px] leading-relaxed bg-background border border-border rounded p-2 overflow-x-auto text-foreground",children:a.payload})]})]})})(),e.jsxs("div",{className:"rounded-lg border border-border bg-muted/30 p-3 space-y-2.5",children:[e.jsx("p",{className:"text-[10px] font-bold text-muted-foreground uppercase tracking-wider",children:"Test the receive side"}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-muted-foreground",children:"Your WhatsApp webhook (Meta posts here)"}),e.jsxs(i,{variant:"ghost",size:"sm",className:"h-6 text-[10px] gap-0.5 px-2",onClick:()=>{navigator.clipboard.writeText(I),t({title:"Copied!"})},children:[e.jsx($,{className:"h-2.5 w-2.5"})," Copy"]})]}),e.jsxs("code",{className:"text-[10px] text-primary break-all block",children:["POST ",I]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1",children:[e.jsx("span",{className:"text-[10px] font-semibold text-muted-foreground",children:"Replay it yourself"}),e.jsxs(i,{variant:"ghost",size:"sm",className:"h-6 text-[10px] gap-0.5 px-2",onClick:()=>{navigator.clipboard.writeText(G),t({title:"cURL copied!"})},children:[e.jsx($,{className:"h-2.5 w-2.5"})," Copy cURL"]})]}),e.jsx("pre",{className:"text-[10px] leading-relaxed bg-background border border-border rounded p-2 overflow-x-auto text-foreground",children:G})]}),e.jsxs("div",{className:"border-t border-border pt-2.5 space-y-1.5",children:[e.jsx("p",{className:"text-[10px] font-semibold text-muted-foreground",children:"Or simulate one â same code path, receipt and all"}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{value:k,onChange:a=>K(a.target.value),placeholder:"ORD-20260802-0001",className:"flex-1 h-8 px-2 text-[11px] rounded-md border border-border bg-background text-foreground font-mono"}),e.jsx(i,{size:"sm",className:"h-8 text-[11px] px-3",disabled:!k||g,onClick:async()=>{A(!0);try{const{data:a}=await y.post(j.payments.simulate,{referenceId:k,status:"completed"});t({title:"Payment simulated â
",description:a.note||`${k} marked paid.`})}catch(a){t({title:"Simulation failed",description:a.response?.data?.error||a.message,variant:"destructive"})}finally{A(!1)}},children:g?e.jsx(S,{className:"h-3 w-3 animate-spin"}):"Simulate"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground leading-relaxed",children:"Use a real order number. It confirms the order, sends the paid receipt, and updates the payment card in the chat â exactly what a real payment does."})]})]}),e.jsxs("div",{className:"pt-1",children:[e.jsxs(i,{size:"sm",className:"w-full h-9 gap-1.5 wa-gradient border-0 text-primary-foreground hover:opacity-90",onClick:Se,disabled:X,children:[X?e.jsx(S,{className:"h-3.5 w-3.5 animate-spin"}):pe?e.jsx(E,{className:"h-3.5 w-3.5"}):e.jsx(ne,{className:"h-3.5 w-3.5"}),X?"Savingâ¦":pe?"Saved â":"Save Credentials"]}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center mt-2",children:"Stored securely ·
10never in .env · unique per account"})]})]})]}),e.jsxs("div",{className:"rounded-xl border border-border bg-card overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 border-b border-border bg-muted/30",children:e.jsx("p",{className:"text-xs font-bold text-foreground",children:"Setup Guide"})}),e.jsx("div",{className:"p-4 space-y-3",children:[{n:"1",t:"Create",d:"Choose Razorpay, PayU, or UPI VPA and set your Merchant Category Code."},{n:"2",t:"Authorize",d:"For payment gateways â open the OAuth link and complete merchant authorization."},{n:"3",t:"Test",d:"When status is Needs Testing, open WhatsApp Manager â India Payments and click Test."},{n:"4",t:"Activate",d:"Click Refresh Status to confirm it moved to Active. Then use the config name in flow nodes."}].map(a=>e.jsxs("div",{className:"flex gap-3",children:[e.jsx("div",{className:"w-5 h-5 rounded-md bg-foreground text-background text-[10px] font-bold flex items-center justify-center shrink-0 mt-0.5",children:a.n}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-bold text-foreground",children:a.t}),e.jsx("p",{className:"text-[11px] text-muted-foreground leading-relaxed mt-0.5",children:a.d})]})]},a.n))})]})]})]})]})]})}export{na 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.