FUNDING LOGIC

mail@pastecode.io avatar
unknown
php
a year ago
14 kB
5
Indexable
<?php

// Include necessary functions
include '../config/functions.inc.php';

// Check if all required POST parameters are set
if (isset($_POST['fund_ref']) && isset($_POST['fund_client']) && isset($_POST['fund_client_name']) && isset($_POST['fund_amount']) && isset($_POST['fund_method'])) {

    // Sanitize input data
    $ref = sanitizeInput($_POST['fund_ref']);
    $email = sanitizeInput($_POST['fund_client']);
    $name = sanitizeInput($_POST['fund_client_name']);
    $amount = sanitizeInput($_POST['fund_amount']);
    $methodfull = sanitizeInput($_POST['fund_method']);

    // Admin email details
    $adminToEmail = 'thomkralow@gmail.com';
    $from = $GLOBALS['system_support_email'];
    $fromName = $GLOBALS['system_name'];

    // Admin email content
    $adminEmailSubject = 'Client Deposit Notification';

    // Admin email HTML message
    $adminEmailMessage = '<!DOCTYPE html>
    <html lang="en">
    <head>
        <!-- Meta tags for HTML document -->
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Client Deposit Notification</title>
        <style>
            /* CSS styles for the email content */
            body {
                font-family: Arial, sans-serif;
                background-color: #f4f4f4;
                margin: 0;
                padding: 0;
            }

            .container {
                max-width: 600px;
                margin: 20px auto;
                background-color: #ffffff;
                padding: 20px;
                border-radius: 5px;
                box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            }

            h2, p {
                color: #333;
            }

            strong {
                color: #007bff;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <h2>Client Deposit Notification</h2>
            <p>Hello <strong>Admin</strong>,</p>
            <p>We\'re excited to inform you that a deposit has been made:</p>
            <ul>
                <li><strong>Email:</strong> ' . $email . '</li>
                <li><strong>Amount:</strong> $' . number_format($amount, 2) . '</li>
                <li><strong>Deposit Method:</strong> ' . $methodfull . '</li>
            </ul>
            <p>If you have any questions or concerns, please feel free to contact our support team.</p>
            <p>Thank you for using our platform.</p>
            <p>Best Regards,<br>' . $GLOBALS['system_name'] . ' Team</p>
        </div>
    </body>
    </html>';

    // Timestamp for the deposit
    $fundTime = date('Y-m-d H:i:s');
    $fundTimeDate = date('F j, Y', strtotime($fundTime));
    $fundTimeTime = date('g:i A', strtotime($fundTime));

    // User email details
    $fromEmail = $GLOBALS['system_support_email'];
    $depositSubject = 'Deposit Notification';

    // User email HTML message
    $depositMessage  = '<!DOCTYPE html>
    <html lang="en">
    <head>
        <!-- Meta tags for HTML document -->
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Deposit Notification</title>
        <style>
            /* Custom CSS styles for the email content */
            body {
                font-family: Arial, sans-serif;
                background-color: #f5f5f5;
                margin: 0;
                padding: 0;
            }

            .container {
                max-width: 600px;
                margin: 0 auto;
                background-color: #ffffff;
                padding: 20px;
                border-radius: 5px;
                box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
            }

            h1 {
                color: #333;
            }

            p {
                color: #666;
            }

            .cta-button {
                display: inline-block;
                background-color: #007bff;
                color: #fff;
                padding: 10px 20px;
                text-decoration: none;
                border-radius: 5px;
                margin-top: 20px;
            }

            .cta-button:hover {
                background-color: #0056b3;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <h2>Deposit Notification</h2>
            <p>Hello '.$name.',</p>
            <p>We\'re excited to inform you that your deposit/funding transaction has been initiated and is now in progress. This is the first step towards growing your investment with us.</p>
            <p>Transaction Details:</p>
            <ul>
                <li><strong>Transaction ID:</strong> #'.$ref.'</li>
                <li><strong>Amount:</strong> $ '.number_format($amount, 2).'</li>
                <li><strong>Deposit Method:</strong> '.$methodfull.'</li>
                <li><strong>Date:</strong> '.$fundTimeDate.' '.$fundTimeTime.'</li>
            </ul>
            <p>If your deposit is confirmed, your wallet balance will be updated accordingly. You will receive another email notification once the status of your deposit is confirmed.</p>
            <p>If you have any questions or concerns regarding this transaction, please feel free to contact our support team. We\'re here to assist you.</p>
            <p>Thank you for choosing our platform for your investment needs. We look forward to a successful partnership.</p>
            <p>Best Regards,<br>'.$GLOBALS['system_name'].' Team</p>
        </div>
    </body>
    </html>';

    $notificationMessage = 'New $' . number_format($amount, 2) . ' Deposit Transaction!';

    // Sanitize and validate amount input
    if (!is_numeric($amount) || $amount <= 0) {

        // Log the specific error for sending admin email
        handleFundingError('Invalid Funding Amount');
    }

    // Validate method input
    if (!ctype_alpha($methodfull)) {

        // Log the specific error for sending admin email
        handleFundingError('Invalid Funding Method');
    }

    // Get user deposit count
    $depositCount = getUserDepositCountByEmail($email);

    // Get referrer details
    $referrerId = selectReferrerByEmail($email);

    $referralId = selectUserReferralIDByEmail($email);

    $checkDepositNotification = checkDepositNotificationStatus($email);

    // Check user deposit count
    if ($depositCount > 0) {

        // Insert funding record
        $insertFunding = insertFundingRecord($ref, $email, $amount, $methodfull, $fundTime);

        if ($insertFunding) {

            // Insert notification record
            $insertNotification = insertNotificationRecord($email, $notificationMessage, $fundTime);

            if ($insertNotification) {

                // Send admin email
                $sendAdminEmail = sendEmail($adminToEmail, $adminEmailSubject, $adminEmailMessage, $from, $fromName);

                if ($sendAdminEmail) {

                    // Check user's deposit notification status
                    if ($checkDepositNotification) {

                        // Send deposit notification email to the user
                        $sendDepositNotificationEmail = sendEmail($email, $depositSubject, $depositMessage, $fromEmail, $fromName);

                        if ($sendDepositNotificationEmail) {
                            // Success: funding and notifications sent
                            echo 'funding success';
                        } else {
                            // Log the specific error for sending deposit notification email
                            handleFundingError('Error Sending Deposit Notification Email');
                        }
                    } else {
                        // User's Deposit Notification Status is Disabled
                        // This also means that the Deposit transaction was initiated successfully
                        echo 'funding success';
                    }
                } else {
                    // Log the specific error for sending admin email
                    handleFundingError('Error Sending Admin Email');
                }
            } else {
                // Log the specific error for inserting notification record
                handleFundingError('Error Inserting Notification Record');
            }
        } else {
            // Log the specific error for inserting funding record
            handleFundingError('Error Inserting Funding Record');
        }
    } else {

        // User has no previous deposits

        if ($referrerId) {

            // User has a referrer

            if (recordReferralEarnings($referrerId, $referralId, $amount)) {

                // Record referral earnings successful

                // Insert funding record
                $insertFunding = insertFundingRecord($ref, $email, $amount, $methodfull, $fundTime);

                if ($insertFunding) {

                    // Insert notification record
                    $insertNotification = insertNotificationRecord($email, $notificationMessage, $fundTime);

                    if ($insertNotification) {

                        // Send admin email
                        $sendAdminEmail = sendEmail($adminToEmail, $adminEmailSubject, $adminEmailMessage, $from, $fromName);

                        if ($sendAdminEmail) {

                            // Check user's deposit notification status
                            if ($checkDepositNotification) {

                                // Send deposit notification email to the user
                                $sendDepositNotificationEmail = sendEmail($email, $depositSubject, $depositMessage, $fromEmail, $fromName);

                                if ($sendDepositNotificationEmail) {
                                    // Success: funding and notifications sent
                                    echo 'funding success';
                                } else {
                                    // Log the specific error for sending deposit notification email
                                    handleFundingError('Error Sending Deposit Notification Email');
                                }
                            } else {
                                // User's Deposit Notification Status is Disabled
                                // This also means that the Deposit transaction was initiated successfully
                                echo 'funding success';
                            }
                        } else {
                            // Log the specific error for sending admin email
                            handleFundingError('Error Sending Admin Email');
                        }
                    } else {
                        // Log the specific error for inserting notification record
                        handleFundingError('Error Inserting Notification Record');
                    }
                } else {
                    // Log the specific error for inserting funding record
                    handleFundingError('Error Inserting Funding Record');
                }
            } else {

                // Log the specific error for referral earnings
                handleFundingError('Error Recording Referral Earnings');
            }
        } else {

            // User has no referrer

            // Insert funding record
            $insertFunding = insertFundingRecord($ref, $email, $amount, $methodfull, $fundTime);

            if ($insertFunding) {

                // Insert notification record
                $insertNotification = insertNotificationRecord($email, $notificationMessage, $fundTime);

                if ($insertNotification) {

                    // Send admin email
                    $sendAdminEmail = sendEmail($adminToEmail, $adminEmailSubject, $adminEmailMessage, $from, $fromName);

                    if ($sendAdminEmail) {

                        // Check user's deposit notification status
                        if ($checkDepositNotification) {

                            // Send deposit notification
                            $sendDepositNotificationEmail = sendEmail($email, $depositSubject, $depositMessage, $fromEmail, $fromName);

                                if ($sendDepositNotificationEmail) {

                                    echo 'funding success';
                                } else {
                                    // Log the specific error for sending deposit notification email
                                    handleFundingError('Error Sending Deposit Notification Email');
                                }
                            } else {
                                
                                // User's Deposit Notification Status is Disabled
                                // This also means that the Deposit transaction was initiated successfully
                                echo 'funding success';
                            }
                        } else {
                            // Log the specific error for sending admin email
                            handleFundingError('Error Sending Admin Email');
                        }
                    } else {
                        // Log the specific error for inserting notification record
                        handleFundingError('Error Inserting Notification Record');
                    }
                } else {
                    // Log the specific error for inserting funding record
                    handleFundingError('Error Inserting Funding Record');
                }
            }
        }
    }
Leave a Comment