"use strict";(()=>{var e={};e.id=7446,e.ids=[7446],e.modules={53524:e=>{e.exports=require("@prisma/client")},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")},40411:(e,t,r)=>{r.r(t),r.d(t,{originalPathname:()=>f,patchFetch:()=>m,requestAsyncStorage:()=>c,routeModule:()=>p,serverHooks:()=>h,staticGenerationAsyncStorage:()=>d});var o={};r.r(o),r.d(o,{POST:()=>u});var n=r(73278),s=r(45002),i=r(54877),a=r(71309),l=r(82208);async function u(e){try{let t=await e.json();console.log("Relworx webhook received:",t);let{status:r,message:o,customer_reference:n,internal_reference:s,msisdn:i,amount:u,currency:p,provider:c,charge:d,completed_at:h}=t;if(!s)return console.error("Missing internal_reference in webhook"),a.NextResponse.json({error:"Missing internal_reference"},{status:400});let f=await l._.$queryRaw`
      SELECT wt.*, w.id as walletId, w.balance as currentBalance
      FROM wallet_transactions wt
      JOIN wallets w ON wt.walletId = w.id
      WHERE JSON_EXTRACT(wt.metadata, '$.relworxReference') = ${s}
      LIMIT 1
    `;if(0===f.length)return console.error("Transaction not found for internal_reference:",s),a.NextResponse.json({error:"Transaction not found"},{status:404});let m=f[0],g=m.walletId,w=m.currentBalance,y="pending",x=!1;return"success"===r?(y="completed",x=!0):"failed"===r&&(y="failed",x=!1),await l._.$executeRaw`
      UPDATE wallet_transactions
      SET status = ${y},
          metadata = JSON_SET(metadata, '$.webhookReceived', ${JSON.stringify(t)}),
          updatedAt = NOW()
      WHERE id = ${m.id}
    `,x&&"completed"===y&&(await l._.$executeRaw`
        UPDATE wallets SET balance = balance + ${u}, updatedAt = NOW() WHERE id = ${g}
      `,console.log(`Wallet ${g} credited with ${u} ${p}. New balance: ${w+u}`)),console.log(`Transaction ${m.id} updated to status: ${y}`),a.NextResponse.json({success:!0,message:"Webhook processed successfully"})}catch(e){return console.error("Error processing Relworx webhook:",e),a.NextResponse.json({error:"Internal server error"},{status:500})}}let p=new n.AppRouteRouteModule({definition:{kind:s.x.APP_ROUTE,page:"/api/webhooks/relworx/route",pathname:"/api/webhooks/relworx",filename:"route",bundlePath:"app/api/webhooks/relworx/route"},resolvedPagePath:"c:\\xampp\\htdocs\\propmaster.io\\src\\app\\api\\webhooks\\relworx\\route.ts",nextConfigOutput:"standalone",userland:o}),{requestAsyncStorage:c,staticGenerationAsyncStorage:d,serverHooks:h}=p,f="/api/webhooks/relworx/route";function m(){return(0,i.patchFetch)({serverHooks:h,staticGenerationAsyncStorage:d})}},36801:e=>{var t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,s={};function i(e){var t;let r=["path"in e&&e.path&&`Path=${e.path}`,"expires"in e&&(e.expires||0===e.expires)&&`Expires=${("number"==typeof e.expires?new Date(e.expires):e.expires).toUTCString()}`,"maxAge"in e&&"number"==typeof e.maxAge&&`Max-Age=${e.maxAge}`,"domain"in e&&e.domain&&`Domain=${e.domain}`,"secure"in e&&e.secure&&"Secure","httpOnly"in e&&e.httpOnly&&"HttpOnly","sameSite"in e&&e.sameSite&&`SameSite=${e.sameSite}`,"partitioned"in e&&e.partitioned&&"Partitioned","priority"in e&&e.priority&&`Priority=${e.priority}`].filter(Boolean),o=`${e.name}=${encodeURIComponent(null!=(t=e.value)?t:"")}`;return 0===r.length?o:`${o}; ${r.join("; ")}`}function a(e){let t=new Map;for(let r of e.split(/; */)){if(!r)continue;let e=r.indexOf("=");if(-1===e){t.set(r,"true");continue}let[o,n]=[r.slice(0,e),r.slice(e+1)];try{t.set(o,decodeURIComponent(null!=n?n:"true"))}catch{}}return t}function l(e){var t,r;if(!e)return;let[[o,n],...s]=a(e),{domain:i,expires:l,httponly:c,maxage:d,path:h,samesite:f,secure:m,partitioned:g,priority:w}=Object.fromEntries(s.map(([e,t])=>[e.toLowerCase(),t]));return function(e){let t={};for(let r in e)e[r]&&(t[r]=e[r]);return t}({name:o,value:decodeURIComponent(n),domain:i,...l&&{expires:new Date(l)},...c&&{httpOnly:!0},..."string"==typeof d&&{maxAge:Number(d)},path:h,...f&&{sameSite:u.includes(t=(t=f).toLowerCase())?t:void 0},...m&&{secure:!0},...w&&{priority:p.includes(r=(r=w).toLowerCase())?r:void 0},...g&&{partitioned:!0}})}((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(s,{RequestCookies:()=>c,ResponseCookies:()=>d,parseCookie:()=>a,parseSetCookie:()=>l,stringifyCookie:()=>i}),e.exports=((e,s,i,a)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let i of o(s))n.call(e,i)||void 0===i||t(e,i,{get:()=>s[i],enumerable:!(a=r(s,i))||a.enumerable});return e})(t({},"__esModule",{value:!0}),s);var u=["strict","lax","none"],p=["low","medium","high"],c=class{constructor(e){this._parsed=new Map,this._headers=e;let t=e.get("cookie");if(t)for(let[e,r]of a(t))this._parsed.set(e,{name:e,value:r})}[Symbol.iterator](){return this._parsed[Symbol.iterator]()}get size(){return this._parsed.size}get(...e){let t="string"==typeof e[0]?e[0]:e[0].name;return this._parsed.get(t)}getAll(...e){var t;let r=Array.from(this._parsed);if(!e.length)return r.map(([e,t])=>t);let o="string"==typeof e[0]?e[0]:null==(t=e[0])?void 0:t.name;return r.filter(([e])=>e===o).map(([e,t])=>t)}has(e){return this._parsed.has(e)}set(...e){let[t,r]=1===e.length?[e[0].name,e[0].value]:e,o=this._parsed;return o.set(t,{name:t,value:r}),this._headers.set("cookie",Array.from(o).map(([e,t])=>i(t)).join("; ")),this}delete(e){let t=this._parsed,r=Array.isArray(e)?e.map(e=>t.delete(e)):t.delete(e);return this._headers.set("cookie",Array.from(t).map(([e,t])=>i(t)).join("; ")),r}clear(){return this.delete(Array.from(this._parsed.keys())),this}[Symbol.for("edge-runtime.inspect.custom")](){return`RequestCookies ${JSON.stringify(Object.fromEntries(this._parsed))}`}toString(){return[...this._parsed.values()].map(e=>`${e.name}=${encodeURIComponent(e.value)}`).join("; ")}},d=class{constructor(e){var t,r,o;this._parsed=new Map,this._headers=e;let n=null!=(o=null!=(r=null==(t=e.getSetCookie)?void 0:t.call(e))?r:e.get("set-cookie"))?o:[];for(let e of Array.isArray(n)?n:function(e){if(!e)return[];var t,r,o,n,s,i=[],a=0;function l(){for(;a<e.length&&/\s/.test(e.charAt(a));)a+=1;return a<e.length}for(;a<e.length;){for(t=a,s=!1;l();)if(","===(r=e.charAt(a))){for(o=a,a+=1,l(),n=a;a<e.length&&"="!==(r=e.charAt(a))&&";"!==r&&","!==r;)a+=1;a<e.length&&"="===e.charAt(a)?(s=!0,a=n,i.push(e.substring(t,o)),t=a):a=o+1}else a+=1;(!s||a>=e.length)&&i.push(e.substring(t,e.length))}return i}(n)){let t=l(e);t&&this._parsed.set(t.name,t)}}get(...e){let t="string"==typeof e[0]?e[0]:e[0].name;return this._parsed.get(t)}getAll(...e){var t;let r=Array.from(this._parsed.values());if(!e.length)return r;let o="string"==typeof e[0]?e[0]:null==(t=e[0])?void 0:t.name;return r.filter(e=>e.name===o)}has(e){return this._parsed.has(e)}set(...e){let[t,r,o]=1===e.length?[e[0].name,e[0].value,e[0]]:e,n=this._parsed;return n.set(t,function(e={name:"",value:""}){return"number"==typeof e.expires&&(e.expires=new Date(e.expires)),e.maxAge&&(e.expires=new Date(Date.now()+1e3*e.maxAge)),(null===e.path||void 0===e.path)&&(e.path="/"),e}({name:t,value:r,...o})),function(e,t){for(let[,r]of(t.delete("set-cookie"),e)){let e=i(r);t.append("set-cookie",e)}}(n,this._headers),this}delete(...e){let[t,r,o]="string"==typeof e[0]?[e[0]]:[e[0].name,e[0].path,e[0].domain];return this.set({name:t,path:r,domain:o,value:"",expires:new Date(0)})}[Symbol.for("edge-runtime.inspect.custom")](){return`ResponseCookies ${JSON.stringify(Object.fromEntries(this._parsed))}`}toString(){return[...this._parsed.values()].map(i).join("; ")}}},25911:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(t,{RequestCookies:function(){return o.RequestCookies},ResponseCookies:function(){return o.ResponseCookies},stringifyCookie:function(){return o.stringifyCookie}});let o=r(36801)},82208:(e,t,r)=>{r.d(t,{_:()=>n});var o=r(53524);let n=globalThis.prisma??new o.PrismaClient({log:["error"]})}};var t=require("../../../../webpack-runtime.js");t.C(e);var r=e=>t(t.s=e),o=t.X(0,[7787,4833],()=>r(40411));module.exports=o})();