"use strict";(()=>{var e={};e.id=4390,e.ids=[4390],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")},55622:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>h,patchFetch:()=>f,requestAsyncStorage:()=>u,routeModule:()=>l,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,returnUrl:o,cancelUrl:n}=await e.json();if(!t||isNaN(Number(t)))return s.NextResponse.json({error:"Invalid amount"},{status:400});if(!o||!n)return s.NextResponse.json({error:"returnUrl and cancelUrl are required"},{status:400});let i=await (0,p.A)(),c=await (0,p.x)(i),l=Number(t).toFixed(2),u={intent:"CAPTURE",payment_source:{paypal:{experience_context:{brand_name:"Doliplay Marketplace",landing_page:"LOGIN",user_action:"PAY_NOW",return_url:o,cancel_url:n}}},purchase_units:[{...a?{description:String(a).slice(0,127)}:{},amount:{currency_code:r,value:l},...a?{soft_descriptor:String(a).slice(0,22)}:{}}]},d=await fetch(`${i.baseUrl}/v2/checkout/orders`,{method:"POST",headers:{Authorization:`Bearer ${c}`,"Content-Type":"application/json","PayPal-Request-Id":`doliplay-${Date.now()}`},body:JSON.stringify(u)});if(!d.ok){let e=await d.json().catch(()=>({}));return s.NextResponse.json({error:e.message??"PayPal order creation failed"},{status:500})}let y=await d.json(),h=y.links?.find(e=>"payer-action"===e.rel)?.href;if(!h)return s.NextResponse.json({error:"No approval URL returned by PayPal"},{status:500});return s.NextResponse.json({paypalOrderId:y.id,approvalUrl:h})}catch(t){let e=t instanceof Error?t.message:"Internal error";return s.NextResponse.json({error:e},{status:500})}}let l=new o.AppRouteRouteModule({definition:{kind:n.x.APP_ROUTE,page:"/api/paypal/create-redirect-order/route",pathname:"/api/paypal/create-redirect-order",filename:"route",bundlePath:"app/api/paypal/create-redirect-order/route"},resolvedPagePath:"/Users/abhayraj/dev/Keyur/Doliplay/src/app/api/paypal/create-redirect-order/route.ts",nextConfigOutput:"",userland:a}),{requestAsyncStorage:u,staticGenerationAsyncStorage:d,serverHooks:y}=l,h="/api/paypal/create-redirect-order/route";function f(){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(55622));module.exports=a})();