PageSourceSearch

https://renderkind.ai/assets/Billing-DwVIpD2b.js

js renderkind.ai collected 2026-10-05 13:53:29 UTC 7,971 bytes, 1 lines download raw bytes

1import{r,A as g,j as e,T as $,L as f}from"./index-B_1WTwD0.js";const j=(n,d="USD")=>new Intl.NumberFormat(void 0,{style:"currency",currency:d}).format(n/100),t=n=>new Date(n).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"}),c=n=>n.split("_").map(d=>`${d.charAt(0).toUpperCase()}${d.slice(1)}`).join(" "),w=n=>n.status==="expired"?"Expired":n.cancelAtPeriodEnd?`Cancels on ${t(n.currentPeriodEnd)}`:n.providerStatus==="past_due"?"Payment past due":`Renews on ${t(n.currentPeriodEnd)}`;function L(){const[n,d]=r.useState(null),[u,x]=r.useState(!1),[a,p]=r.useState(null),[v,o]=r.useState(null),[C,h]=r.useState(!1),b=r.useCallback(async()=>{x(!0),o(null);try{const s=await fetch(`${g}/api/billing`,{credentials:"include"}),l=await s.json();if(!s.ok)throw new Error(l?.error||"Failed to load billing.");d(l)}catch(s){o(s instanceof Error?s.message:"Failed to load billing.")}finally{x(!1)}},[]);r.useEffect(()=>{b()},[b]);const y=async s=>{p(s),o(null);try{const l=await fetch(`${g}/api/subscription/${s}`,{method:"POST",credentials:"include"}),k=await l.json();if(!l.ok)throw new Error(k?.error||`Failed to ${s} subscription.`);h(!1),await b()}catch(l){o(l instanceof Error?l.message:`Failed to ${s} subscription.`)}finally{p(null)}},P=async()=>{p("manage"),o(null);try{const s=await fetch(`${g}/api/subscription/manage`,{credentials:"include"}),l=await s.json();if(!s.ok||!l?.url)throw new Error(l?.error||"Subscription management portal is unavailable.");window.location.href=l.url}catch(s){o(s instanceof Error?s.message:"Failed to open subscription management portal.")}finally{p(null)}},i=n?.subscription||null,m=n?.plan||null,E=n?.payment||null,N=n?.subscriptions.filter(s=>s.id!==i?.id)||[],S=m?m.key!=="free"&&m.nickname?`${m.name} (${m.nickname})`:m.name:i?c(i.planKey):"Free";return e.jsxs("div",{className:"simple-page",children:[e.jsx($,{}),e.jsxs("div",{className:"simple-card billing-card",children:[e.jsxs("div",{className:"billing-page-head",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"simple-title",children:"Billing & Plan"}),e.jsx("p",{className:"simple-subtitle",children:"Manage your membership, payments, and renewals."})]}),e.jsx(f,{className:"admin-save billing-change-plan",to:"/pricing",children:"Change plan"})]}),v&&e.jsx("div",{className:"inventory-error",children:v}),u&&!n&&e.jsx("div",{className:"inventory-empty",children:"Loading billing..."}),!u&&!i&&e.jsxs("div",{className:"billing-empty-state",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"No paid subscription"}),e.jsx("span",{children:"Choose a plan when you are ready for more credits and features."})]}),e.jsx(f,{className:"admin-save",to:"/pricing",children:"View plans"})]}),i&&e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"billing-overview",children:[e.jsxs("div",{className:"billing-plan-summary",children:[e.jsx("span",{className:"billing-eyebrow",children:"Current membership"}),e.jsx("div",{className:"billing-plan-name",children:S}),e.jsxs("div",{className:`billing-status${i.cancelAtPeriodEnd?" is-warning":""}`,children:[e.jsx("span",{}),w(i)]}),e.jsxs("div",{className:"billing-plan-price",children:[j(i.priceCents,i.currency),e.jsxs("span",{children:[" / ",i.billing==="annual"?"year":i.billing==="weekly"?"week":"month"]})]}),e.jsxs("div",{className:"billing-actions",children:[i.cancelAtPeriodEnd?e.jsx("button",{type:"button",className:"admin-save",onClick:()=>{y("resume")},disabled:a!==null,children:a==="resume"?"Resuming...":"Resume subscription"}):i.status==="active"?e.jsx("button",{type:"button",className:"admin-delete",onClick:()=>h(!0),disabled:a!==null,children:"Cancel subscription"}):null,i.provider==="lemonsqueezy"&&e.jsx("button",{type:"button",className:"inventory-refresh",onClick:()=>{P()},disabled:a!==null,children:a==="manage"?"Opening...":"Manage payment method"})]})]}),e.jsxs("div",{className:"billing-metrics",children:[e.jsxs("div",{className:"billing-metric",children:[e.jsx("span",{children:"Plan credits remaining"}),e.jsx("strong",{children:Number(n?.creditUsage?.planRemaining??n?.creditUsage?.remaining??0).toLocaleStr
1ing()})]}),e.jsxs("div",{className:"billing-metric",children:[e.jsx("span",{children:"Add-on credits"}),e.jsx("strong",{children:Number(n?.creditUsage?.addonRemaining??0).toLocaleString()})]}),e.jsxs("div",{className:"billing-metric",children:[e.jsx("span",{children:i.cancelAtPeriodEnd?"Access until":"Next renewal"}),e.jsx("strong",{children:t(i.currentPeriodEnd)})]}),e.jsxs("div",{className:"billing-metric",children:[e.jsx("span",{children:"Billing provider"}),e.jsx("strong",{children:c(i.provider)})]})]})]}),E?.status==="failed"&&e.jsx("div",{className:"inventory-error",children:"Your latest subscription payment failed. Update your payment method to avoid interruption."})]}),e.jsxs("section",{className:"billing-section",children:[e.jsx("div",{className:"billing-section-head",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Payment history"}),e.jsx("p",{children:"Subscription payments, add-on purchases, failures, and refunds."})]})}),e.jsxs("div",{className:"billing-table",children:[e.jsxs("div",{className:"billing-table-row billing-table-row--head",children:[e.jsx("span",{children:"Date"}),e.jsx("span",{children:"Item"}),e.jsx("span",{children:"Provider"}),e.jsx("span",{children:"Status"}),e.jsx("span",{children:"Amount"})]}),(n?.payments||[]).map(s=>e.jsxs("div",{className:"billing-table-row",children:[e.jsx("span",{children:t(s.createdAt)}),e.jsx("span",{children:c(s.planKey)}),e.jsx("span",{children:c(s.provider)}),e.jsx("span",{className:`billing-payment-status is-${s.status}`,children:s.status}),e.jsx("strong",{children:j(s.amountCents,s.currency)})]},s.id)),!u&&(n?.payments||[]).length===0&&e.jsx("div",{className:"inventory-empty",children:"No payments yet."})]})]}),e.jsxs("section",{className:"billing-section",children:[e.jsx("div",{className:"billing-section-head",children:e.jsxs("div",{children:[e.jsx("h2",{children:"Previous subscriptions"}),e.jsx("p",{children:"Your canceled and expired memberships."})]})}),e.jsxs("div",{className:"billing-subscription-history",children:[N.map(s=>e.jsxs("div",{className:"billing-history-card",children:[e.jsxs("div",{children:[e.jsx("strong",{children:c(s.planKey)}),e.jsxs("span",{children:[c(s.billing)," billing · ",c(s.provider)]})]}),e.jsxs("div",{children:[e.jsx("strong",{children:w(s)}),e.jsxs("span",{children:[t(s.currentPeriodStart)," - ",t(s.currentPeriodEnd)]})]}),e.jsx("strong",{children:j(s.priceCents,s.currency)})]},s.id)),!u&&N.length===0&&e.jsx("div",{className:"inventory-empty",children:"No previous subscriptions."})]})]})]}),C&&i&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"history-modal-backdrop",role:"button","aria-label":"Close confirmation",onClick:()=>h(!1)}),e.jsxs("div",{className:"history-modal billing-cancel-modal",role:"dialog","aria-modal":"true","aria-labelledby":"billing-cancel-title",children:[e.jsxs("div",{className:"history-modal-header",children:[e.jsxs("div",{children:[e.jsx("div",{className:"history-modal-title",id:"billing-cancel-title",children:"Cancel subscription?"}),e.jsx("div",{className:"history-modal-subtitle",children:"Renewal will stop, but your current access and remaining plan credits stay available."})]}),e.jsx("button",{type:"button",className:"history-modal-close billing-cancel-close","aria-label":"Close confirmation",onClick:()=>h(!1),children:"X"})]}),e.jsxs("div",{className:"billing-cancel-summary",children:[e.jsx("span",{children:"Access until"}),e.jsx("strong",{children:t(i.currentPeriodEnd)})]}),e.jsxs("div",{className:"billing-cancel-actions",children:[e.jsx("button",{type:"button",className:"admin-delete billing-cancel-danger",onClick:()=>{y("cancel")},disabled:a!==null,children:a==="cancel"?"Canceling...":"Confirm cancellation"}),e.jsx("button",{type:"button",className:"admin-save",onClick:()=>h(!1),children:"Keep subscription"})]})]})]})]})}export{L 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.