"use strict";(()=>{var e={};e.id=6574,e.ids=[6574],e.modules={20399:e=>{e.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},30517:e=>{e.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},63759:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>m,requestAsyncStorage:()=>l,routeModule:()=>u,serverHooks:()=>y,staticGenerationAsyncStorage:()=>d});var a={};r.r(a),r.d(a,{POST:()=>c});var o=r(49303),n=r(88716),i=r(60670),s=r(87070),p=r(57684);async function c(e){try{let{amount:t,currency:r="USD",itemName:a,quantity:o=1}=await e.json();if(!t||isNaN(Number(t)))return s.NextResponse.json({error:"Invalid amount"},{status:400});let n=await (0,p.A)(),i=await (0,p.x)(n),c=Number(t).toFixed(2),u=await fetch(`${n.baseUrl}/v2/checkout/orders`,{method:"POST",headers:{Authorization:`Bearer ${i}`,"Content-Type":"application/json"},body:JSON.stringify({intent:"CAPTURE",purchase_units:[{...a?{description:String(a).slice(0,127)}:{},amount:{currency_code:r,value:c,...a?{breakdown:{item_total:{currency_code:r,value:c}}}:{}},...a?{items:[{name:String(a).slice(0,127),quantity:String(o),unit_amount:{currency_code:r,value:c},category:"PHYSICAL_GOODS"}]}:{}}]})});if(!u.ok){let e=await u.json();return s.NextResponse.json({error:e.message??"Order creation failed"},{status:500})}let l=await u.json();return s.NextResponse.json({orderId:l.id})}catch(t){let e=t instanceof Error?t.message:"Internal error";return s.NextResponse.json({error:e},{status:500})}}let u=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/paypal/create-order/route",pathname:"/api/paypal/create-order",filename:"route",bundlePath:"app/api/paypal/create-order/route"},resolvedPagePath:"/Users/abhayraj/dev/Keyur/Doliplay/src/app/api/paypal/create-order/route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:l,staticGenerationAsyncStorage:d,serverHooks:y}=u,h="/api/paypal/create-order/route";function m(){return(0,i.patchFetch)({serverHooks:y,staticGenerationAsyncStorage:d})}},57684:(e,t,r)=>{async function a(){let e=process.env.API_BASE_URL??"https://stag.divinetechs.com/dttube/public/api/",t=await fetch(`${e}get_payment_option`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","Api-Token":""},body:JSON.stringify({}),cache:"no-store"});if(!t.ok)throw Error(`Failed to fetch payment options: ${t.status}`);let r=await t.json(),a=(r?.result??{}).paypal;if(!a||"1"!==a.visibility)throw Error("PayPal gateway is not enabled");let o=a.key_1,n=a.key_2;if(!o||!n)throw Error("PayPal credentials (key_1 / key_2) are not set in the admin panel");let i="1"===a.is_live;return{clientId:o,secret:n,isLive:i,baseUrl:i?"https://api-m.paypal.com":"https://api-m.sandbox.paypal.com"}}async function o(e){let t=Buffer.from(`${e.clientId}:${e.secret}`).toString("base64"),r=await fetch(`${e.baseUrl}/v1/oauth2/token`,{method:"POST",headers:{Authorization:`Basic ${t}`,"Content-Type":"application/x-www-form-urlencoded"},body:"grant_type=client_credentials"});if(!r.ok){let e=await r.text();throw Error(`PayPal auth failed (${r.status}): ${e}`)}return(await r.json()).access_token}r.d(t,{A:()=>a,x:()=>o})}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),a=t.X(0,[8948,5972],()=>r(63759));module.exports=a})();