HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-31-18-78 6.17.0-1017-aws #17~24.04.1-Ubuntu SMP Tue May 26 21:09:53 UTC 2026 aarch64
User: ubuntu (1000)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /var/www/selfanalyse/wp-content/plugins/psychometrics/psy_thank_you.php
<?php
//session_start();
//Razorpay
include 'razorpay/psy_razorypay_config.php';
require 'razorpay/library/Razorpay.php';

use Razorpay\Api\Api;
//Decode
function decodeReq($value)
{
    $str = substr($value, 7);
    $str1 = substr($str, 0, -6);
    $decode = base64_decode($str1);
    return $decode;
}
if (is_user_logged_in()) {

    global $current_user;
    $user_id = $current_user->ID;

    global $wpdb;

    $PSY_ONLINE_TXN_TEMP = $wpdb->prefix . PSY_ONLINE_TXN_TEMP;
    $PSY_ONLINE_TXN_MAIN = $wpdb->prefix . PSY_ONLINE_TXN_MAIN;
    $PSY_SUBSCRIPTION = $wpdb->prefix . PSY_SUBSCRIPTION;
    $PSY_PLANS = $wpdb->prefix . PSY_PLANS;
    $PSY_COUNSELORS = $wpdb->prefix . PSY_COUNSELORS;
    $PSY_COUNSELLING_SUBSCRIPTION = $wpdb->prefix . PSY_COUNSELLING_SUBSCRIPTION;
    $PSY_USERS_DETAILS = $wpdb->prefix . PSY_USERS_DETAILS;
    $PSY_DISCOUNT_CODE = $wpdb->prefix . PSY_DISCOUNT_CODE;
    $PSY_SLOT_AVAILABLE = $wpdb->prefix . PSY_SLOT_AVAILABLE;
    $PSY_STATES = $wpdb->prefix . PSY_STATES;

    $userDetails = $wpdb->get_row("SELECT ud.first_name,ud.email_address,s.state_name,s.state_code,ud.address,ud.pincode,ud.mobile_number,ud.state_id FROM $PSY_USERS_DETAILS as ud LEFT JOIN $PSY_STATES as s on s.state_id=ud.state_id where user_id='$user_id'");
    $user_name = $userDetails->first_name;
    $email = $userDetails->email_address;
    $user_state = $userDetails->state_name;
    $student_mobile = $userDetails->mobile_number;
    $user_address = $userDetails->address . ' ' . $userDetails->pincode;
    $student_state_name = $userDetails->state_name ? $userDetails->state_name : 'NA';
    $student_state_code = $userDetails->state_code ? $userDetails->state_code : 'NA';
    $state_id = $userDetails->state_id ? $userDetails->state_id : 0;

    //Check
    if (empty($_POST['razorpay_payment_id']) === false) {
        $api = new Api($keyId, $keySecret);
        try {
            // Please note that the razorpay order ID must
            // come from a trusted source (session here, but
            // could be database or something else)
            $attributes = array(
                'razorpay_order_id' => $_POST['razorpay_resp_id2'],
                'razorpay_payment_id' => $_POST['razorpay_payment_id'],
                'razorpay_signature' => $_POST['razorpay_signature']
            );
            $api->utility->verifyPaymentSignature($attributes);
            $success = true;
        } catch (SignatureVerificationError $e) {
            $success = false;
            $error = $e->getMessage();
        }
    } else {
        //echo '<script>window.location.href="/self-analyse/"</script>';
        //exit;
    }

    if ($success == true) {

        $pgSt = 1;
        $temp_txn_id = decodeReq($_POST['razorpay_resp_id']);

        if (is_numeric($temp_txn_id) && $temp_txn_id != '') {

            $result = $wpdb->get_row("SELECT temp_id, type_of_txn, user_id, ref_id, discount_code, mrp_amount, net_amount, payment_type, other_data, txn_status, any_other_remarks, txn_date FROM $PSY_ONLINE_TXN_TEMP WHERE temp_id='$temp_txn_id' AND txn_status='F'");

            if ($result) {
                $temp_id = $result->temp_id;
                $txn_type = $result->type_of_txn;
                $ref_id = $result->ref_id;
                $discount_code = $result->discount_code;
                $mrp_amount = $result->mrp_amount;
                $amount = $result->net_amount;
                $payment_type = $result->payment_type;
                $other_data = $result->other_data;
                $transaction_id = $_POST['razorpay_payment_id'];
                $rz_order_id = $_POST['razorpay_resp_id2'];
                $message = 'Transaction Successful';
                $date = date('Y-m-d h:i:s');
                //check product
                if ($txn_type == 'P') {
                    $get_plan = $wpdb->get_row("SELECT plan_name,plan_price FROM $PSY_PLANS where plan_id='$ref_id'");
                    $mrp_amount = $get_plan->plan_price;
                    $counselor_id = '';
                } else if ($txn_type == 'C') {
                    $get_plan = $wpdb->get_row("SELECT ps.id, pc.counselor_name,ps.counselor_id ,ps.pricing_for_slot FROM $PSY_SLOT_AVAILABLE as ps LEFT JOIN $PSY_COUNSELORS as pc on pc.counselor_id=ps.counselor_id WHERE ps.id='$ref_id'");
                    $mrp_amount = $mrp_amount;
                    $counselor_id = $get_plan->counselor_id;
                }
                //data Array
                $txn_other_data = $transaction_id . '|' . $temp_id . '|' . $mrp_amount . '|' . $amount . '|' . $discount_code . '|' . $txn_type . '|' . $message;
                //Insert
                $insertMain = "INSERT into $PSY_ONLINE_TXN_MAIN SET temp_id='$temp_id', type_of_txn='$txn_type', user_id='$user_id', ref_id='$ref_id', mrp_amount='$mrp_amount', discount_code='$discount_code', net_amount='$amount', payment_type='online', payment_gateway='$payment_type', other_data='$other_data', transaction_id='$transaction_id', sec_txn_id='$rz_order_id', txn_message='$message', txn_return_data='$txn_other_data', txn_status='S', txn_date='$date'";
                if ($wpdb->query($insertMain)) {
                    $last_id = $wpdb->insert_id;
                    $updateTemp = $wpdb->query("UPDATE $PSY_ONLINE_TXN_TEMP set txn_status='S', any_other_remarks='$txn_other_data' where temp_id='$temp_id'");

                    // data to send on other database with payment details
                    $from_domain = ROOT_LINK;
                    $gst_rate = 18;
                    $if_vendor = 'SA';
                    $year_extn = finYear();
                    $discount_amount = ($discount_code != '') ? ($mrp_amount-$amount) : 0;
                    $net_amount = ($amount != '') ? $amount : 0;
                    $gepl_amount = $mrp_amount;
                    $transaction_id2 = '0';
                    $ref_name3 = '0';
                    $ref_id3 = '0';
                    $student_gst_name = '';
                    $student_gstin = '';

                    $ref_name1 = 'ref_id';
                    $ref_id1 = $ref_id;
                    $ref_name2 = 'razorpay_order_id';
                    $ref_id2 = $rz_order_id;
                    $ref_name3 = 'counselor_id';
                    $ref_id3 = $counselor_id;
                    
                    $paymentType = 'ONLINE';

                    if ($txn_type == 'C') {

                        $insertSubscription = "INSERT into $PSY_COUNSELLING_SUBSCRIPTION set slot_table_id='$ref_id', counselor_id='$counselor_id', user_id='$user_id', online_txn_table_id='$last_id', status='A', subs_date='$date'";
                        $updateSlot = $wpdb->query("UPDATE $PSY_SLOT_AVAILABLE set slot_status='S' where id='$ref_id'");
                        if ($wpdb->query($insertSubscription)) {
                            $order_id = $wpdb->insert_id;
                            $random_number = substr(number_format(time() * rand(), 0, '', ''), 0, 5);

                            /*********send counselling booking message***** */
                            include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
                            sendBookingCounsSMS($phone, $user_name);
                            sendCounselorSMS($user_name, $ref_id);

                            /*********send counselling booking email***** */
                            include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
                            sendBookingCounsEmail($ref_id, $user_id);
                            sendBookingEmailToCounselor($ref_id, $user_id);

                            /********create invoice data */
                            include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_functions.php';
                            $payment_type_id = '3';
                            $txnType ='SA-CNS-DIR-PG-counselling-booking';
                            $payment_for = 'Selfanalyse Counselling session';
                            invoice($txnType, $txn_type, $ref_id, $order_id, $amount, $txn_id, $user_id, $user_name, $email, $user_address, $user_state, $date);
                            //to store payment data of all platform to specific database
                            getPaymentInvoice($from_domain, $if_vendor, $txnType, $payment_for, $paymentType, $temp_id, $mrp_amount, $gst_rate, $gepl_amount, $discount_amount, $net_amount, $user_name, $user_address, $student_mobile, $email, $student_gst_name, $student_gstin, $state_id, $student_state_code, $student_state_name, $year_extn, $transaction_id, $transaction_id2, $date, $ref_name1, $ref_id1, $ref_name2, $ref_id2, $ref_name3, $ref_id3);
                        }
                    } else if ($txn_type == 'P') {
                        $get_exams = $wpdb->get_row("SELECT plan_name,reference_id,test_type FROM $PSY_PLANS where plan_id='$ref_id'");

                        $exam_id = explode(",", $get_exams->reference_id);
                        foreach ($exam_id as $e_id) {
                            if ($e_id == '48282') {
                                $test_type = 'APT';
                            } else if ($e_id == '48305') {
                                $test_type = 'PER';
                            } else if ($e_id == '48328') {
                                $test_type = 'INT';
                            } else {
                                $test_type = $get_exams->test_type;
                            }
                            $insertSubscription = "INSERT into $PSY_SUBSCRIPTION set user_id='$user_id', plan_id='$ref_id', exam_id='$e_id', test_type='$test_type', purchase_date='$date', status='1', active_status='1', active_date='$date', online_txn_table_id='$last_id', source='SM', source_id='0'";
                            if ($wpdb->query($insertSubscription)) {
                                $order_id = $last_id;
                                $random_number = substr(number_format(time() * rand(), 0, '', ''), 0, 5);
                            }
                        }

                        /*********send counselling booking message***** */
                        include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_mail_sms_functions.php';
                        sendBookingCounsSMS($phone, $user_name);
                        sendCounselorSMS($user_name, $ref_id);

                        /*********send counselling booking email***** */
                        sendBookingCounsEmail($ref_id, $user_id);
                        sendBookingEmailToCounselor($ref_id, $user_id);

                        /********create invoice data */
                        include_once '/var/www/selfanalyse/wp-content/plugins/psychometrics/api/psy_functions.php';
                        $payment_type_id = '3';
                        $txnType ='SA-EXM-DIR-PG-student-registration';
                        $payment_for = 'Selfanalyse Plan';
                        $ref_name3 = 'user_id';
                        $ref_id3 = $user_id;
                        invoice($txnType, $txn_type, $ref_id, $order_id, $amount, $txn_id, $user_id, $user_name, $email, $user_address, $user_state, $date);
                        //to store payment data of all platform to specific database
                        getPaymentInvoice($from_domain, $if_vendor, $txnType, $payment_for, $paymentType, $temp_id, $mrp_amount, $gst_rate, $gepl_amount, $discount_amount, $net_amount, $user_name, $user_address, $student_mobile, $email, $student_gst_name, $student_gstin, $state_id, $student_state_code, $student_state_name, $year_extn, $transaction_id, $transaction_id2, $date, $ref_name1, $ref_id1, $ref_name2, $ref_id2, $ref_name3, $ref_id3);
                    }
                    $pgSt = 1;
                    $showMessage = "Success: Transaction successful";
                } else {
                    $pgSt = 2;
                    $showMessage = "Error: While adding transaction";
                }
            } else {
                $pgSt = 2;
                $showMessage = "Error: Temp detail not fetch";
            }
        } else {
            $pgSt = 2;
            $showMessage = "Error: Temp detail not fetch";
        }
    } else {
        $pgSt = 2;
        $showMessage = "Error: Transaction falied";
    }
?>
    <script src="/wp-content/plugins/psychometrics/js/bootstrap.js"></script>
    <!-- THANK YOU SECTION -->
    <?php if ($pgSt == 1) { ?>
        <section class="thankyou-section">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="thankyou-box">
                            <h4>Thank you. You are successfully enrolled.</h4>

                            <table class="table">
                                <tbody>
                                    <tr class="bg">
                                        <th style="width: 26%;">Transaction ID</th>
                                        <th>: &nbsp; &nbsp; #<?php echo $transaction_id; ?></th>
                                    </tr>
                                    <tr class="bg">
                                        <th style="width: 26%;">Order ID</th>
                                        <th>: &nbsp; &nbsp; #<?php echo $random_number . $order_id; ?></th>
                                    </tr>
                                    <tr class="bg">
                                        <th>Email</th>
                                        <th>: &nbsp; &nbsp; <?php echo $email; ?></th>
                                    </tr>
                                    <tr class="bg">
                                        <th>Date</th>
                                        <th>: &nbsp; &nbsp; <?php echo date('d F, Y'); ?></th>
                                    </tr>
                                    <tr class="bg">
                                        <th>Total</th>
                                        <th>: &nbsp; &nbsp; Rs. <?php echo $amount; ?></th>
                                    </tr>
                                    <tr class="bg">
                                        <th>Payment Method</th>
                                        <th>: &nbsp; &nbsp; Online Payment</th>
                                    </tr>
                                </tbody>
                            </table>
                            <div class="details-box" style="display: block;" id="tt_payment_cheque">
                                <span>Your Address</span> <br><br>

                                <p>Grapss Edutech Pvt. Ltd.</p>
                                <p>Address :-1/22, 2nd Floor,</p>
                                <p>Asaf Ali road,New Delhi - 110002</p>
                            </div>

                            <button class="continue-btn" onclick="window.location.href='/dashboard'">Continue</button>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- END THANK YOU SECTION -->
    <?php
        unset($_SESSION['COUNSELOR']);
    } else {

        $updateTemp = $wpdb->query("UPDATE $PSY_ONLINE_TXN_TEMP set txn_status='F', any_other_remarks='transaction failed' where temp_id='$temp_txn_id'");
    ?>
        <section class="thankyou-section">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="thankyou-box">
                            <h4>Your transaction is failed..</h4>

                            <table class="table">
                                <tbody>
                                    <tr class="bg">
                                        <div class="alert alert-danger">
                                            Error:Transaction failed
                                        </div>
                                    </tr>
                                </tbody>
                            </table>
                            <button onclick="window.location.href='/dashboard'">Continue</button>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    <?php
        unset($_SESSION['COUNSELOR']);
    }
} else {
    ?>
    <script>
        window.location.href = '<?php echo ROOT_LINK . 'login' ?>'
    </script>
<?php
}
?>