1import{r as a,j as e}from"./vendor-react-B-3LVNtP.js";import{c as $,B as J}from"./index-BEQqEzCH.js";import{I as N}from"./input-DJWHaYx0.js";import{L as E}from"./loader-circle-BCzTKmqW.js";const w=a.forwardRef(({className:n,...l},m)=>e.jsx("textarea",{className:$("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-sm placeholder:text-gray-400 dark:placeholder:text-gray-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:m,...l}));w.displayName="Textarea";function L(n){try{return JSON.stringify(n,null,2)}catch{return String(n)}}function v({mode:n="package"}){const l=n==="package",m=l?"package_id":"plan_id",T=l?"SecurePay Tinkoff package init":"SecurePay Tinkoff plan init",S=a.useMemo(()=>localStorage.getItem("token")||localStorage.getItem("jwt_token")||"",[]),[x,_]=a.useState("https://api.neirochat.io"),[p,B]=a.useState("1"),[u,P]=a.useState(S),[b,g]=a.useState(!1),[o,f]=a.useState(null),[I,y]=a.useState(""),[k,i]=a.useState(""),c=a.useMemo(()=>{const t=x.trim().replace(/\/+$/,""),d=Number(p)||1;return l?{url:`${t}/api/payments/securepay_tinkoff/packages/${d}/init`,body:{}}:{url:`${t}/api/payments/securepay_tinkoff/plans/init`,body:{plan_id:d}}},[x,p,l]),O=a.useMemo(()=>{const t=u.trim()||"YOUR_JWT_TOKEN";return[`curl -X POST '${c.url}' \\`," -H 'Content-Type: application/json' \\",` -H 'Authorization: Bearer ${t}' \\`,` -d '${JSON.stringify(c.body,null,2)}'`].join(` 2`)},[c,u]),R=async t=>{t.preventDefault();const d=Number(p),j=u.trim();if(!x.trim()){i("Base URL is required.");return}if(!Number.isInteger(d)||d<=0){i(`${m} must be a positive integer.`);return}if(!j){i("JWT token is required.");return}g(!0),i(""),f(null),y("");try{const r=await fetch(c.url,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${j}`},body:JSON.stringify(c.body)}),h=await r.text();let s=h;try{s=h?JSON.parse(h):null}catch{}f({ok:r.ok,status:r.status,statusText:r.statusText}),y(typeof s=="string"?s:L(s)),r.ok&&s&&typeof s=="object"&&typeof s.payment_url=="string"&&s.payment_url.trim()&&window.open(s.payment_url,"_blank","noopener,noreferrer")}catch(r){i(r.message||"Request failed.")}finally{g(!1)}};return e.jsx("div",{className:"min-h-screen bg-neutral-950 text-white",children:e.jsxs("div",{className:"mx-auto flex w-full max-w-5xl flex-col gap-8 px-4 py-10 sm:px-6 lg:px-8",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-xs font-medium uppercase tracking-[0.28em] text-emerald-400/80",children:"Payment Testing"}),e.jsx("h1",{className:"text-3xl font-semibold tracking-tight sm:text-4xl",children:T}),e.jsx("p",{className:"max-w-3xl text-sm text-neutral-400 sm:text-base",children:"Internal page for testing the new payment endpoint from the browser with the current JWT."})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-[minmax(0,1fr)_minmax(320px,420px)]",children:[e.jsxs("form",{onSubmit:R,className:"space-y-5 rounded-3xl border border-white/10 bg-white/[0.03] p-6 shadow-[0_20px_80px_rgba(0,0,0,0.35)] backdrop-blur",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"payment-base-url",className:"text-sm font-medium text-neutral-200",children:"Base URL"}),e.jsx(N,{id:"payment-base-url",value:x,onChange:t=>_(t.target.value),placeholder:"https://api.neirochat.io",className:"border-white/10 bg-black/20 text-white placeholder:text-neutral-500"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"payment-entity-id",className:"text-sm font-medium text-neutral-200",children:m}),e.jsx(N,{id:"payment-entity-id",type:"number",min:"1",step:"1",value:p,onChange:t=>B(t.target.value),className:"border-white/10 bg-black/20 text-white placeholder:text-neutral-500"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{htmlFor:"payment-token",className:"text-sm font-medium text-neutral-200",children:"JWT token"}),e.jsx(w,{id:"payment-token",value:u,onChange:t=>P(t.target.value),placeholder:"Bearer token without the Bearer prefix",className:"min-h-[140px] border-white/10 bg-black/20 font-mono text-xs text-white placeholder:text-neutral-500"}),e.jsx("p",{className:"text-xs text-neutral-500",children:"Auto-filled from `localStorage.token` or `localStorage.jwt_token`."})]}),e.jsx("div",{className:"flex items-center gap-3",children:e.jsxs(J,{type:"submit",disabled:b,className:"bg-emerald-500 text-black hover:bg-emerald-400",children:[b?e.jsx(E,{className:"h-4 w-4 animate-spin"}):null,"Send request"]})}),k?e.jsx("div",{className:"rounded-2xl border border-red-500/30 bg-red-500/10 px-4 py-3 text-sm text-red-700 dark:text-red-200",children:k}):null,o?e.jsx("div",{className:"rounded-2xl border border-white/10 bg-black/20 px-4 py-3 text-sm",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("span",{className:`inline-flex rounded-full px-2.5 py-1 text-xs font-medium ${o.ok?"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300":"bg-red-500/15 text-red-700 dark:text-red-300"}`,children:o.ok?"Success":"Failed"}),e.jsxs("span",{className:"text-neutral-300",children:["HTTP ",o.status," ",o.statusText]})]})}):null]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("section",{className:"rounded-3xl border border-white/10 bg-[#0d1117] p-5",children:[e.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:e.jsx("h2",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-neutral-300",children:"cURL preview"})}),e.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-all rounded-2xl bg-black/30 p-4 font-mono text-xs text-neutral-200",children:O})]}),e.jsxs("section",{className:"rounded-3xl border border-white/10 bg-[#0d1117] p-5",children:[e.jsx("h2",{className:"mb-3 text-sm font-semibold uppercase tracking-[0.18em] text-neutral-300",children:"Response body"}),e.jsx("pre",{className:"min-h-[280px] overflow-x-auto whitespace-pre-wrap break-all rounded-2xl bg-black/30 p-4 font-mono text-xs text-neutral-200",children:I||"No response yet."})]})]})]})]})})}function F(){return e.jsx(v,{mode:"package"})}function W(){return e.jsx(v,{mode:"plan"})}export{F as PackagePaymentEndpointTesting,W as PlanPaymentEndpointTesting,v 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.