(()=>{var e={};e.id=526,e.ids=[526],e.modules={10846:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},44870:e=>{"use strict";e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},3295:e=>{"use strict";e.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},29294:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-async-storage.external.js")},63033:e=>{"use strict";e.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},12412:e=>{"use strict";e.exports=require("assert")},79646:e=>{"use strict";e.exports=require("child_process")},55511:e=>{"use strict";e.exports=require("crypto")},94735:e=>{"use strict";e.exports=require("events")},29021:e=>{"use strict";e.exports=require("fs")},81630:e=>{"use strict";e.exports=require("http")},55591:e=>{"use strict";e.exports=require("https")},33873:e=>{"use strict";e.exports=require("path")},27910:e=>{"use strict";e.exports=require("stream")},83997:e=>{"use strict";e.exports=require("tty")},79551:e=>{"use strict";e.exports=require("url")},28354:e=>{"use strict";e.exports=require("util")},74075:e=>{"use strict";e.exports=require("zlib")},45247:()=>{},43729:(e,t,r)=>{"use strict";r.r(t),r.d(t,{patchFetch:()=>v,routeModule:()=>x,serverHooks:()=>h,workAsyncStorage:()=>_,workUnitAsyncStorage:()=>w});var a={};r.r(a),r.d(a,{POST:()=>g});var s=r(42706),n=r(28203),i=r(45994),o=r(39187),u=r(37915),c=r(93292);async function l(e,t,r){try{let a=await c.A.get(`${r}/user-wallets/user/${e}`,{headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`}});if(a.data&&Array.isArray(a.data)&&a.data.length>0){let e=a.data[0];return{walletBalance:parseFloat(e.balance||"0"),walletData:e}}return{walletBalance:0,walletData:null}}catch(e){return console.error("Error fetching wallet balance:",e.message),{walletBalance:0,walletData:null}}}async function p(e,t){if(t<=0)return null;try{let r=`wallet_discount_${Math.round(100*t)}_${Date.now()}`;return await e.coupons.create({id:r,amount_off:Math.round(100*t),currency:"eur",duration:"once",name:"Remise - Beta Test"})}catch(e){return console.error("Error creating wallet discount coupon:",e.message),null}}async function d(e,t,r,a,s,n){let i={payment_method_types:["card"],line_items:t,mode:"payment",success_url:`${a}/campaigns/createSepCampaigns?payment_success=true&session_id={CHECKOUT_SESSION_ID}`,cancel_url:`${a}/campaigns/createSepCampaigns?payment_cancelled=true`,metadata:r,locale:"fr"};if(void 0!==n&&n>0){let t=await p(e,n);t&&(i.discounts=[{coupon:t.id}])}return s&&(i.customer_email=s),await e.checkout.sessions.create(i)}let m=new u.A(process.env.STRIPE_SECRET_KEY||"",{apiVersion:"2025-10-29.clover"});async function g(e){try{var t;let{stripe_customer_id:r,amount:a,metadata:s,successUrl:n,cancelUrl:i,selectedEvents:u,customerEmail:c,token:p}=await e.json();console.log("customer email : ",c);let g=a&&!(a<0)?{valid:!0}:{valid:!1,error:"Invalid amount"};if(!g.valid)return o.NextResponse.json({error:g.error},{status:400});let x=0,_=null;if(s?.user_id&&p){let e=await l(s.user_id,p,"https://backendv2testing.eventx.fr");x=e.walletBalance,_=e.walletData}let{totalAmount:w,discountAmount:h,finalAmount:v}=function(e,t){let r=e.reduce((e,t)=>e+t.price,0),a=Math.min(t,r),s=Math.max(0,r-a);return{totalAmount:r,discountAmount:a,finalAmount:s}}(u,x),y=u.map(e=>{let t=function(e,t){let r=new Date(e);return Math.floor((new Date(t).getTime()-r.getTime())/864e5)}(e.startDate,e.endDate);return{price_data:{currency:"eur",product_data:{name:`${e.advert_type.toUpperCase()} Grand Pub \xe0 ${e.location}`,description:`${e.title} - ${t} jours`,images:e.eventImageUrl?[e.eventImageUrl]:void 0},unit_amount:Math.round(100*e.price)},quantity:1}}),f=(t=x,{user_id:s?.user_id||"",event_count:s?.event_count||"",wallet_balance:t.toString(),discount_applied:h.toString(),original_amount:w.toString(),final_amount:v.toString()}),q=e.headers.get("origin")||"",S=await d(m,y,f,q,c,h);return o.NextResponse.json({sessionId:S.id,url:S.url,walletBalance:x,discountApplied:h,originalAmount:w,finalAmount:v,walletData:_})}catch(e){return console.error("Error creating checkout session:",e),o.NextResponse.json({error:e.message||"Failed to create checkout session"},{status:500})}}let x=new s.AppRouteRouteModule({definition:{kind:n.RouteKind.APP_ROUTE,page:"/api/payment/create-intent/route",pathname:"/api/payment/create-intent",filename:"route",bundlePath:"app/api/payment/create-intent/route"},resolvedPagePath:"/Users/user/Desktop/nestjs/self sever portal/src/app/api/payment/create-intent/route.ts",nextConfigOutput:"",userland:a}),{workAsyncStorage:_,workUnitAsyncStorage:w,serverHooks:h}=x;function v(){return(0,i.patchFetch)({workAsyncStorage:_,workUnitAsyncStorage:w})}},96487:()=>{},78335:()=>{}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[638,312,915,292],()=>r(43729));module.exports=a})();