PageSourceSearch

https://office-supply-connect.lovable.app/assets/OrderConfirmationPage-BOqfCzYE.js

js office-supply-connect.lovable.app collected 2026-10-03 03:34:39 UTC 19,241 bytes, 1 lines download raw bytes

1import{aa as te,t as re,aU as ie,n as ne,u as le,q as oe,r as j,aV as ce,aW as de,ay as me,am as xe,au as pe,s as C,j as e,A as u,aR as k,a1 as I,B as l,L as o,m as c,ak as X,o as A,C as f,b as g,d as b,e as N,aX as G,S as B,V as E,Y as ue,k as he,F as K,R as W,aN as je}from"./index-CSZt44S3.js";import{C as fe}from"./circle-x-CAuolWS_.js";import{C as ge}from"./credit-card-BFCtNSoE.js";const d=r=>new Intl.NumberFormat("it-IT",{style:"currency",currency:"EUR"}).format(r),be=r=>{switch(r){case"bank_transfer":return"🏦";case"credit_card":case"stripe":return"💳";case"invoice":return"📄";case"paypal":return"🅿️";default:return"💰"}},Ne=r=>{switch(r){case"bank_transfer":return"Bonifico Bancario Anticipato";case"credit_card":case"stripe":return"Carta di Credito";case"invoice":return"Fattura a 30gg";case"paypal":return"PayPal";default:return r||"N/A"}};function Se(){var M;const{orderId:r}=te(),Y=re(),J=ie(),{user:R}=ne(),{clearCart:O}=le(),{calculateEarnablePoints:Z,currentTier:_}=oe(),[s,P]=j.useState(null),[Q,x]=j.useState(!0),[L,y]=j.useState(null),a=J.state,m=a==null?void 0:a.bankTransfer,T=a==null?void 0:a.orderNumber,F=a!=null&&a.order_items?{id:r||"",order_number:a.order_number||T||"",status:a.status||"pending",created_at:a.created_at||new Date().toISOString(),billing_company_name:a.billing_company_name||"",billing_vat_number:a.billing_vat_number||null,billing_address:a.billing_address||"",billing_city:a.billing_city||"",billing_postal_code:a.billing_postal_code||"",billing_province:a.billing_province||null,shipping_address:a.shipping_address||"",shipping_city:a.shipping_city||"",shipping_postal_code:a.shipping_postal_code||"",shipping_province:a.shipping_province||null,shipping_notes:a.shipping_notes||null,payment_method_type:a.payment_method_type||null,payment_method_label:a.payment_method_label||null,subtotal:a.subtotal||0,shipping_cost:a.shipping_cost||0,cod_surcharge:a.cod_surcharge||0,total:a.total||0,discount_code:a.discount_code||null,discount_amount:a.discount_amount||null,promo_gift_sku:a.promo_gift_sku||null,promo_gift_discount:a.promo_gift_discount||null,order_items:a.order_items||[]}:null,z=new URLSearchParams(window.location.search),$=z.get("order_id"),q=z.get("session_id"),H=!!$||!!q,D=z.get("payment")==="success";j.useEffect(()=>{H?ee($||void 0,q||void 0):F?(P(F),O(),x(!1)):m?x(!1):r&&r!=="success"?U():D&&r?(O(),U()):x(!1)},[r]),j.useEffect(()=>{if(!s)return;const t=s.order_items.map(i=>({content_id:i.id,content_type:"product",content_name:i.product_name,price:i.unit_price,num_items:i.quantity}));ce(t,s.total);const n=s.order_items.map(i=>i.product_sku||i.id);de(n)},[s]);const ee=async(t,n)=>{var v;for(let p=1;p<=10;p++)try{const w={"Content-Type":"application/json",apikey:me},S=(v=(await xe.auth.getSession()).data.session)==null?void 0:v.access_token;S&&(w.Authorization=`Bearer ${S}`);const h=await(await fetch(`${pe}/ecommerce-verify-payment`,{method:"POST",headers:w,body:JSON.stringify({order_id:t,session_id:n})})).json();if(h.payment_status==="paid"){y("paid"),O(),(h.order_id||t)&&await se(h.order_id||t),x(!1);return}if(p===10){h.payment_status==="pending"?y("pending"):y("failed"),x(!1);return}console.log(`[payment-verify] Attempt ${p}/10: status=${h.payment_status}, retrying in 2500ms...`),await new Promise(ae=>setTimeout(ae,2500))}catch(w){if(console.error(`[payment-verify] Attempt ${p}/10 error:`,w),p===10){y("failed"),x(!1);return}await new Promise(S=>setTimeout(S,2500))}},se=async t=>{const n=t||r;if(n)try{const{data:i,error:V}=await C.from("orders").select("*").eq("id",n).maybeSingle();if(V||!i)throw new Error("Order not found");const{data:v}=await C.from("order_items").select("*").eq("order_id",n);P({...i,order_items:v||[]})}catch(i){console.error("Error fetching order:",i)}},U=async()=>{if(r)try{const{data:t,error:n}=await C.from("orders").select("*").eq("id",r).maybeSingle();if(n||!t)throw new Error("Order not found");const{data:i}=await C.from("order_items").select("*").eq("order_id",r);P({...t,order_items:i||[]})}catch(t){console.error("Error fetching order:",t),R&&Y("/orders")}finally{x(!1)}};return Q?e.jsx(u,{children:e.jsx("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:H?e.jsxs("div",{className:"text-center py-16",children:[e.jsx("div",{className:"inline-flex items-center justify-center w-16 h-16 rounded-full bg-primary/10 mb-4",children:e.jsx(k,{className:"w-8 h-8 text-primary animate-pulse"})}),e.jsx("h2",{className:"text-xl font-semibold mb-2",children:"Verifica pagamento in corso..."}),e.jsx("p",{className:"text-muted-foreground",children:"Stiamo confermando il tuo pagamento con Stripe. Attendi qualche secondo."})]}):e.jsxs(e.Fragment,{children:[e.jsx(I,{className:"h-32 w-full mb-8"}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6",children:[e.jsx(I,{className:"h-48"}),e.jsx(I,{className:"h-48"})]}),e.jsx(I,{className:"h-64 mt-6"})]})})}):L==="pending"?e.jsx(u,{children:e.jsxs("div",{className:"container mx-auto px-4 py-16 max-w-lg text-center",children:[e.jsx(k,{className:"h-16 w-16 mx-auto mb-4 text-yellow-500"}),e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Pagamento in elaborazione"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Il tuo pagamento è in fase di elaborazione. Riceverai una conferma via email."}),e.jsx(l,{asChild:!0,children:e.jsx(o,{to:"/orders",children:"Vai ai miei ordini"})})]})}):L==="failed"?e.jsx(u,{children:e.jsxs("div",{className:"container mx-auto px-4 py-16 max-w-lg text-center",children:[e.jsx(fe,{className:"h-16 w-16 mx-auto mb-4 text-destructive"}),e.jsx("h1",{className:"text-2xl font-bold mb-2",children:"Pagamento non riuscito"}),e.jsx("p",{className:"text-muted-foreground mb-6",children:"Si è verificato un problema con il pagamento. Riprova o contatta l'assistenza."}),e.jsxs("div",{className:"flex gap-4 justify-center",children:[e.jsx(l,{asChild:!0,variant:"outline",children:e.jsx(o,{to:"/",children:"Torna alla Home"})}),e.jsx(l,{asChild:!0,children:e.jsx(o,{to:"/cart",children:"Torna al Carrello"})})]})]})}):m&&!s?e.jsx(u,{children:e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsxs(c.div,{initial:{opacity:0,y:-20}
1,animate:{opacity:1,y:0},className:"text-center mb-8",children:[e.jsx(c.div,{initial:{scale:0},animate:{scale:1},transition:{delay:.2,type:"spring"},className:"inline-flex items-center justify-center w-20 h-20 rounded-full bg-green-100 text-green-600 mb-4",children:e.jsx(X,{className:"w-12 h-12"})}),e.jsx("h1",{className:"text-3xl font-bold text-foreground mb-2",children:"Ordine Confermato!"}),T&&e.jsxs(A,{variant:"outline",className:"text-lg px-4 py-2 mt-2",children:["Ordine: ",e.jsx("span",{className:"font-mono font-bold ml-2",children:T})]})]}),e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(b,{className:"flex items-center gap-2",children:"🏦 Bonifico Bancario Anticipato"})}),e.jsxs(N,{className:"space-y-4",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 space-y-3",children:[e.jsx("p",{className:"font-semibold text-sm",children:"Effettua il bonifico con i seguenti dati:"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"IBAN:"})," ",e.jsx("span",{className:"font-mono font-medium",children:m.iban})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Beneficiario:"})," ",e.jsx("span",{className:"font-medium",children:m.beneficiary})]}),m.bic&&e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"BIC/SWIFT:"})," ",e.jsx("span",{className:"font-mono font-medium",children:m.bic})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Causale:"})," ",e.jsx("span",{className:"font-medium",children:m.reference})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Importo:"})," ",e.jsx("span",{className:"font-medium",children:d(m.amount)})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-300 dark:border-amber-700 space-y-2",children:[e.jsxs("p",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(k,{className:"h-4 w-4 text-amber-600"}),"Importante: Bonifico Anticipato"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["L'ordine verrà elaborato ",e.jsx("strong",{children:"esclusivamente dopo l'effettivo accredito"})," del bonifico sul nostro conto corrente. I tempi di consegna decorrono dalla data di incasso."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Per velocizzare l'evasione, ti invitiamo a inviare copia della contabile bancaria a:"," ",e.jsx("a",{href:"mailto:[email protected]",className:"text-primary font-medium hover:underline",children:"[email protected]"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["⚠️ Senza il pagamento o l'invio della contabile, l'ordine ",e.jsx("strong",{children:"non verrà processato"})," e resterà in stato di attesa."]})]})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 justify-center mt-8",children:[e.jsx(l,{asChild:!0,variant:"outline",size:"lg",children:e.jsxs(o,{to:"/",children:[e.jsx(G,{className:"w-4 h-4 mr-2"})," Torna alla Home"]})}),e.jsx(l,{asChild:!0,size:"lg",children:e.jsxs(o,{to:"/orders",children:[e.jsx(B,{className:"w-4 h-4 mr-2"})," I Miei Ordini ",e.jsx(E,{className:"w-4 h-4 ml-2"})]})})]})]})}):s?e.jsx(u,{children:e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsxs(c.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},className:"text-center mb-8",children:[e.jsx(c.div,{initial:{scale:0},animate:{scale:1},transition:{delay:.2,type:"spring",stiffness:200},className:"inline-flex items-center justify-center w-20 h-20 rounded-full bg-green-100 text-green-600 mb-4",children:e.jsx(X,{className:"w-12 h-12"})}),e.jsx("h1",{className:"text-3xl font-bold text-foreground mb-2",children:"Ordine Confermato!"}),e.jsx("p",{className:"text-muted-foreground text-lg",children:"Grazie per il tuo ordine. Riceverai una email di conferma a breve."}),e.jsx("div",{className:"mt-4 inline-block",children:e.jsxs(A,{variant:"outline",className:"text-lg px-4 py-2",children:["Ordine: ",e.jsx("span",{className:"font-mono font-bold ml-2",children:s.order_number})]})})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-6 mb-6",children:[e.jsx(c.div,{initial:{opacity:0,x:-20}
1,animate:{opacity:1,x:0},transition:{delay:.3},children:e.jsxs(f,{children:[e.jsx(g,{className:"pb-3",children:e.jsxs(b,{className:"text-base flex items-center gap-2",children:[e.jsx(ue,{className:"w-4 h-4 text-primary"})," Fatturazione"]})}),e.jsxs(N,{className:"text-sm",children:[e.jsx("p",{className:"font-semibold",children:s.billing_company_name}),s.billing_vat_number&&e.jsxs("p",{className:"text-muted-foreground",children:["P.IVA: ",s.billing_vat_number]}),e.jsx("p",{className:"mt-2",children:s.billing_address}),e.jsxs("p",{children:[s.billing_postal_code," ",s.billing_city,s.billing_province&&` (${s.billing_province})`]})]})]})}),e.jsx(c.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},transition:{delay:.4},children:e.jsxs(f,{children:[e.jsx(g,{className:"pb-3",children:e.jsxs(b,{className:"text-base flex items-center gap-2",children:[e.jsx(he,{className:"w-4 h-4 text-primary"})," Spedizione"]})}),e.jsx(N,{className:"text-sm",children:(M=s.shipping_notes)!=null&&M.includes("RITIRO IN NEGOZIO")?e.jsxs(e.Fragment,{children:[e.jsx(A,{variant:"secondary",className:"mb-2",children:"🏪 Ritiro in negozio"}),e.jsx("p",{children:s.shipping_address}),e.jsxs("p",{children:[s.shipping_postal_code," ",s.shipping_city,s.shipping_province&&` (${s.shipping_province})`]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{children:s.shipping_address}),e.jsxs("p",{children:[s.shipping_postal_code," ",s.shipping_city,s.shipping_province&&` (${s.shipping_province})`]}),s.shipping_notes&&e.jsxs("p",{className:"mt-2 text-muted-foreground italic",children:["Note: ",s.shipping_notes]})]})})]})})]}),e.jsx(c.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.5},className:"mb-6",children:e.jsxs(f,{children:[e.jsx(g,{className:"pb-3",children:e.jsxs(b,{className:"text-base flex items-center gap-2",children:[e.jsx(ge,{className:"w-4 h-4 text-primary"})," Metodo di Pagamento"]})}),e.jsxs(N,{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:be(s.payment_method_type)}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:Ne(s.payment_method_type)}),s.payment_method_label&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s.payment_method_label})]})]}),s.payment_method_type==="bank_transfer"&&e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsxs("div",{className:"p-4 rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800 space-y-3",children:[e.jsx("p",{className:"font-semibold text-sm",children:"Dati per il Bonifico Bancario Anticipato:"}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"IBAN:"})," ",e.jsx("span",{className:"font-mono font-medium",children:"IT32B0306903516100000066202"})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Banca:"})," ",e.jsx("span",{className:"font-medium",children:"INTESA SAN PAOLO"})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Intestatario:"})," ",e.jsx("span",{className:"font-medium",children:"CN SOLUTION S.R.L."})]}),e.jsxs("p",{children:[e.jsx("span",{className:"text-muted-foreground",children:"Causale:"})," ",e.jsxs("span",{className:"font-medium",children:["Pagamento ordine ",s.order_number]})]})]})]}),e.jsxs("div",{className:"p-4 rounded-lg bg-amber-50 dark:bg-amber-950/30 border border-amber-300 dark:border-amber-700 space-y-2",children:[e.jsxs("p",{className:"font-semibold text-sm flex items-center gap-2",children:[e.jsx(k,{className:"h-4 w-4 text-amber-600"}),"Importante: Bonifico Anticipato"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["L'ordine verrà elaborato ",e.jsx("strong",{children:"esclusivamente dopo l'effettivo accredito"})," del bonifico sul nostro conto corrente. I tempi di consegna decorrono dalla data di incasso."]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Per velocizzare l'evasione, invia copia della contabile bancaria a:"," ",e.jsx("a",{href:"mailto:[email protected]",className:"text-primary font-medium hover:underline",children:"[email protected]"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["⚠️ Senza il pagamento o l'invio della contabile, l'ordine ",e.jsx("strong",{children:"non verrà processato"})," e resterà in stato di attesa."]})]})]})]})]})}),e.jsx(c.div,{initial:{opacity:0,y:20}
1,animate:{opacity:1,y:0},transition:{delay:.6},children:e.jsxs(f,{children:[e.jsx(g,{children:e.jsxs(b,{className:"flex items-center gap-2",children:[e.jsx(K,{className:"w-5 h-5 text-primary"})," Prodotti Ordinati (",s.order_items.length,")"]})}),e.jsxs(N,{children:[e.jsx("div",{className:"space-y-4",children:s.order_items.map(t=>e.jsxs("div",{className:"flex items-center gap-4 py-3 border-b last:border-0",children:[e.jsx("div",{className:"w-16 h-16 bg-muted rounded-lg overflow-hidden flex-shrink-0",children:t.product_image_url?e.jsx("img",{src:t.product_image_url,alt:t.product_name,className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center",children:e.jsx(K,{className:"w-6 h-6 text-muted-foreground"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:t.product_name}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["SKU: ",t.product_sku]}),e.jsxs("p",{className:"text-sm",children:[t.quantity," x ",d(t.unit_price)]})]}),e.jsx("div",{className:"text-right",children:e.jsx("p",{className:"font-semibold",children:d(t.total_price)})})]},t.id))}),e.jsx(W,{className:"my-4"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Subtotale"}),e.jsx("span",{children:d(s.subtotal)})]}),Number(s.discount_amount||0)>0&&e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsxs("span",{children:["Sconto",s.discount_code?` (${s.discount_code})`:""]}),e.jsxs("span",{children:["-",d(Number(s.discount_amount))]})]}),Number(s.promo_gift_discount||0)>0&&e.jsxs("div",{className:"flex justify-between text-sm text-green-600",children:[e.jsxs("span",{children:["Omaggio",s.promo_gift_sku?` (${s.promo_gift_sku})`:""]}),e.jsxs("span",{children:["-",d(Number(s.promo_gift_discount))]})]}),e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Spedizione"}),e.jsx("span",{children:s.shipping_cost===0?e.jsx(A,{variant:"secondary",className:"text-xs",children:"Gratuita"}):d(s.shipping_cost)})]}),Number(s.cod_surcharge||0)>0&&e.jsxs("div",{className:"flex justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"Supplemento Contrassegno"}),e.jsx("span",{children:d(Number(s.cod_surcharge))})]}),e.jsx(W,{}),e.jsxs("div",{className:"flex justify-between text-lg font-bold pt-2",children:[e.jsx("span",{children:"Totale"}),e.jsx("span",{className:"text-primary",children:d(s.total)})]}),s.subtotal>0&&e.jsxs("div",{className:"flex items-center gap-2 p-3 rounded-lg bg-yellow-50 dark:bg-yellow-950/30 border border-yellow-200 dark:border-yellow-800 mt-3",children:[e.jsx(je,{className:"h-4 w-4 text-yellow-500 fill-yellow-500 shrink-0"}),e.jsxs("span",{className:"text-sm",children:["Hai guadagnato"," ",e.jsxs("span",{className:"font-bold text-primary",children:[Z(s.subtotal)," punti"]})," ","con questo ordine!",_&&_.points_multiplier>1&&e.jsxs("span",{className:"text-xs text-muted-foreground ml-1",children:["(x",_.points_multiplier," bonus ",_.name,")"]})]})]})]})]})]})}),e.jsxs(c.div,{initial:{opacity:0}
1,animate:{opacity:1},transition:{delay:.8},className:"flex flex-col sm:flex-row gap-4 justify-center mt-8",children:[e.jsx(l,{asChild:!0,variant:"outline",size:"lg",children:e.jsxs(o,{to:"/",children:[e.jsx(G,{className:"w-4 h-4 mr-2"})," Torna alla Home"]})}),R?e.jsx(l,{asChild:!0,size:"lg",children:e.jsxs(o,{to:"/orders",children:[e.jsx(B,{className:"w-4 h-4 mr-2"})," I Miei Ordini ",e.jsx(E,{className:"w-4 h-4 ml-2"})]})}):e.jsx(l,{asChild:!0,size:"lg",children:e.jsxs(o,{to:"/catalog",children:[e.jsx(B,{className:"w-4 h-4 mr-2"})," Continua gli acquisti ",e.jsx(E,{className:"w-4 h-4 ml-2"})]})})]})]})}):e.jsx(u,{children:e.jsxs("div",{className:"container mx-auto px-4 py-8 text-center",children:[e.jsx("p",{className:"text-muted-foreground",children:"Ordine non trovato."}),e.jsx(l,{asChild:!0,className:"mt-4",children:e.jsx(o,{to:"/",children:"Torna alla Home"})})]})})}export{Se 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.