module.exports = {

"[project]/.next-internal/server/app/api/privatewebhook/route/actions.js [app-rsc] (server actions loader, ecmascript)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
}}),
"[externals]/next/dist/compiled/next-server/app-route-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-route-turbo.runtime.dev.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-route-turbo.runtime.dev.js"));

module.exports = mod;
}}),
"[externals]/next/dist/compiled/@opentelemetry/api [external] (next/dist/compiled/@opentelemetry/api, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/@opentelemetry/api", () => require("next/dist/compiled/@opentelemetry/api"));

module.exports = mod;
}}),
"[externals]/next/dist/compiled/next-server/app-page-turbo.runtime.dev.js [external] (next/dist/compiled/next-server/app-page-turbo.runtime.dev.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js", () => require("next/dist/compiled/next-server/app-page-turbo.runtime.dev.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/work-unit-async-storage.external.js [external] (next/dist/server/app-render/work-unit-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/work-unit-async-storage.external.js", () => require("next/dist/server/app-render/work-unit-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/work-async-storage.external.js [external] (next/dist/server/app-render/work-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/work-async-storage.external.js", () => require("next/dist/server/app-render/work-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/next/dist/server/app-render/after-task-async-storage.external.js [external] (next/dist/server/app-render/after-task-async-storage.external.js, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("next/dist/server/app-render/after-task-async-storage.external.js", () => require("next/dist/server/app-render/after-task-async-storage.external.js"));

module.exports = mod;
}}),
"[externals]/mongoose [external] (mongoose, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("mongoose", () => require("mongoose"));

module.exports = mod;
}}),
"[project]/lib/connectdb.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "default": (()=>__TURBOPACK__default__export__)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
const MONGODB_URI = process.env.MONGODB_URI;
let isConnected = false;
const dbConnect = async ()=>{
    __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].set("strictQuery", true);
    if (isConnected) {
        return;
    }
    try {
        await __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].connect(MONGODB_URI, {
            dbName: "VTUAPP"
        });
        isConnected = true;
    } catch (error) {
        throw error;
    }
};
const __TURBOPACK__default__export__ = dbConnect;
}}),
"[externals]/crypto [external] (crypto, cjs)": (function(__turbopack_context__) {

var { g: global, __dirname, m: module, e: exports } = __turbopack_context__;
{
const mod = __turbopack_context__.x("crypto", () => require("crypto"));

module.exports = mod;
}}),
"[project]/models/user.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "AdminSettings": (()=>AdminSettings),
    "Referral": (()=>Referral),
    "ReferralDeposit": (()=>ReferralDeposit),
    "User": (()=>User)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/bcryptjs/index.js [app-route] (ecmascript)");
