PageSourceSearch

https://www.smart-company.ai/assets/AdminStripe-CqKUvNYL.js

js smart-company.ai collected 2026-10-05 14:59:13 UTC 17,225 bytes, 6 lines download raw bytes

1import{c as $,r as p,s as E,a as w,j as e,aE as v,aF as C,aG as b,aH as S,aI as k,aJ as T,B as j,aK as K,aL as D,a9 as z,o as q,p as V,q as B,t as G,v as Y,w as Q,x as W,y as X,l as y,L as _,I as P,aM as I,E as U,d as Z,aN as ee,aO as se,i as te,aP as re,aQ as ae,D as ne,Y as O,ac as ie,ad as ce,ae as oe,af as le,ag as de}from"./index-BQSuW3M2.js";const me=$("TrendingDown",[["polyline",{points:"22 17 13.5 8.5 8.5 13.5 2 7",key:"1r2t7k"}],["polyline",{points:"16 17 22 17 22 11",key:"11uiuu"}]]);const pe=$("Webhook",[["path",{d:"M18 16.98h-5.99c-1.1 0-1.95.94-2.48 1.9A4 4 0 0 1 2 17c.01-.7.2-1.4.57-2",key:"q3hayz"}],["path",{d:"m6 17 3.13-5.78c.53-.97.1-2.18-.5-3.1a4 4 0 1 1 6.89-4.06",key:"1go1hn"}],["path",{d:"m12 6 3.13 5.73C15.66 12.7 16.9 13 18 13a4 4 0 0 1 0 8",key:"qlwsc0"}]]),N="stripe_config_cache",he=300*1e3,ue=()=>{const[t,r]=p.useState(null),[c,s]=p.useState(!0),[a,l]=p.useState(null),i=p.useCallback(async()=>{try{s(!0),l(null);const h=localStorage.getItem(N);if(h){const g=JSON.parse(h);if(Date.now()-g.timestamp<he){r(g.data),s(!1);return}}const{data:n,error:o}=await E.functions.invoke("stripe-admin-config",{method:"GET"});if(o)throw new Error(o.message);if(n.error)throw new Error(n.error);r(n);const x={data:n,timestamp:Date.now()};localStorage.setItem(N,JSON.stringify(x))}catch(h){const n=h instanceof Error?h.message:"Failed to fetch configuration";l(n),console.error("Error fetching Stripe config:",h)}finally{s(!1)}},[]),u=p.useCallback(async h=>{try{s(!0),l(null);const{data:n,error:o}=await E.functions.invoke("stripe-admin-config/update-mode",{method:"POST",body:{mode:h}});if(o)throw new Error(o.message);if(n.error){if(n.error_code==="MANUAL_UPDATE_REQUIRED"&&n.instructions){const x=n.instructions;throw new Error(`Mode switch requires manual update.
2
3Run this command:
4${x.command}
5
6Then refresh the page.`)}throw new Error(n.error)}if(n.config){r(n.config);const x={data:n.config,timestamp:Date.now()};localStorage.setItem(N,JSON.stringify(x))}localStorage.removeItem(N),await i()}catch(n){const o=n instanceof Error?n.message:"Failed to update mode";throw l(o),n}finally{s(!1)}},[i]),d=p.useCallback(async h=>{try{s(!0),l(null);const{data:n,error:o}=await E.functions.invoke("stripe-admin-config/update-keys",{method:"POST",body:h});if(o)throw new Error(o.message);if(n.error)throw new Error(n.error);localStorage.removeItem(N),await i()}catch(n){const o=n instanceof Error?n.message:"Failed to update keys";throw l(o),n}finally{s(!1)}},[i]),m=p.useCallback(async h=>{try{s(!0),l(null),console.log("Updating default currency to:",h),localStorage.removeItem(N),await i()}catch(n){const o=n instanceof Error?n.message:"Failed to update currency";throw l(o),n}finally{s(!1)}},[i]);return p.useEffect(()=>{i()},[i]),{config:t,loading:c,error:a,refetch:i,updateMode:u,updateKeys:d,updateDefaultCurrency:m}},xe="stripe_stats_cache_",fe=900*1e3,ye=t=>{const[r,c]=p.useState(null),[s,a]=p.useState(!0),[l,i]=p.useState(null),u=p.useCallback(async()=>{try{a(!0),i(null);const d=`${xe}${t}`,m=localStorage.getItem(d);if(m){const x=JSON.parse(m);if(Date.now()-x.timestamp<fe){c(x.data),a(!1);return}}const{data:h,error:n}=await E.functions.invoke("stripe-admin-config/statistics",{method:"GET"});if(n)throw new Error(n.message);if(h.error)throw new Error(h.error);c(h);const o={data:h,timestamp:Date.now()};localStorage.setItem(d,JSON.stringify(o))}catch(d){const m=d instanceof Error?d.message:"Failed to fetch statistics";i(m),console.error("Error fetching Stripe stats:",d)}finally{a(!1)}},[t]);return p.useEffect(()=>{u()},[u]),{stats:r,loading:s,error:l,refetch:u}},ge=({config:t,onModeSwitch:r,isLoading:c})=>{const{t:s}=w(),[a,l]=p.useState(!1),[i,u]=p.useState(null),[d,m]=p.useState(!1),h=x=>{u(x),l(!0)},n=async()=>{if(i)try{m(!0),await r(i),y.success(s("admin.stripe.config.switch_success").replace("{mode}",i))}catch(x){const g=x instanceof Error?x.message:"Unknown error";y.error(s("admin.stripe.config.switch_error").replace("{error}",g))}finally{m(!1),l(!1),u(null)}},o=[];return t.testKeyConfigured||o.push("Test Key"),t.prodKeyConfigured||o.push("Production Key"),e.jsxs(e.Fragment,{children:[e.jsxs(v,{children:[e.jsxs(C,{children:[e.jsx(b,{children:s("admin.stripe.config.title")}),e.jsx(S,{children:s("admin.stripe.description")})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s("admin.stripe.config.current_mode")}),e.jsx("div",{className:"flex items-center gap-2 mt-1",children:e.jsx(T,{variant:t.mode==="test"?"secondary":"default",children:t.mode==="test"?s("admin.stripe.config.mode.test"):s("admin.stripe.config.mode.production")})})]}),e.jsx(j,{onClick:()=>h(t.mode==="test"?"production":"test"),disabled:c||d,variant:"outline",children:s("admin.stripe.config.switch_mode")})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:"API Keys"}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.testKeyConfigured?e.jsx(K,{className:"h-4 w-4 text-green-600"}):e.jsx(D,{className:"h-4 w-4 text-red-600"}),e.jsxs("span",{children:[s("admin.stripe.keys.test_key"),":"," ",t.testKeyConfigured?t.testKeyLast4:s("admin.stripe.keys.not_configured")]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[t.prodKeyConfigured?e.jsx(K,{className:"h-4 w-4 text-green-600"}):e.jsx(D,{className:"h-4 w-4 text-red-600"}),e.jsxs("span",{children:[s("admin.stripe.keys.prod_key"),":"," ",t.prodKeyConfigured?t.prodKeyLast4:s("admin.stripe.keys.not_configured")]})]})]})]}),o.length>0&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-yellow-50 border border-yellow-200 rounded-md",children:[e.jsx(z,{className:"h-5 w-5 text-yellow-600 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-yellow-800",children:s("admin.stripe.keys.warning_missing")}),e.jsx("p",{className:"text-sm text-yellow-700 mt-1",children:o.join(", ")})]})]})]})]}),e.jsx(q,{open:a,onOpenChange:l,children:e.jsxs(V,{children:[e.jsxs(B,{children:[e.jsx(G,{children:s("admin.stripe.config.switch_confirm_title")}),e.jsx(Y,{children:s("admin.stripe.config.switch_confirm_message").replace("{mode}",i||"")})]}),e.jsxs(Q,{children:[e.jsx(W,{disabled:d,children:s("admin.stripe.cancel")}),e.jsx(X,{onClick:n,disabled:d,children:s(d?"admin.stripe.loading":"admin.stripe.confirm")})]})]})})]})},L=t=>t?/^sk_(test|live)_[a-zA-Z0-9]+$/.test(t):!1,je=(t,r)=>`https://dashboard.stripe.com${t==="test"?"/test":""}${{home:"",payments:"/payments",customers:"/customers",webhooks:"/webhooks","api-keys":"/apikeys"}[r]}`,we=(t,r)=>
6{const s={usd:{symbol:"$",decimals:2},eur:{symbol:"€",decimals:2},chf:{symbol:"CHF ",decimals:2}}[r.toLowerCase()]||{symbol:r.toUpperCase()+" ",decimals:2},a=Math.pow(10,s.decimals),l=(t/a).toFixed(s.decimals);return`${s.symbol}${l}`},F=t=>({usd:"$9.99",eur:"€8.99",chf:"CHF 9.90"})[t.toLowerCase()]||`${t.toUpperCase()} 9.99`,Ne=({config:t,onSaveKeys:r,isLoading:c})=>{const{t:s}=w(),[a,l]=p.useState(""),[i,u]=p.useState(""),[d,m]=p.useState(!1),[h,n]=p.useState(!1),[o,x]=p.useState(!1),[g,A]=p.useState({}),H=()=>{const f={};return a&&!L(a)&&(f.testKey=s("admin.stripe.keys.invalid_format")),i&&!L(i)&&(f.prodKey=s("admin.stripe.keys.invalid_format")),A(f),Object.keys(f).length===0},R=async()=>{if(!H())return;const f={};if(a&&(f.testKey=a),i&&(f.prodKey=i),Object.keys(f).length===0){y.error("No keys to save");return}try{x(!0),await r(f),y.success(s("admin.stripe.keys.save_success")),l(""),u(""),m(!1),n(!1)}catch(M){const J=M instanceof Error?M.message:"Unknown error";y.error(s("admin.stripe.keys.save_error").replace("{error}",J))}finally{x(!1)}};return e.jsxs(v,{children:[e.jsxs(C,{children:[e.jsx(b,{children:s("admin.stripe.keys.title")}),e.jsx(S,{children:"Update Stripe API keys for test and production environments"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"testKey",children:s("admin.stripe.keys.test_key")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(P,{id:"testKey",type:d?"text":"password",value:a,onChange:f=>l(f.target.value),placeholder:t.testKeyLast4||"sk_test_...",disabled:c||o}),g.testKey&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:g.testKey})]}),e.jsx(j,{type:"button",variant:"outline",size:"icon",onClick:()=>m(!d),disabled:c||o,children:d?e.jsx(I,{className:"h-4 w-4"}):e.jsx(U,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"prodKey",children:s("admin.stripe.keys.prod_key")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx(P,{id:"prodKey",type:h?"text":"password",value:i,onChange:f=>u(f.target.value),placeholder:t.prodKeyLast4||"sk_live_...",disabled:c||o}),g.prodKey&&e.jsx("p",{className:"text-sm text-red-600 mt-1",children:g.prodKey})]}),e.jsx(j,{type:"button",variant:"outline",size:"icon",onClick:()=>n(!h),disabled:c||o,children:h?e.jsx(I,{className:"h-4 w-4"}):e.jsx(U,{className:"h-4 w-4"})})]})]}),e.jsx(j,{onClick:R,disabled:c||o||!a&&!i,className:"w-full",children:s(o?"admin.stripe.loading":"admin.stripe.keys.save")})]})]})},ve=({mode:t})=>{const{t:r}=w(),c=[{label:r("admin.stripe.dashboard.payments"),icon:Z,section:"payments"},{label:r("admin.stripe.dashboard.customers"),icon:ee,section:"customers"},{label:r("admin.stripe.dashboard.webhooks"),icon:pe,section:"webhooks"},{label:r("admin.stripe.dashboard.api_keys"),icon:se,section:"api-keys"}];return e.jsxs(v,{children:[e.jsxs(C,{children:[e.jsx(b,{children:r("admin.stripe.dashboard.title")}),e.jsx(S,{children:r("admin.stripe.dashboard.description")})]}),e.jsx(k,{children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:c.map(s=>{const a=s.icon;return e.jsx(j,{variant:"outline",className:"justify-start",asChild:!0,children:e.jsxs("a",{href:je(t,s.section),target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2",children:[e.jsx(a,{className:"h-4 w-4"}),e.jsx("span",{className:"flex-1",children:s.label}),e.jsx(te,{className:"h-4 w-4"})]})},s.section)})})})]})},Ce=({stats:t,mode:r,isLoading:c,onRefresh:s})=>{const{t:a}=w();return e.jsxs(v,{children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(b,{children:a("admin.stripe.stats.title")}),e.jsxs("div",{className:"flex items-center gap-2 mt-1.5",children:[e.jsx(S,{className:"mb-0",children:a("admin.stripe.stats.period")}),e.jsx(T,{variant:r==="test"?"secondary":"default",children:a(r==="test"?"admin.stripe.stats.test_data":"admin.stripe.stats.production_data")})]})]}
6),e.jsx(j,{variant:"outline",size:"icon",onClick:s,disabled:c,children:e.jsx(re,{className:`h-4 w-4 ${c?"animate-spin":""}`})})]})}),e.jsx(k,{children:c&&!t?e.jsx("p",{className:"text-sm text-muted-foreground",children:a("admin.stripe.stats.loading")}):t?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ae,{className:"h-4 w-4 text-green-600"}),a("admin.stripe.stats.successful_payments")]}),e.jsx("p",{className:"text-2xl font-bold",children:t.successfulPayments30d})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(me,{className:"h-4 w-4 text-red-600"}),a("admin.stripe.stats.failed_payments")]}),e.jsx("p",{className:"text-2xl font-bold",children:t.failedPayments30d})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(ne,{className:"h-4 w-4 text-blue-600"}),a("admin.stripe.stats.total_revenue")]}),e.jsx("p",{className:"text-2xl font-bold",children:we(t.totalRevenue30d*100,t.currency.toLowerCase())})]})]}):e.jsx("p",{className:"text-sm text-red-600",children:a("admin.stripe.stats.error")})})]})},be=({mode:t})=>{const{t:r}=w(),[c,s]=p.useState(!1),[a,l]=p.useState(null),i=async()=>{try{s(!0),l(null);const{data:u,error:d}=await E.functions.invoke("stripe-admin-config/test-connection",{method:"POST",body:{mode:t}});if(d)throw new Error(d.message);l(u),u.success?y.success(r("admin.stripe.connection.success")):y.error(r("admin.stripe.connection.error").replace("{error}",u.error||"Unknown error"))}catch(u){const d=u instanceof Error?u.message:"Unknown error";l({success:!1,error:d}),y.error(r("admin.stripe.connection.error").replace("{error}",d))}finally{s(!1)}};return e.jsxs(v,{children:[e.jsxs(C,{children:[e.jsx(b,{children:r("admin.stripe.connection.title")}),e.jsx(S,{children:r("admin.stripe.connection.testing_credentials").replace("{mode}",t)})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsx(j,{onClick:i,disabled:c,className:"w-full",children:c?e.jsxs(e.Fragment,{children:[e.jsx(O,{className:"mr-2 h-4 w-4 animate-spin"}),r("admin.stripe.connection.testing")]}):r("admin.stripe.connection.test_button")}),a&&e.jsx("div",{className:`p-4 rounded-md border ${a.success?"bg-green-50 border-green-200":"bg-red-50 border-red-200"}`,children:e.jsxs("div",{className:"flex items-start gap-2",children:[a.success?e.jsx(K,{className:"h-5 w-5 text-green-600 mt-0.5"}):e.jsx(D,{className:"h-5 w-5 text-red-600 mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:`font-medium ${a.success?"text-green-800":"text-red-800"}`,children:a.success?r("admin.stripe.connection.success"):r("admin.stripe.error")}),a.success&&a.accountName&&e.jsxs("div",{className:"mt-2 space-y-1 text-sm",children:[e.jsxs("p",{children:[e.jsxs("span",{className:"font-medium",children:[r("admin.stripe.connection.account_name"),":"]})," ",a.accountName]}),e.jsxs("p",{children:[e.jsxs("span",{className:"font-medium",children:[r("admin.stripe.connection.account_id"),":"]})," ",e.jsx(T,{variant:"secondary",children:a.accountId})]})]}),!a.success&&a.error&&e.jsx("p",{className:"mt-1 text-sm text-red-700",children:a.error})]})]})})]})]})},Se=({config:t,onUpdateDefaultCurrency:r,isLoading:c})=>{const{t:s}=w(),[a,l]=p.useState(t.defaultCurrency),[i,u]=p.useState(!1),d=async()=>{if(a===t.defaultCurrency){y.info("No changes to save");return}try{u(!0),await r(a),y.success(s("admin.stripe.currency.save_success"))}catch(m){const h=m instanceof Error?m.message:"Unknown error";y.error(s("admin.stripe.currency.save_error").replace("{error}",h))}finally{u(!1)}};return e.jsxs(v,{children:[e.jsxs(C,{children:[e.jsx(b,{children:s("admin.stripe.currency.title")}),e.jsx(S,{children:"Configure supported currencies and default currency for payments"})]}),e.jsxs(k,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(_,{className:"text-sm font-medium",children:s("admin.stripe.currency.supported")}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:t.supportedCurrencies.map(m=>e.jsxs("div",{className:"px-3 py-1 bg-secondary text-secondary-foreground rounded-md text-sm",children:[m.toUpperCase()," - ",F(m)]},m))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{htmlFor:"defaultCurrency",children:s("admin.stripe.currency.default")}),e.jsxs(ie,{value:a,onValueChange:l,disabled:c||i,children:[e.jsx(ce,{id:"defaultCurrency",children:e.jsx(oe,{})}),e.jsx(le,{children:t.supportedCurrencies.map(m=>e.jsxs(de,{value:m,children:[m.toUpperCase()," - ",F(m)]},m))})]})]}),e.jsx(j,{onClick:d,disabled:c||i||a===t.defaultCurrency,className:"w-full",children:s(i?"admin.stripe.loading":"admin.stripe.currency.save")})]})]})},Ee=()=>{const{t}=w(),{config:r,loading:c,error:s,updateMode:a,updateKeys:l,updateDefaultCurrency:i}=ue(),{stats:u,loading:d,refetch:m}=ye(r?.mode||"test");return c&&!r?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx(O,{className:"h-8 w-8 animate-spin text-muted-foreground"})}
6):s?e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsxs("div",{className:"text-center space-y-2",children:[e.jsx("p",{className:"text-red-600 font-medium",children:t("admin.stripe.error")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})}):r?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:t("admin.stripe.title")}),e.jsx("p",{className:"text-muted-foreground mt-1",children:t("admin.stripe.description")})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(ge,{config:r,onModeSwitch:a,isLoading:c}),e.jsx(Ne,{config:r,onSaveKeys:l,isLoading:c})]}),e.jsx(ve,{mode:r.mode}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(Ce,{stats:u,mode:r.mode,isLoading:d,onRefresh:m}),e.jsx(be,{mode:r.mode})]}),e.jsx(Se,{config:r,onUpdateDefaultCurrency:i,isLoading:c})]}):e.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:e.jsx("p",{className:"text-muted-foreground",children:"No configuration available"})})};export{Ee 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.