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/api/psy_payment_temp.php
<?php
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
include("../../../../wp-config.php");


$json = file_get_contents('php://input');
$data = json_decode($json);
// ini_set('display_errors',1);
// ini_set('display_startup_errors',1);
// error_reporting(E_ALL);

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

global $wpdb;
$PSY_SLOT_AVAILABLE = $wpdb->prefix . PSY_SLOT_AVAILABLE;
$PSY_ONLINE_TXN_TEMP = $wpdb->prefix . PSY_ONLINE_TXN_TEMP;
$PSY_PLANS = $wpdb->prefix . PSY_PLANS;
$PSY_USERS_DETAILS = $wpdb->prefix . PSY_USERS_DETAILS;
$PSY_DISCOUNT_CODE = $wpdb->prefix . PSY_DISCOUNT_CODE;

if(isset($data)){

$amount = $wpdb->get_var("SELECT pricing_for_slot FROM $PSY_SLOT_AVAILABLE where id='$slot'");

$date = date('Y-m-d H:i:s');
$txn_type = $data->txn_type;
$ref_id = $data->ref_id;
$payment_type = $data->payment_type;
$hash_value = $data->hash_value;
$counselor = $data->counselor;
$state_id = $data->state_id;

//find percentage value
function percentage($num, $per)
{
    return ($num / 100) * $per;
}

if($txn_type == 'C')
{
    $amount = $wpdb->get_var("SELECT pricing_for_slot FROM $PSY_SLOT_AVAILABLE where id='$ref_id'");
}
else if($txn_type == 'P')
{
    $amount = $wpdb->get_var("SELECT plan_price FROM $PSY_PLANS where plan_id='$ref_id'");
}

if($state_id != '' && $state_id != '0')
{
    $updateState = $wpdb->query("UPDATE $PSY_USERS_DETAILS set state_id='$state_id' where user_id='$user_id'");
}

if (isset($_SESSION['DISCOUNT_ID'])) {
    $discount_id = $_SESSION['DISCOUNT_ID'];
    $getdiscount = $wpdb->get_row("SELECT id,discount_value FROM $PSY_DISCOUNT_CODE where id='$discount_id' and status='1'");
    $percentValue = percentage($amount, $getdiscount->discount_value);

    $finalAmount = $amount - $percentValue;
} else {
    $finalAmount = $amount;
}


$insertTemp = "INSERT into $PSY_ONLINE_TXN_TEMP set type_of_txn='$txn_type', user_id='$user_id', ref_id='$ref_id', mrp_amount='$amount', net_amount='$finalAmount', payment_type='$payment_type', other_data='$hash_value', txn_status='F', txn_date='$date'";
if($wpdb->query($insertTemp))
{
    $last_id = $wpdb->insert_id;

    unset($_SESSION['TEMP_ID']);
    unset($_SESSION['TXN_TYPE']);
    unset($_SESSION['REF_ID']);
    unset($_SESSION['COUNSELOR']);
    session_start();
    $_SESSION['TEMP_ID'] = $last_id;
    $_SESSION['TXN_TYPE'] = $txn_type;
    $_SESSION['REF_ID'] = $ref_id;
    $_SESSION['COUNSELOR'] = $counselor;

    $revertArray[] = array("status" => "1", "message" => "Inserted");
}
echo json_encode($revertArray);



}