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/razorpay/api_psy_product_checkout.php
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
# json header
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');

include("../../../../wp-config.php");
date_default_timezone_set('Asia/Calcutta');
global $wpdb;
global $current_user;
wp_get_current_user();
$user_id = $current_user->ID;

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


//encoded parameters
function random_strings($length_of_string) 
{ 
    $str_result = '0123$456789ABC#DEFGHIJKL$MNOPQRST@UVWXYZab!cdefghijklmnopqrstuvwxyz'; 

    return substr(str_shuffle($str_result),0, $length_of_string); 
}

// rzp_test_e5mtb6253WwYAz

// LOn4oF1yGfixAexNGosuZJhm
include 'psy_razorypay_config.php';
require 'library/Razorpay.php';

use Razorpay\Api\Api;

/****request form parameters */
$json = file_get_contents('php://input');
$response = json_decode($json);

function decodeReq($value)
{
    $str = substr($value, 7);
    $str1 = substr($str, 0, -6);

    $decode = base64_decode($str1);
    return $decode;
}

$curDate = date('Y-m-d H:i:s');

if (!empty($response)) {

    $discount_id = $response->discount_id;
    $encodeRef = $response->encode_ref;
    $encodeType = $response->encode_type;
    $slot_id = decodeReq($encodeRef);
    $plan_id = decodeReq($encodeType);
    $payMethod = $response->payMethod;
    $category = $response->category;
    $txn_type = $response->txn_type;
    #userdetails
    $getUdata = $wpdb->get_row("SELECT first_name,email_address,mobile_number FROM $PSY_USERS_DETAILS where user_id='$user_id'");
    #plandetails
    if ($plan_id == 'C') {
        $getSlotDetails = $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='$slot_id'");
        $amount = $getSlotDetails->pricing_for_slot;
        $plan_name = $getSlotDetails->counselor_name;
        $counselor = $getSlotDetails->counselor_id;
    } else if ($plan_id == 'P') {
        $getPlansDetails = $wpdb->get_row("SELECT plan_id, plan_name, plan_price FROM $PSY_PLANS where plan_id='$slot_id'");
        $plan_name = $getPlansDetails->plan_name;
        $amount = $getPlansDetails->plan_price;
    }

    $other_info = $user_id . "|" . $amount;
    $date = date('Y-m-d H:i:s');
    $gateway = $payMethod;
    $txn_type_id = $txn_type;
    $TXN_AMOUNT = $amount;
    if ($discount_id != '' && $discount_id != '0' && is_numeric($discount_id)) {
        /*** get discount data***/
        $discountData = $wpdb->get_row("SELECT discount_type, discount_value, discount_code FROM $PSY_DISCOUNT_CODE WHERE id='$discount_id'");
        $discountCode = $discountData->discount_code;
        if ($discountData->discount_type == 'F') {
            $sendAmount = ($amount - $discountData->discount_value);
        } else if ($discountData->discount_type == 'P') {
            $sendAmount = $amount - ($amount * ($discountData->discount_value / 100));
        }
        /**update discount used count */
        $updateUsedCount = $wpdb->query("UPDATE $PSY_DISCOUNT_CODE set used_count=used_count+1 where id='$discount_id'");
        $other_info = $other_info."|".$discountCode;
    } else {
        $sendAmount = $TXN_AMOUNT;
        $discountCode = '';
    }
    // echo $sendAmount;
    if ($sendAmount != '0' && $sendAmount != '') {

        // INSERT DATA INTO TRANSACTION TABLE 
        $insertTemp = "INSERT into $PSY_ONLINE_TXN_TEMP set type_of_txn='$plan_id', user_id='$user_id', ref_id='$slot_id', discount_code='$discountCode', mrp_amount='$amount', net_amount='$sendAmount', payment_type='$gateway', other_data='$other_info', txn_status='F', txn_date='$curDate'";
        if ($wpdb->query($insertTemp)) {
            $insertId = $wpdb->insert_id;
            $encode = rtrim(strtr(base64_encode($insertId), '+/', '-_'), '=');
            $shuffle = random_strings(7);
            $backShuffle = random_strings(6);
            $razorpay_resp_id = $shuffle . $encode . $backShuffle;
            $amount = $sendAmount * 100;
            $api = new Api($keyId, $keySecret);
            $orderData = [
                'receipt'         => 'rcptid_' . $insertId,
                'amount'          => $amount, // rupees in paise
                'currency'        => 'INR'
            ];

            $razorpayOrder = $api->order->create($orderData);
            $razorpayOrderId = $razorpayOrder['id'];
            $displayAmount = $orderData['amount'];
            $merchantOrderId = 'SA-'.$insertId;
            $data = [
                "key"               => $keyId,
                "amount"            => $amount,
                "name"              => "Self Analyse",
                "description"       => "Registered for ".$plan_name,
                "image"             => "https://selfanalyse.com/wp-content/themes/psychometrics/images/shine-logo.png",
                "prefill"           => [
                    "name"              => $getUdata->first_name,
                    "email"             => $getUdata->email_address,
                    "contact"           => $getUdata->mobile_number,
                ],
                "notes"             => [
                    "merchant_order_id" => $merchantOrderId,
                    "domain_name" => 'selfanalyse.com'
                ],
                "theme"             => [
                    "color"             => "#01356e"
                ],
                "order_id"          => $razorpayOrderId,
            ];

           $reverseArray = array("status" => 1, "message" => "Payment under process", "razorpay_resp_id" => $razorpay_resp_id, "cookie_save" => $data);
        } else {
           $reverseArray = array("status" => 0, "message" => "Something went wrong please try again later");
        }
    } else {
        $reverseArray = array("status" => 0, "message" => "Error:in payment amount");
    }
}
echo json_encode($reverseArray);