PageSourceSearch

https://standard-direct.replit.app/assets/Checkout-DSoJxgHS.js

js standard-direct.replit.app collected 2026-10-03 03:52:50 UTC 14,001 bytes, 1 lines download raw bytes

1import{aC as ee,H as se,s as ae,u as te,r as m,a as ne,w as re,I as ie,j as e,n as v,o as i,aY as de,B as d,K as A,k as O,M as j,N as f,p as x,Y as oe,J as R,_ as F,aZ as ce,F as H,X as le,a_ as me,a$ as xe}from"./index-DcZOIKL4.js";import{S as b}from"./separator-BBDHrtck.js";function pe(){const{id:n}=ee(),[,$]=se(),{toast:h}=ae(),{languageCode:M}=te(),[r,w]=m.useState(null),[o,N]=m.useState(!1),[y,Y]=m.useState(null),[I,J]=m.useState(null),_=typeof window<"u"?new URLSearchParams(window.location.search):null,q=_?.get("payment"),k=_?.get("session_id"),{data:u,isLoading:Q,refetch:D}=ne({queryKey:["/api/orders/checkout",n],queryFn:async()=>{const s=await fetch(`/api/orders/checkout/${n}`);if(!s.ok)throw new Error("Failed to load order");return s.json()},enabled:!!n});m.useEffect(()=>{q==="success"&&k&&n&&fetch(`/api/orders/${n}/stripe-status?session_id=${k}`).then(s=>s.json()).then(()=>{D(),h({title:"Payment successful",description:"Your payment has been processed."}),typeof window<"u"&&window.history.replaceState({},"",`/checkout/${n}`)}).catch(()=>{})},[q,k,n]);const a=u?.order;m.useEffect(()=>{!a||!(a.status==="paid"||a.status==="deposit_paid")||re.trackPurchaseConversion({value:parseFloat(a.grandTotal||"0")||0,currency:a.currency||"USD",transactionId:String(a.orderNumber||a.id)})},[a]),u?.quote;const U=u?.items||[],B=u?.payments||[],G=u?.subscriptions||[],K=a?.currency||"USD",W=ie(K),t=s=>`${W}${s.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}`,C=parseFloat(a?.machineTotal||"0"),P=parseFloat(a?.servicesTotal||"0"),p=parseFloat(a?.taxAmount||"0");parseFloat(a?.grandTotal||"0");const z=parseFloat(a?.amountDue||"0"),L=parseFloat(a?.amountPaid||"0"),S=a?.depositPercent||20,c=C+p,T=c*(S/100),g=a?.status==="paid"||a?.status==="deposit_paid",V=async s=>{N(!0);try{const l=await(await fetch(`/api/orders/${n}/stripe-checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentType:s})})).json();l.url?window.location.href=l.url:h({title:"Could not create checkout session",description:l.message,variant:"destructive"})}catch{h({title:"Payment error",variant:"destructive"})}N(!1)},E=async s=>{N(!0);try{const l=await(await fetch(`/api/orders/${n}/bank-transfer`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({paymentType:s,languageCode:M})})).json();Y(l.invoiceHtml),J(l.stripePaymentLink),h({title:"Invoice generated",description:"Your invoice has been created and emailed."}),D()}catch{h({title:"Error generating invoice",variant:"destructive"})}N(!1)},X=()=>{if(!y)return;const s=window.open("","_blank");s&&(s.document.write(y),s.document.close())};return Q?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(v,{className:"h-8 w-8 animate-spin text-primary"})}):a?e.jsx("div",{className:"min-h-screen bg-muted/30 py-8",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsxs(d,{variant:"ghost",size:"sm",onClick:()=>$("/quote"),"data-testid":"button-back",children:[e.jsx(A,{className:"h-4 w-4 mr-1"})," Back"]}),e.jsxs("div",{children:[e.jsxs("h1",{className:"font-heading font-black text-2xl","data-testid":"text-checkout-title",children:["Checkout — ",a.orderNumber]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Complete your purchase"})]}),e.jsx("div",{className:"ml-auto",children:e.jsx(O,{variant:g?"default":"secondary",className:`text-xs ${g?"bg-green-600":""}`,"data-testid":"badge-order-status",children:a.status==="paid"?"Paid":a.status==="deposit_paid"?"Deposit Paid":a.status==="pending_payment"?"Awaiting Payment":a.status})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs(i,{className:"rounded-sm shadow-sm",children:[e.jsx(j,{className:"pb-3 border-b bg-muted/30",children:e.jsx(f,{className:"text-sm font-heading",children:"Machines & Equipment"})}),e.jsx(x,{className:"p-4",children:e.jsxs("div",{className:"space-y-3",children:[U.map(s=>e.jsxs("div",{className:"flex justify-between items-start","data-testid":`item-${s.id}`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:s.machineName}),s.machineFamily&&e.jsx("div",{className:"text-xs text-muted-foreground",children:s.machineFamily}),(s.quantity||1)>1&&e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Qty: ",s.quantity]})]}),e.jsx("span",{className:"font-mono text-sm font-semibold",children:t(parseFloat(s.totalPrice)*(s.quantity||1))})]},s.id)),e.jsx(b,{}),e.jsxs("div",{className:"flex justify-between font-bold text-sm",children:[e.jsx("span",{children:"Machines Subtotal"}),e.jsx("span",{className:"font-mono",children:t(C)})]}),p>0&&e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[a.taxType||"Tax"," 
1(",a.taxRate,"%)"]}),e.jsx("span",{className:"font-mono",children:t(p)})]}),e.jsx(b,{}),e.jsxs("div",{className:"flex justify-between font-bold",children:[e.jsx("span",{children:"One-Time Total (Due Now)"}),e.jsx("span",{className:"font-mono text-lg",children:t(c)})]})]})})]}),P>0&&e.jsxs(i,{className:"rounded-sm shadow-sm border-amber-200 bg-amber-50/30 dark:bg-amber-950/20 dark:border-amber-800",children:[e.jsx(j,{className:"pb-3 border-b border-amber-200 bg-amber-50/50 dark:bg-amber-950/30 dark:border-amber-800",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}),e.jsx(f,{className:"text-sm font-heading text-amber-900 dark:text-amber-300",children:"Service Subscriptions (Invoiced Separately)"})]})}),e.jsxs(x,{className:"p-4",children:[e.jsx("p",{className:"text-sm text-amber-800 mb-3",children:"These services will be billed monthly once your equipment is installed and the service agreement is activated."}),e.jsx("div",{className:"space-y-2",children:G.map(s=>e.jsxs("div",{className:"flex justify-between items-center","data-testid":`sub-${s.id}`,children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-medium text-sm",children:s.description}),e.jsx(O,{variant:"secondary",className:"text-[10px] mt-0.5",children:s.status==="inactive"?"Starts on Installation":s.status})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:"font-mono text-sm font-semibold",children:[t(parseFloat(s.monthlyAmount)),"/mo"]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono",children:[t(parseFloat(s.annualAmount)),"/yr"]})]})]},s.id))})]})]}),g&&B.length>0&&e.jsxs(i,{className:"rounded-sm shadow-sm border-green-200 bg-green-50/30",children:[e.jsx(j,{className:"pb-3 border-b border-green-200 bg-green-50/50",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4 text-green-600"}),e.jsx(f,{className:"text-sm font-heading text-green-900",children:"Payment Received"})]})}),e.jsx(x,{className:"p-4",children:e.jsxs("div",{className:"space-y-2",children:[B.filter(s=>s.status==="completed").map(s=>e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsxs("span",{children:[s.paymentType==="deposit"?"Deposit":"Full Payment"," via ",s.method==="str
1ipe"?"Card":"Bank Transfer"]}),e.jsx("span",{className:"font-mono font-semibold",children:t(parseFloat(s.amount))})]},s.id)),e.jsx(b,{}),e.jsxs("div",{className:"flex justify-between font-bold text-green-700",children:[e.jsx("span",{children:"Total Paid"}),e.jsx("span",{className:"font-mono",children:t(L)})]}),a.status==="deposit_paid"&&e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsx("span",{children:"Remaining Balance"}),e.jsx("span",{className:"font-mono",children:t(c-L)})]})]})})]})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(i,{className:"rounded-sm shadow-sm bg-primary/5 border-primary/20",children:e.jsxs(x,{className:"p-4 space-y-3",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{children:"Machines & Equipment"}),e.jsx("span",{className:"font-mono",children:t(C)})]}),p>0&&e.jsxs("div",{className:"flex justify-between text-sm text-muted-foreground",children:[e.jsxs("span",{children:[a.taxType," (",a.taxRate,"%)"]}),e.jsx("span",{className:"font-mono",children:t(p)})]}),e.jsx(b,{}),e.jsxs("div",{className:"flex justify-between font-bold",children:[e.jsx("span",{children:"Due Now"}),e.jsx("span",{className:"font-mono text-lg","data-testid":"text-amount-due",children:t(z)})]}),P>0&&e.jsxs("div",{className:"text-xs text-amber-700 dark:text-amber-400 bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-sm p-2",children:["Services (",t(P),"/yr) billed monthly after installation"]})]})}),!g&&!y&&e.jsxs(i,{className:"rounded-sm shadow-sm",children:[e.jsx(j,{className:"pb-3 border-b bg-muted/30",children:e.jsx(f,{className:"text-sm font-heading",children:"Choose Payment"})}),e.jsxs(x,{className:"p-4 space-y-3",children:[e.jsxs("button",{className:`w-full text-left p-3 rounded-sm border-2 transition-all ${r==="deposit"?"border-primary bg-primary/5":"border-border hover:border-primary/40"}`,onClick:()=>w("deposit"),"data-testid":"option-deposit",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(F,{className:"h-4 w-4 text-primary"}),e.jsxs("span",{className:"font-semibold text-sm",children:["Pay ",S,"% Deposit"]})]}),e.jsx("div",{className:"font-mono text-lg font-bold text-primary",children:t(T)}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Secure your order with a deposit. Balance due before shipping."})]}),e.jsxs("button",{className:`w-full text-left p-3 rounded-sm border-2 transition-all ${r==="full"?"border-primary bg-primary/5":"border-border hover:border-primary/40"}`,onClick:()=>w("full"),"data-testid":"option-full",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(F,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-semibold text-sm",children:"Pay 100% Now"})]}),e.jsx("div",{className:"font-mono text-lg font-bold text-primary",children:t(c)}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Pay in full via credit or debit card."})]}),e.jsxs("button",{className:`w-full text-left p-3 rounded-sm border-2 transition-all ${r==="bank_transfer"?"border-primary bg-primary/5":"border-border hover:border-primary/40"}`,onClick:()=>w("bank_transfer"),"data-testid":"option-bank-transfer",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ce,{className:"h-4 w-4 text-primary"}),e.jsx("span",{className:"font-semibold text-sm",children:"Bank Transfer (ACH / Wire / SWIFT / EFT)"})]}),e.jsx("p",{className:"text-[11px] text-muted-foreground mt-1",children:"Receive an invoice with bank details and an optional card payment link."})]}),r&&e.jsxs(e.Fragment,{children:[e.jsx(b,{}),r==="bank_transfer"?e.jsxs("div",{className:"space-y-2",children:[e.jsxs(d,{className:"w-full rounded-sm font-bold h-11",onClick:()=>E("full"),disabled:o,"data-testid":"button-bank-full",children:[o?e.jsx(v,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(H,{className:"h-4 w-4 mr-2"}),"Generate Invoice — ",t(c)]}),e.jsxs(d,{variant:"outline",className:"w-full rounded-sm font-semibold h-10",onClick:()=>E("deposit"),disabled:o,"data-testid":"button-bank-deposit",children:[o?e.jsx(v,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(H,{className:"h-4 w-4 mr-2"}),"Invoice for ",S,"% Deposit — ",t(T)]})]}):e.jsxs(d,{className:"w-full rounded-sm font-bold h-11 bg-primary",onClick:()=>V(r),disabled:o,"data-testid":"button-pay-stripe",children:[o?e.jsx(v,{className:"h-4 w-4 animate-spin mr-2"}):e.jsx(F,{className:"h-4 w-4 mr-2"}),"Pay ",t(r==="deposit"?T:c)," with Card"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-muted-foreground justify-center pt-1",children:[e.jsx(le,{className:"h-3 w-3"}),e.jsx("span",{children:"Payments are processed securely via Stripe"})]})]})]}),y&&e.jsxs(i,{className:"rounded-sm shadow-sm border-green-200",children:[e.jsx(j,{className:"pb-3 border-b bg-green-50/50",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{className:"h-4 w-4 text-green-600"}),e.jsx(f,{className:"text-sm font-heading text-green-900",children:"Invoice Generated"})]})}),e.jsxs(x,{className:"p-4 space-y-3",children:[e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Your invoice has been emailed to ",e.jsx("strong",{children:a.customerEmail})," with bank transfer details."]}),e.jsxs(d,{variant:"outline",className:"w-full rounded-sm",onClick:X,"data-testid":"button-view-invoice",children:[e.jsx(me,{className:"h-4 w-4 mr-2"})," View / Print Invoice"]}),I&&e.jsxs(d,{className:"w-full rounded-sm",onClick:()=>window.open(I,"_blank"),"data-testid":"button-pay-online",children:[e.jsx(xe,{className:"h-4 w-4 mr-2"})," Pay Online Instead"]})]})]}),e.jsx("div",{className:"text-center",children:e.jsx("p",{className:"text-[10px] text-muted-foreground leading-relaxed px-2",children:"By completing this purchase, you agree to our Standard Terms of Sale. Machines & equipment are charged as a one-time payment. Service subscriptions (PM/SLA) begin after installation and are invoiced monthly."})})]})]})]})}):e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsxs(i,{className:"rounded-sm p-8 text-center max-w-md",children:[e.jsx(de,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h2",{className:"font-heading font-bold text-xl mb-2",children:"Order Not Found"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:"This order may have been removed or doesn't exist."}),e.jsxs(d,{variant:"outline",onClick:()=>$("/quote"),"data-testid":"button-back-to-quote",children:[e.jsx(A,{className:"h-4 w-4 mr-2"})," Back to Quote"]})]})})}export{pe 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.