<?php



// ===================================
//  Costomize : RAJNI WEB DEVELOPER =====
//  Date   : 23/12/2023 ==============
//  Version : 1.0.2 ==================
//  About  : Paid Payment Gatway =====
//  Insta  : rajni.kant.mahato =======
//  Telegram : Simplehacker1 =========
//  whatsapp : 919771241425 ==========
// ====================================


// LICENCE UDYAM-JH-06-0039636
// ENTERPRISE RAJNI WEB DEVELOPER
// Copyright (c) 2022 - 2023 The SM02

// Permission is hereby granted, free of charge, to any person or MSME (Micro, Small, and Medium Enterprises) obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software with permission from the author, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons or MSMEs to whom the Software is
// furnished to do so, subject to the following conditions:

// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.

// Usage without explicit permission from the author is strictly prohibited.
// If you have any inquiries or need permission, please contact the author.

// THE SOFTWARE IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES, OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.

// If you have any problems, please contact the author.


include("conn.php");
error_reporting(0);

require_once('checksum.php');

$verifySignature = '';
$array = array();
$paramList = array();

$secret = 'AnEnXHu0Bq'; // Your Secret Key.
$status = $_POST['status']; // Payment Status Only, Not Txn Status.
$message = $_POST['message']; // Txn Message.
$cust_Mobile = $_POST['cust_Mobile']; // Txn Message.
$cust_Email = $_POST['cust_Email']; // Txn Message.
$hash = $_POST['hash']; // Encrypted Hash / Generated Only SUCCESS Status.
$checksum = $_POST['checksum']; // Checksum verifySignature / Generated Only SUCCESS Status.

// Payment Status.
if ($status == "SUCCESS") {
    $paramList = hash_decrypt($hash, $secret);
    $verifySignature = RechPayChecksum::verifySignature($paramList, $secret, $checksum);

    // Checksum verify.
    if ($verifySignature) {
        $array = json_decode($paramList);

        // Store the payment response in variables
        $paymentStatus = $status;
        $paymentMessage = $message;
        $paymentHash = $hash;
        $paymentChecksum = $checksum;
        $customerMobile = $cust_Mobile;      // Customer mobile SAVE
        $customerEmail = $cust_Email;        // Customer email SAVE
        $senderNote = $array->sender_note;   // Store the sender note
        $amount = $array->txnAmount;         // Store the transaction amount
        $utr = $array->orderId;          // Store the orderId
        $txnStatus = $array->txnStatus;      // Store the transaction status
        $resultInfo = $array->resultInfo;    // Store the result information
        $txnId = $array->txnId;              // Store the transaction ID
        $bankTxnId = $array->bankTxnId;      // Store the bank transaction ID
        $paymentMode = $array->paymentMode;  // Store the payment mode
        $txnDate = $array->txnDate;          // Store the transaction date
        // $utr = $array->utr;                  // Store the UTR
        $senderVpa = $array->sender_vpa;     // Store the sender VPA
        $payeeVpa = $array->payee_vpa;       // Store the payee VPA

    
        
        $username = $senderNote;

        
        $opt="SELECT COUNT(*) as total FROM `recharge` WHERE username='$username' AND status='Success'";
        $optres=$conn->query($opt);
        $sum= mysqli_fetch_assoc($optres);
        if($sum['total']=="" or $sum['total']<=2){
           
                  if($sum['total']==1 && $amount ==500){
                      
                        $bonus=250
                        ;
                      }elseif($sum['total']==2 && $amount >=1000){
                          $bonus=200;
                      }else{
                          
                          $percent = 10;
                          $bonus = ($amount * $percent) / 100;
                        //   $bonus/=20;
                      }
                    
                  
                    $win="select refcode FROM `users` WHERE  username='$username' ";
                    $result3 =$conn->query($win);
                    $row3 = mysqli_fetch_assoc($result3);
                    $refcode=$row3['refcode'];
                    $adb="UPDATE users SET bonus= bonus +$bonus WHERE usercode='$refcode'";
                    $conn->query($adb);
                     $transquery="INSERT INTO trans (username,reason,amount) VALUES ('$refcode' ,'CheckIn Bonus',$bonus)";
                    	$conn->query($transquery);
                    $addbrec="INSERT INTO bonus (giver,usercode,amount,level) VALUES ('$username','$refcode','$bonus','1')";
                    $conn->query($addbrec);
            
        }
        
        $addwin00="UPDATE recharge SET status='Success' WHERE username='$username' AND recharge='$amount' AND utr='$utr'";
        $conn->query($addwin00);
         $transquery="INSERT INTO trans (username,reason,amount) VALUES ('$username', 'Recharge',$amount)";
        	$conn->query($transquery);
        
        if($conn->query($addwin00)){
            
            
            $addwin0="UPDATE users SET balance= balance +($amount) WHERE username='$username'";
           
            if($conn->query($addwin0)){
               
                header("location: https://mxwin.in/#/rechargerecord");
            }
        }else{
            // echo"FAILED";
            
            
                
            header("location: https://mxwin.in/#/rechargerecord");
        }
    } else {
        // Payment Response
        header("Location: https://mxwin.in/#/rechargerecord");
        exit; // Make sure to exit after redirection
    }
} else {
    // Payment Response
    header("Location: https://mxwin.in/#/rechargerecord");
    exit; // Make sure to exit after redirection
}
?>
