PageSourceSearch

https://dataskeptic.com/assets/StripeCartTest-IgyAOo-q.js

js dataskeptic.com collected 2026-09-24 08:49:08 UTC 5,874 bytes, 1 lines download raw bytes

1import{a as P,u as D,r as u,j as e,H as m,g as d,S as y,B as g}from"./index-Ba9Uy_0B.js";import{D as C,T as s}from"./Parameter-CIU04DnV.js";import"./index-B_UEhZpz.js";function R(){const{fetchSecureApi:h}=P(),{username:a}=D(),[x,c]=u.useState(!1),[o,T]=u.useState([]),[f,k]=u.useState([]),[i,l]=u.useState(null),[S,n]=u.useState(null),b=async()=>{var t;c(!0),n(null),l(null);try{const r=await h("/stripe/products/one-time-only",{method:"GET"});T(r.products||[]),l({test:"Fetch Products",success:!0,message:"Found ".concat(((t=r.products)==null?void 0:t.length)||0," products"),data:r.products})}catch(r){n(r.message||"Failed to fetch products")}finally{c(!1)}},F=async()=>{var t;if(o.length===0){n("Please fetch products first");return}c(!0),n(null),l(null);try{const r=o[0],j=(t=r.prices)==null?void 0:t[0];if(!j)throw new Error("No price found for test product");const p=[{productId:r.id,priceId:j.id,quantity:1}],v={name:"Test User",address1:"123 Test St",address2:"",city:"Los Angeles",state:"CA",postalCode:"90001",country:"US"},w=await h("/stripe/cart/checkout",{method:"POST",body:{cartItems:p,shippingAddress:v,billingAddress:v}});l({test:"Create Checkout Session",success:!0,message:"Checkout session created successfully",data:w,note:"In production, you would redirect to: "+w.url})}catch(r){n(r.message||"Failed to create checkout session")}finally{c(!1)}},H=async()=>{var t;c(!0),n(null),l(null);try{const r=await h("/stripe/cart/orders",{method:"GET"});k(r.orders||[]),l({test:"Fetch Orders",success:!0,message:"Found ".concat(((t=r.orders)==null?void 0:t.length)||0," orders"),data:r.orders})}catch(r){n(r.message||"Failed to fetch orders")}finally{c(!1)}},A=async()=>{c(!0),n(null),l(null);try{const t=Date.now();await h("/stripe/products/one-time-only",{method:"GET"});const r=Date.now()-t,j=Date.now();await h("/stripe/products/one-time-only",{method:"GET"});const p=Date.now()-j;l({test:"Cache Performance",success:!0,message:"Cache is working",data:{firstFetch:"".concat(r,"ms"),secondFetch:"".concat(p,"ms (cached)"),speedup:"".concat(Math.round(r/p*10)/10,"x faster")}})}catch(t){n(t.message||"Cache test failed")}finally{c(!1)}};return e.jsxs("div",{style:{padding:"2rem",maxWidth:"1200px",margin:"0 auto"},children:[e.jsx(m,{as:"h1",children:"Stripe Cart Backend Tests"}),e.jsxs(d,{info:!0,children:[e.jsx(d.Header,{children:"Testing Backend Endpoints"}),e.jsx("p",{children:"This page tests the three backend endpoints we just created:"}),e.jsxs("ul",{children:[e.jsxs("li",{children:[e.jsx("code",{children:"GET /stripe/products/one-time-only"})," - with caching"]}),e.jsxs("li",{children:[e.jsx("code",{children:"POST /stripe/cart/checkout"})," - create checkout session"]}),e.jsxs("li",{children:[e.jsx("code",{children:"GET /stripe/cart/orders"})," - retrieve order history"]})]}),a?e.jsxs("p",{children:[e.jsx("strong",{children:"Logged in as:"})," ",a]}):e.jsx(d,{negative:!0,children:"You must be logged in to test these endpoints"}),e.jsx(C,{}),e.jsx("p",{children:e.jsx("strong",{children:"Prerequisites to test:"})}),e.jsxs("ol",{children:[e.jsxs("li",{children:["Admin must configure Stripe credential in: ",e.jsx("strong",{children:"Admin → Site Configuration → Stripe Integration"})]}),e.jsx("li",{children:"Create products in Stripe Dashboard"}),e.jsxs("li",{children:['Admin marks products as "Available" in: ',e.jsx("strong",{children:"Admin → One-Time Products"})]})]})]}),e.jsx(C,{}),e.jsxs(y,{children:[e.jsx(m,{as:"h3",children:"Test Controls"}),e.jsx(g,{primary:!0,loading:x,onClick:b,disabled:!a,children:"1. Fetch Products (Test Cache)"}),e.jsx(g,{color:"blue",loading:x,onClick:F,disabled:!a||o.length===0,children:"2. Create Checkout Session"}),e.jsx(g,{color:"green",loading:x,onClick:H,disabled:!a,children:"3. Fetch Orders"}),e.jsx(g,{color:"orange",loading:x,onClick:A,disabled:!a,children:"4. Test Cache Performance"})]}),S&&e.jsxs(d,{negative:!0,children:[e.jsx(d.Header,{children:"Error"}),e.jsx("p",{children:S})]}),i&&e.jsxs(d,{positive:!0,children:[e.jsxs(d.Header,{children:[i.test," - ",i.success?"✓ Success":"✗ Failed"]}),e.jsx("p",{children:i.message}),i.note&&e.jsx("p",{children:e.jsx("em",{children:i.note})}),i.data&&e.jsxs("div",{style:{marginTop:"1rem"},children:[e.jsx("strong",{children:"Result Data:"}),e.jsx("pre",{style:{background:"#f4f4f4",padding:"1rem",borderRadius:"4px",overflow:"auto",maxHeight:"300px"},children:JSON.stringify(i.data,null,2)})]})]}),o.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(C,{}),e.jsxs(y,{children:[e.jsxs(m,{as:"h3",children:["Available Products (",o.length,")"]}),e.jsxs(s,{celled:!0,children:[e.jsx(s.Header,{children:e.jsxs(s.Row,{children:[e.jsx(s.HeaderCell,{children:"Product ID"}),e.jsx(s.HeaderCell,{children:"Name"}),e.jsx(s.HeaderCell,{children:"Available"}),e.jsx(s.HeaderCell,{children:"Prices"})]})}),e.jsx(s.Body,{children:o.map(t=>{var r;return e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:t.id}),e.jsx(s.Cell,{children:t.name}),e.jsx(s.Cell,{children:t.available?"✓ Yes":"✗ No"}),e.jsxs(s.Cell,{children:[((r=t.prices)==null?void 0:r.length)||0," price(s)"]})]},t.id)})})]})]})]}),f.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(C,{}),e.jsxs(y,{children:[e.jsxs(m,{as:"h3",children:["Order History (",f.length,")"]}),e.jsxs(s,{celled:!0,children:[e.jsx(s.Header,{children:e.jsxs(s.Row,{children:[e.jsx(s.HeaderCell,{children:"Order ID"}),e.jsx(s.HeaderCell,{children:"Date"}),e.jsx(s.HeaderCell,{children:"Amount"}),e.jsx(s.HeaderCell,{children:"Status"})]})}),e.jsx(s.Body,{children:f.map(t=>{var r;return e.jsxs(s.Row,{children:[e.jsx(s.Cell,{children:t.id}),e.jsx(s.Cell,{children:new Date(t.created*1e3).toLocaleDateString()}),e.jsxs(s.Cell,{children:["$",((t.amount_total||0)/100).toFixed(2)," ",(r=t.currency)==null?void 0:r.toUpperCase()]}),e.jsx(s.Cell,{children:t.payment_status})]},t.id)})})]})]})]})]})}export{R 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.