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/grapossconnect/center-admin/wallet_function.php
<?php

/***make wallet deduction and payment */
function makeWalletTxn($agent_id, $agent_code, $product_id, $txn_amount, $finalDeduct, $user_id)
{
    include '../sample-wp/wp-config.php';
    global $wpdb;
    $date = date('Y-m-d H:i:s');

    $agentData = $wpdb->get_row("SELECT name,email FROM grp_agents where agent_id='$agent_id'");

    $email = $agentData->email;
    $name = $agentData->name;

    /***get the agent commission and type */
    $getAgentdata = $wpdb->get_row("SELECT comm_id, comm_share_type, commission_agent, commission_mf FROM grp_agents_product_comm where agent_id='$agent_id' and product_id='$product_id'");

    if (($getAgentdata->comm_id != '') && ($getAgentdata->commission_agent != '') && ($getAgentdata->commission_agent != '0')) {
        $getProdData = $wpdb->get_row("SELECT product_amount, gst_percentage, tds_percentage, merchant_share, share_type,amount_type, self_share FROM grp_product where product_id='$product_id'");
        
        $p_amt = $txn_amount; //$getProdData->product_amount;
        $productAmt = $getProdData->product_amount;
        $amtType = $getProdData->amount_type;
        $comm_share_type = $getAgentdata->comm_share_type; // share type percent or fix value from product comm table
        $agt_comm = $getAgentdata->commission_agent; // Agent Share


        /**check for amount type */
        if ($amtType == 'V') {

            if ($p_amt >= $productAmt) {
                $makeTxn = 1;
            } else {
                $makeTxn = 0;
            }
        } else if ($amtType == 'F') {
            if ($p_amt == $productAmt) {
                $makeTxn = 1;
            } else {
                $makeTxn = 0;
            }
        }

        if ($makeTxn == 1) {
            /****final deduct amount :) round of value up to 3 digit */
            $agentCOmmRof = $txn_amount-$finalDeduct;
            $walletDeduction = $finalDeduct;
            /***check for agent wallet balance */
            $checkWalletBalance = $wpdb->get_var("SELECT balance_amount from grp_agents_wallet where agent_id='$agent_id'");
            if ($checkWalletBalance < $walletDeduction) {
                $response = array("status" => 0, "msg" => "Error:Insufficient wallet balance");
                return $response;
            } else {
                    /***insert all data in transactions table */
                    $insertTransaction = "INSERT into grp_agents_transaction set agent_id='$agent_id', agent_code='$agent_code', txn_type='dr', product_id='$product_id', txn_amount='$walletDeduction',product_mrp='$txn_amount', before_payment='$checkWalletBalance', reference_id='$user_id',  deduct_amount='$walletDeduction', agent_share_type='$comm_share_type', agent_share_val='$agt_comm', agent_share_amt='$agentCOmmRof',txn_date='$date'";
                    if ($wpdb->query($insertTransaction)) {
                        /***generated txn id */
                        $txn_id = $wpdb->insert_id;

                        /***wallet balance after deduction */
                        $afterPayment = ($checkWalletBalance - $walletDeduction);

                        /***update the deduct amount from wallet */
                        $updateWalletBal = "UPDATE grp_agents_wallet set balance_amount='$afterPayment', last_txn_date='$date' where agent_id='$agent_id'";
                        if ($wpdb->query($updateWalletBal)) {
                            if ($txn_id != '') {
                                /***update the transaction after payment */
                                $updateAfterPayment = $wpdb->query("UPDATE grp_agents_transaction set after_payment='$afterPayment' where txn_id='$txn_id'");

                                /***create response array for merchant in success case */
                                $response = array("status" => 1, "msg" => "Payment Response:Success,You will redirect to merchant site","txn_id"=>$txn_id);

                                // transactionSentMail($email, $name, $deductAmt,'success');
                            }
                        }
                    } else {
                        $response = array("status" => 2, "msg" => "Payment Response:Failed,You will redirect to merchant site");

                        // transactionSentMail($email, $name, $deductAmt,'failed');
                    }
                
                return $response;
            }
        } else {
            $response = array("status" => 0, "msg" => "Error:something went wrong with amount value");
            return $response;
        }
    } else {
        $response = array("status" => 0, "msg" => "Error:Credentials not set properly");
        return $response;
    }
}

function createUser($data) {

    $url = "https://shineolympiad.com/wp-content/plugins/tet-india/vendorapi/user_creation_gepl.php";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    $outPutArr = json_decode($output);
    return $outPutArr;

}