;
;
const authenticatorSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    credentialID: {
        type: Buffer,
        required: true
    },
    credentialPublicKey: {
        type: Buffer,
        required: true
    },
    counter: {
        type: Number,
        required: true
    },
    transports: {
        type: [
            String
        ]
    }
});
const referralSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    referrerId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    },
    referredId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    }
}, {
    timestamps: true
});
const referralDepositSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    referredId: {
        type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
        ref: "User"
    },
    amount: {
        type: Number
    },
    referrerCredit: {
        type: Number
    }
}, {
    timestamps: true
});
const reservedAccountDetailsSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    accountName: {
        type: String,
        default: ""
    },
    accountReferences: {
        type: String,
        default: ""
    },
    reservationReference: {
        type: String,
        default: ""
    },
    accounts: [
        {
            bankCode: {
                type: String,
                default: ""
            },
            bankName: {
                type: String,
                default: ""
            },
            accountNumber: {
                type: String,
                default: ""
            },
            accountName: {
                type: String,
                default: ""
            }
        }
    ]
});
// const webAuthCredentialSchema = new Schema<WebAuthCredential>({
//   credentialID: { type: String, required: true }, // Base64URL
//   credentialPublicKey: { type: String, required: true }, // Base64URL
//   transports: { type: [String], default: [] },
//   counter: { type: Number, required: true },
// });
const userSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    username: {
        type: String,
        unique: true
    },
    firstName: {
        type: String
    },
    middleName: {
        type: String
    },
    lastName: {
        type: String
    },
    name: {
        type: String
    },
    email: {
        type: String,
        unique: true
    },
    role: {
        type: String,
        enum: [
            "admin",
            "user"
        ]
    },
    userType: {
        type: String,
        enum: [
            "Smart Earner",
            "TopUser",
            "API User",
            "Affiliate User"
        ],
        default: "Smart Earner"
    },
    mobileNumber: {
        type: String
    },
    accountBalance: {
        type: Number,
        default: 0
    },
    reservedAccountDetails: [
        reservedAccountDetailsSchema
    ],
    bvn: {
        type: String
    },
    nin: {
        type: String
    },
    image: {
        type: String,
        default: ""
    },
    dateOfBirth: {
        type: Date
    },
    transactionPin: {
        type: String
    },
    referralCode: {
        type: String,
        unique: true
    },
    referredBy: [
        {
            type: __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].Schema.Types.ObjectId,
            ref: "User",
            default: []
        }
    ],
    refererBonus: {
        type: Number,
        default: 0
    },
    thumbprintStatus: {
        type: Boolean,
        default: false
    },
    transactionStatus: {
        type: Boolean,
        default: false
    },
    lastLogin: {
        type: Date,
        default: null
    },
    dateJoined: {
        type: Date,
        default: Date.now
    },
    webhookUrl: {
        type: String
    },
    currentChallenge: {
        type: String
    },
    authenticators: [
        authenticatorSchema
    ],
    hasSeenModal: {
        type: Boolean,
        default: false
    },
    hasTransactionPin: {
        type: Boolean,
        default: false
    },
    transactionPinResetCode: {
        type: Number
    },
    transactionPinResetExpires: {
        type: Date
    },
    failedResetAttempts: {
        type: Number,
        default: 0
    }
}, {
    timestamps: true,
    toJSON: {
        virtuals: true
    },
    toObject: {
        virtuals: true
    }
});
const adminSettingsSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    firstDepositPercentage: {
        type: Number,
        default: 1.5
    },
    subsequentDepositPercentage: {
        type: Number,
        default: 0.5
    },
    depositFeePercentage: {
        type: Number,
        default: 1.5
    }
});
userSchema.pre("save", async function(next) {
    if (this.isModified("transactionPin")) {
        const salt = await __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].genSalt(10);
        this.transactionPin = await __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$bcryptjs$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].hash(this.transactionPin, salt);
    }
    next();
});
userSchema.virtual("referrals", {
    ref: "Referral",
    localField: "_id",
    foreignField: "referrerId"
});
const User = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.User || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("User", userSchema);
const Referral = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Referral || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("Referral", referralSchema);
const ReferralDeposit = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.ReferralDeposit || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("ReferralDeposit", referralDepositSchema);
const AdminSettings = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.AdminSettings || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("AdminSettings", adminSettingsSchema);
}}),
"[project]/models/transactions.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "default": (()=>__TURBOPACK__default__export__)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
;
const transactionSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    type: {
        type: String,
        required: true,
        enum: [
            "CableSubscription",
            "BillPayment",
            "ManualFunding",
            "AutomaticFunding",
            "DataTransaction",
            "AirtimeTransaction",
            "WithdrawalTransaction",
            "ReferalBonus",
            "RefundTransaction"
        ]
    },
    amount: {
        type: Number
    },
    balanceBefore: {
        type: Number
    },
    balanceAfter: {
        type: Number
    },
    adminEmail: {
        type: String
    },
    status: {
        type: String,
        required: true,
        enum: [
            "Pending",
            "Successful",
            "Failed"
        ]
    },
    referenceId: {
        type: String,
        unique: true
    },
    // Airtime Subscription Field
    airtimeType: {
        type: String
    },
    buyingPrice: {
        type: Number
    },
    // Cable Subscription Fields
    iucOrSmartcardNumber: {
        type: Number
    },
    request_id: {
        type: String
    },
    provider: {
        type: String
    },
    cablePlan: {
        type: String
    },
    action: {
        type: String
    },
    userId: {
        type: String
    },
    userEmail: {
        type: String
    },
    refund: {
        type: Boolean,
        default: false
    },
    bypass: {
        type: Boolean,
        default: false
    },
    // Bill Payment Fields
    meterNumber: {
        type: Number
    },
    token: {
        type: String
    },
    customerPhone: {
        type: Number
    },
    meterType: {
        type: String
    },
    customerName: {
        type: String
    },
    customerAddress: {
        type: String
    },
    discoName: {
        type: String
    },
    // Data Transaction Fields
    planType: {
        type: String
    },
    mobileNumber: {
        type: Number
    },
    medium: {
        type: String
    },
    network: {
        type: String
    },
    plansize: {
        type: String
    },
    // Funding Transaction Fields
    fundingType: {
        type: String,
        enum: [
            "Manual",
            "Automatic"
        ]
    },
    fundingSource: {
        type: String,
        enum: [
            "API",
            "Admin",
            "Referral",
            "ONE TIME PAYMENT"
        ]
    }
}, {
    timestamps: true
});
// Create the model if it doesn't already exist
const Transaction = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Transaction || (0, __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["model"])("Transaction", transactionSchema);
const __TURBOPACK__default__export__ = Transaction;
}}),
"[project]/utils/junkfunctions.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "extractPlanDetails": (()=>extractPlanDetails),
    "generateReferenceId": (()=>generateReferenceId),
    "generateReferralCode": (()=>generateReferralCode),
    "generateRequestId": (()=>generateRequestId)
});
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$date$2d$fns$2f$format$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$locals$3e$__ = __turbopack_context__.i("[project]/node_modules/date-fns/format.js [app-route] (ecmascript) <locals>");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$uuid$2f$dist$2f$esm$2d$node$2f$v4$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__v4$3e$__ = __turbopack_context__.i("[project]/node_modules/uuid/dist/esm-node/v4.js [app-route] (ecmascript) <export default as v4>");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$date$2d$fns$2d$tz$2f$dist$2f$esm$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$module__evaluation$3e$__ = __turbopack_context__.i("[project]/node_modules/date-fns-tz/dist/esm/index.js [app-route] (ecmascript) <module evaluation>");
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$date$2d$fns$2d$tz$2f$dist$2f$esm$2f$toZonedTime$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/date-fns-tz/dist/esm/toZonedTime/index.js [app-route] (ecmascript)");
;
;
;
async function extractPlanDetails(planString) {
    console.log("Extracting plan details from:", planString);
    const match = planString.match(/(\d+(?:GB|MB))\s+N(\d+)/);
    if (match) {
        console.log("Match found:", match);
        // Extracting the plan size and amount from the matched groups
        console.log("Plan size:", match[1], "Amount:", match[2]);
        // Return the extracted details as an object
        // Convert the amount to a number
        console.log("Parsed amount:", parseFloat(match[2]));
        // Return the plan size and amount
        console.log("Returning plan details:", {
            plansize: match[1],
            amount: parseFloat(match[2])
        });
        return {
            plansize: match[1],
            amount: parseFloat(match[2])
        };
    }
    return {
        plansize: null,
        amount: 0
    };
}
async function generateReferenceId() {
    return "TXN-" + Math.random().toString(36).slice(2, 12).toUpperCase();
}
async function generateRequestId() {
    const timeZone = "Africa/Lagos";
    const now = (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$date$2d$fns$2d$tz$2f$dist$2f$esm$2f$toZonedTime$2f$index$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["toZonedTime"])(new Date(), timeZone);
    const timestamp = (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$date$2d$fns$2f$format$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$locals$3e$__["format"])(now, "yyyyMMddHHmm");
    const uniqueId = (0, __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$uuid$2f$dist$2f$esm$2d$node$2f$v4$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__$3c$export__default__as__v4$3e$__["v4"])().replace(/-/g, "").slice(0, 8);
    return `${timestamp}${uniqueId}`;
}
async function generateReferralCode() {
    const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    let code = "";
    for(let i = 0; i < 8; i++){
        code += chars.charAt(Math.floor(Math.random() * chars.length));
    }
    return code;
}
}}),
"[project]/models/notification.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "deleteNotification": (()=>deleteNotification),
    "getAllNotifications": (()=>getAllNotifications),
    "getAllUsers": (()=>getAllUsers),
    "getNotification": (()=>getNotification),
    "getUserNotifications": (()=>getUserNotifications),
    "saveNotification": (()=>saveNotification),
    "updateNotification": (()=>updateNotification)
});
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/lib/connectdb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/user.ts [app-route] (ecmascript)");
;
;
;
const NotificationSchema = new __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["Schema"]({
    message: {
        type: String,
        required: true
    },
    recipient: {
        type: String,
        required: true
    },
    createdAt: {
        type: Date,
        default: Date.now
    }
});
const Notification = __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].models.Notification || __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].model("Notification", NotificationSchema);
async function saveNotification(message, recipient) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    const notification = new Notification({
        message,
        recipient
    });
    await notification.save();
}
async function getUserNotifications(email) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.find({
        $or: [
            {
                recipient: email
            },
            {
                recipient: "all"
            }
        ]
    }).sort({
        createdAt: -1
    });
}
async function getAllNotifications() {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.find().sort({
        createdAt: -1
    });
}
async function getAllUsers() {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].find().select("email -_id");
}
async function getNotification(id) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findById(id);
}
async function updateNotification(id, message, recipient) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findByIdAndUpdate(id, {
        message,
        recipient
    }, {
        new: true
    });
}
async function deleteNotification(id) {
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    return Notification.findByIdAndDelete(id);
}
}}),
"[project]/app/api/privatewebhook/route.ts [app-route] (ecmascript)": ((__turbopack_context__) => {
"use strict";

var { g: global, __dirname } = __turbopack_context__;
{
__turbopack_context__.s({
    "POST": (()=>POST)
});
var __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/node_modules/next/server.js [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/lib/connectdb.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/mongoose [external] (mongoose, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/user.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/transactions.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$externals$5d2f$crypto__$5b$external$5d$__$28$crypto$2c$__cjs$29$__ = __turbopack_context__.i("[externals]/crypto [external] (crypto, cjs)");
var __TURBOPACK__imported__module__$5b$project$5d2f$utils$2f$junkfunctions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/utils/junkfunctions.ts [app-route] (ecmascript)");
var __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__ = __turbopack_context__.i("[project]/models/notification.ts [app-route] (ecmascript)");
;
;
;
;
;
;
;
;
// Monnify's API secret key (store this securely in environment variables)
const MONNIFY_API_SECRET = process.env.MONNIFY_SECRET_KEY;
if (!MONNIFY_API_SECRET) {
    throw new Error("MONNIFY_API_SECRET is not defined in environment variables");
}
// Whitelist of Monnify's IP addresses (update this list as needed)
const MONNIFY_IP_WHITELIST = [
    "35.242.133.146"
];
// Function to validate the Monnify signature
function validateMonnifySignature(body, apiSecret, signature) {
    if (!body || !signature) {
        throw new Error("Request body or Monnify signature is missing");
    }
    const computedHash = __TURBOPACK__imported__module__$5b$externals$5d2f$crypto__$5b$external$5d$__$28$crypto$2c$__cjs$29$__["default"].createHmac("sha512", apiSecret).update(JSON.stringify(body)).digest("hex");
    // console.log(`Computed Hash: ${computedHash}`);
    // console.log(`Received Signature: ${signature}`);
    const isValid = computedHash === signature;
    // console.log(`Signature validation result: ${isValid}`);
    return isValid;
}
async function POST(req) {
    // console.log("Received webhook request...");
    try {
        const clientIp = req.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || null;
        // console.log(`Client IP: ${clientIp}`);
        if (!clientIp || !MONNIFY_IP_WHITELIST.includes(clientIp)) {
            // console.warn(`Unauthorized IP address attempt: ${clientIp}`);
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Unauthorized IP address",
                clientIp
            }, {
                status: 403
            });
        }
        const body = await req.json();
        // console.log("Request body parsed successfully");
        // console.log(`Event Type: ${body.eventType}`);
        const { eventType } = body;
        if (eventType !== "SUCCESSFUL_TRANSACTION" && eventType !== "FAILED") {
            // console.log(`No action taken for event type: ${eventType}`);
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Webhook received but no action taken",
                eventType
            }, {
                status: 200
            });
        }
        const monnifySignature = req.headers.get("monnify-signature");
        // console.log(`Received Monnify Signature: ${monnifySignature}`);
        if (!monnifySignature) {
            // console.error("Monnify signature is missing from headers");
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Monnify signature is missing"
            }, {
                status: 400
            });
        }
        if (!validateMonnifySignature(body, MONNIFY_API_SECRET, monnifySignature)) {
            console.error("Monnify signature validation failed");
            return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
                message: "Invalid Monnify signature",
                signature: monnifySignature
            }, {
                status: 400
            });
        }
        console.log("Monnify signature validated successfully");
        const response = __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            message: "Webhook received"
        }, {
            status: 200
        });
        // console.log("Starting async processing of webhook payload...");
        processWebhookPayload(body).catch((error)=>{
            console.error("Error in async processing:", error);
        });
        return response;
    } catch (error) {
        console.error("Error in webhook handler:", error);
        return __TURBOPACK__imported__module__$5b$project$5d2f$node_modules$2f$next$2f$server$2e$js__$5b$app$2d$route$5d$__$28$ecmascript$29$__["NextResponse"].json({
            message: "Internal server error",
            error: error instanceof Error ? error.message : "Unknown error"
        }, {
            status: 500
        });
    }
}
async function processWebhookPayload(body) {
    console.log("Processing webhook payload...");
    try {
        const { eventData } = body;
        // console.log("Event Data:", JSON.stringify(eventData, null, 2));
        const { paymentReference, product, destinationAccountInformation, amountPaid, customer, paymentStatus } = eventData;
        // console.log(`Payment Reference: ${paymentReference}`);
        // console.log(`Product Type: ${product?.type}`);
        // console.log(`Amount Paid: ${amountPaid}`);
        // console.log(`Payment Status: ${paymentStatus}`);
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
        // console.log("Database connected successfully");
        // Check for existing transaction first
        const existingTransaction = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"].findOne({
            referenceId: paymentReference
        });
        if (existingTransaction) {
            console.log(`Duplicate transaction found with reference: ${paymentReference}. Skipping processing.`);
            return;
        }
        if (product?.type === "RESERVED_ACCOUNT") {
            await processReservedAccountPayment(paymentReference, product, destinationAccountInformation, amountPaid, customer, paymentStatus);
            console.log("wallet Funded");
        } else if (product?.type === "WEB_SDK") {
            await processWebSDKPayment(paymentReference, product, amountPaid, customer, paymentStatus);
            console.log("wallet Funded");
        } else {
            console.log(`Non-handled transaction type (${product?.type}), skipping processing`);
        }
    } catch (error) {
        console.error("Error processing webhook payload:", error);
        if (error instanceof Error) {
            console.error("Error details:", {
                message: error.message,
                stack: error.stack
            });
        }
    }
}
async function processReservedAccountPayment(paymentReference, product, destinationAccountInformation, amountPaid, customer, paymentStatus) {
    console.log("Processing RESERVED_ACCOUNT transaction...");
    const { accountNumber } = destinationAccountInformation;
    // console.log(`Destination Account Number: ${accountNumber}`);
    const user = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findOne({
        "reservedAccountDetails.accounts.accountNumber": accountNumber
    });
    if (!user) {
        console.error(`No user found with account number: ${accountNumber}`);
        return;
    }
    // console.log(`User found: ${user._id}`);
    const userId = user._id;
    const myReferral = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findById(userId).populate("referredBy");
    // console.log( `User referral data loaded: ${myReferral?.referredBy ? "exists" : "none"}`);
    const myReferralEmail = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findById(myReferral.referredBy._id).populate("email");
    const settings = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AdminSettings"].findOne();
    if (!settings) {
    // console.error("No Admin Settings found in database");
    }
    const fee = 2 / 100 * parseFloat(amountPaid);
    const netAmount = parseFloat(amountPaid) - fee;
    console.log(`Calculated fee: ${fee}, Net amount: ${netAmount}`);
    // Start transaction processing
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    const session = await __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].startSession();
    session.startTransaction();
    try {
        // Attempt to create transaction (will fail if duplicate)
        const funding = new __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"]({
            userId: user._id,
            userEmail: user.email,
            type: "AutomaticFunding",
            amount: netAmount,
            balanceBefore: user.accountBalance,
            balanceAfter: user.accountBalance + netAmount,
            referenceId: paymentReference,
            refund: false,
            fundingType: "Automatic",
            fundingSource: "API",
            status: "Successful"
        });
        await funding.save({
            session
        });
        // Only update user balance if transaction was created successfully
        user.accountBalance += netAmount;
        await user.save({
            session
        });
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["saveNotification"])(`Your wallet has been credited with ₦${netAmount.toFixed(2)}`, user.email);
        // Process referral logic
        const isFirstDeposit = !await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ReferralDeposit"].findOne({
            referredId: userId
        }).session(session);
        console.log(`Is first deposit: ${isFirstDeposit}`);
        const referrerCredit = isFirstDeposit ? netAmount * (1.5 / 100) : netAmount * (0.5 / 100);
        console.log(`Calculated referrer credit: ${referrerCredit}`);
        await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ReferralDeposit"].create([
            {
                referredId: userId,
                amount: netAmount,
                referrerCredit
            }
        ], {
            session
        });
        if (myReferral.referredBy) {
            await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findByIdAndUpdate(myReferral.referredBy._id, {
                $inc: {
                    accountBalance: referrerCredit
                }
            }, {
                session
            });
            if (!user) {
                console.log("No user found for referral bonus transaction");
                return;
            } else {
                const referralReferece = await (0, __TURBOPACK__imported__module__$5b$project$5d2f$utils$2f$junkfunctions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["generateReferenceId"])();
                const referralTransaction = new __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"]({
                    userId: myReferral.referredBy._id,
                    userEmail: myReferralEmail,
                    type: "ReferalBonus",
                    amount: referrerCredit,
                    balanceBefore: user.accountBalance,
                    balanceAfter: user.accountBalance + referrerCredit,
                    referenceId: referralReferece,
                    refund: false,
                    fundingType: "Automatic",
                    fundingSource: "API",
                    status: "Successful"
                });
                await referralTransaction.save({
                    session
                });
                await (0, __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["saveNotification"])(`Your wallet has been credited with ₦${referrerCredit.toFixed(2)} as a bonus from the person you referred.`, user.email);
            }
        }
        await session.commitTransaction();
        console.log("Transaction committed successfully");
    } catch (error) {
        await session.abortTransaction();
        if (error.code === 11000) {
            console.warn(`Duplicate transaction detected for reference: ${paymentReference}`);
        } else {
            console.error("Error in transaction processing:", error);
            throw error;
        }
    } finally{
        session.endSession();
    }
}
async function processWebSDKPayment(paymentReference, product, amountPaid, customer, paymentStatus) {
    console.log("Processing WEB_SDK transaction...");
    const { email } = customer;
    const user = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findOne({
        email
    });
    if (!user) {
        console.error(`No user found with email: ${email}`);
        return;
    }
    const userId = user._id;
    const myReferral = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findById(userId).populate("referredBy");
    const myReferralEmail = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findById(myReferral.referredBy._id).populate("email");
    const settings = await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["AdminSettings"].findOne();
    if (!settings) {
        console.log("no Admin Settings");
    }
    console.log(amountPaid);
    const fee = 2 / 100 * parseFloat(amountPaid);
    const netAmount = parseFloat(amountPaid) - fee;
    // Start transaction processing
    await (0, __TURBOPACK__imported__module__$5b$project$5d2f$lib$2f$connectdb$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"])();
    const session = await __TURBOPACK__imported__module__$5b$externals$5d2f$mongoose__$5b$external$5d$__$28$mongoose$2c$__cjs$29$__["default"].startSession();
    session.startTransaction();
    try {
        // Attempt to create transaction (will fail if duplicate)
        const funding = new __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"]({
            userId: user._id,
            userEmail: user.email,
            type: "AutomaticFunding",
            amount: netAmount,
            balanceBefore: user.accountBalance,
            balanceAfter: user.accountBalance + netAmount,
            referenceId: paymentReference,
            refund: false,
            fundingType: "Automatic",
            fundingSource: "ONE TIME PAYMENT",
            status: "Successful"
        });
        await funding.save({
            session
        });
        // Only update user balance if transaction was created successfully
        user.accountBalance += netAmount;
        await user.save({
            session
        });
        await (0, __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["saveNotification"])(`Your wallet has been credited with ₦${netAmount.toFixed(2)}`, user.email);
        // Process referral logic
        const isFirstDeposit = !await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ReferralDeposit"].findOne({
            referredId: userId
        }).session(session);
        const referrerCredit = isFirstDeposit ? netAmount * (1.5 / 100) : netAmount * (0.5 / 100);
        await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["ReferralDeposit"].create([
            {
                referredId: userId,
                amount: netAmount,
                referrerCredit
            }
        ], {
            session
        });
        if (myReferral.referredBy) {
            await __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$user$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["User"].findByIdAndUpdate(myReferral.referredBy._id, {
                $inc: {
                    accountBalance: referrerCredit
                }
            }, {
                session
            });
            if (!user) {
                console.log("No user found for referral bonus transaction");
                return;
            } else {
                const referralReferece = await (0, __TURBOPACK__imported__module__$5b$project$5d2f$utils$2f$junkfunctions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["generateReferenceId"])();
                const referralTransaction = new __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$transactions$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["default"]({
                    userId: myReferral.referredBy._id,
                    userEmail: myReferralEmail,
                    type: "ReferalBonus",
                    amount: referrerCredit,
                    balanceBefore: user.accountBalance,
                    balanceAfter: user.accountBalance + referrerCredit,
                    referenceId: referralReferece,
                    refund: false,
                    fundingType: "Automatic",
                    fundingSource: "API",
                    status: "Successful"
                });
                await referralTransaction.save({
                    session
                });
                await (0, __TURBOPACK__imported__module__$5b$project$5d2f$models$2f$notification$2e$ts__$5b$app$2d$route$5d$__$28$ecmascript$29$__["saveNotification"])(`Your wallet has been credited with ₦${referrerCredit.toFixed(2)} as a bonus from the person you referred.`, user.email);
            }
        }
        await session.commitTransaction();
        console.log("Transaction committed successfully");
    } catch (error) {
        await session.abortTransaction();
        if (error.code === 11000) {
            console.warn(`Duplicate transaction detected for reference: ${paymentReference}`);
        } else {
            console.error("Error in transaction processing:", error);
            throw error;
        }
    } finally{
        session.endSession();
    }
}
}}),

};

//# sourceMappingURL=%5Broot-of-the-server%5D__0df39105._.js.map