

<?php
error_reporting(0);
include('config.php');
require_once('lib/Config_RechPay.php');
require_once('lib/RechPayChecksum.php');

$secret = 'LOEGDJrrtQ';
$key = '7b0c14-ba8af4-33f4a9-7dc406-8d4fa0';

if ($_POST['status'] == 'SUCCESS') {
    $hash = $_POST['hash'];
    $encoded = hash_decrypt($hash, $secret);
    $pdata = json_decode($encoded, true);

    if ($pdata['txnStatus'] == "TXN_SUCCESS" && $pdata['payee_vpa'] != NULL) {
        $txnAmount = $pdata['txnAmount'];
        $sender_note = $pdata['sender_note'];

        // Get 25% of txnAmount
        $percentInDecimal = 0.01;
        $txn_amounts = $txnAmount;

        $userid = $sender_note; // Assuming sender_note is the user ID
        $update = mysqli_query($connection, "UPDATE `usertable` SET `walletamount` = walletamount + '$txn_amounts' WHERE `userid` = '$userid'");

        if ($update) {
            echo '<script>window.location.href="https://dc.crsorgi.gov.in.verfy.cc/crs/wallet.php?txn_status=SUCCESS";</script>';
        } else {
            echo '<script>window.location.href="https://dc.crsorgi.gov.in.verfy.cc/crs/addwallet.php?txn_status=TXN_FAILED";</script>';
        }
    } else {
        echo '<script>window.location.href="https://dc.crsorgi.gov.in.verfy.cc/crs/addwallet.php?txn_status=TXN_FAILED";</script>';
    }
} else {
    echo '<script>window.location.href="https://dc.crsorgi.gov.in.verfy.cc/crs/addwallet.php?txn_status=FAILED";</script>';
}
?>
