1import{b as P,a as A,r as o,t as d,j as e,B as y,A as B,C as f,e as g,f as j,d as b,k as v,s as n}from"./index-C-GMF1w8.js";import{r as N}from"./paymentRedirect-Hyf9-okN.js";import{R as F,a as _}from"./radio-group-BMHLG4Pj.js";import{M as E,P as L}from"./PaymentBrands-w7k3KgPE.js";import"./paypal-C1JI37v9.js";function R(){const i=P(),{user:c}=A(),[l,w]=o.useState("mollie"),[m,u]=o.useState(!1),[a,k]=o.useState(null);o.useEffect(()=>{if(!c){d.error("Log in om door te gaan"),i("/auth");return}const r=localStorage.getItem("pendingCreditPurchase");if(!r){d.error("Geen pakket geselecteerd"),i("/profile?tab=credits");return}k(JSON.parse(r))},[c,i]);const C=async()=>{if(!(!c||!a)){u(!0);try{const{data:r,error:p}=await n.from("credit_purchases").insert({user_id:c.id,package_id:a.packageId,payment_amount:a.paymentAmount,credit_value:a.creditValue,currency:a.currency,payment_provider:l,payment_status:"pending"}).select().single();if(p)throw p;const x=`${window.location.origin}/payment/success?type=credits&purchase_id=${r.id}`,h=`${window.location.origin}/payment/cancel?type=credits`;if(l==="mollie"){const{data:t,error:s}=await n.functions.invoke("create-mollie-payment",{body:{amount:a.paymentAmount,currency:a.currency,description:`Credits: ${a.packageName}`,return_url:x,cancel_url:h,metadata:{purchase_id:r.id,type:"credit_purchase"}}});if(s)throw s;await n.from("credit_purchases").update({payment_id:t.payment_id}).eq("id",r.id),N(t.checkout_url)}else{const{data:t,error:s}=await n.functions.invoke("create-paypal-payment",{body:{amount:a.paymentAmount,currency:a.currency,items:[{name:`Credits: ${a.packageName}`,quantity:1,unit_amount:{currency_code:a.currency,value:a.paymentAmount.toFixed(2)}}],return_url:x,cancel_url:h}});if(s)throw s;await n.from("credit_purchases").update({payment_id:t.order_id}).eq("id",r.id),N(t.approval_url)}}catch(r){console.error("Payment error:",r),d.error("Fout bij verwerken van betaling"),u(!1)}}};return a?e.jsxs("main",{className:"container mx-auto px-4 py-8",children:[e.jsxs(y,{variant:"ghost",onClick:()=>i("/profile?tab=credits"),className:"mb-6",children:[e.jsx(B,{className:"h-4 w-4 mr-2"}),"Terug"]}),e.jsxs("div",{className:"max-w-2xl mx-auto space-y-6",children:[e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(j,{children:"Bestelling Overzicht"})}),e.jsxs(b,{className:"space-y-4",children:[e.jsxs("div",{className:"flex justify-between items-center pb-4 border-b",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:a.packageName}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["â¬",a.creditValue.toFixed(2)," credit waarde"]})]}),e.jsxs("p",{className:"text-2xl font-bold",children:["â¬",a.paymentAmount.toFixed(2)]})]}),e.jsx("div",{className:"bg-green-50 dark:bg-green-950 p-4 rounded-lg",children:e.jsxs("p",{className:"text-green-800 dark:text-green-200 font-medium",children:["Je bespaart â¬",(a.creditValue-a.paymentAmount).toFixed(2),"!"]})})]})]}),e.jsxs(f,{children:[e.jsx(g,{children:e.jsx(j,{children:"Betaalmethode"})}),e.jsx(b,{children:e.jsxs(F,{value:l,onValueChange:r=>w(r),children:[e.jsxs("div",{className:"flex items-start space-x-2 p-4 border rounded-lg cursor-pointer hover:bg-accent",children:[e.jsx(_,{value:"mollie",id:"mollie",className:"mt-1"}),e.jsxs(v,{htmlFor:"mollie",className:"cursor-pointer flex-1",children:[e.jsx("div",{className:"font-semibold",children:"Betaal met het beveiligd betaal platform MOLLIE"}),e.jsx("div",{className:"text-sm text-muted-foreground mb-2",children:"iDEAL, Creditcard, Bancontact, etc."}),e.jsx(E,{})]})]}),e.jsxs("div",{className:"flex items-start space-x-2 p-4 border rounded-lg cursor-pointer hover:bg-accent",children:[e.jsx(_,{value:"paypal",id:"paypal",className:"mt-1"}),e.jsxs(v,{htmlFor:"paypal",className:"cursor-pointer flex-1",children:[e.jsx("div",{className:"font-semibold",children:"Betaal met PayPal"}),e.jsx(L,{className:"mt-2"})]})]})]})})]}),e.jsx(y,{className:"w-full",size:"lg",onClick:C,disabled:m,children:m?"Verwerken...":`Betaal â¬${a.paymentAmount.toFixed(2)}`})]})]}):null}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.