<?php include ("../serive/samparka.php");?>
<?php 
if(isset($_GET['amount'])){
	$ramt = htmlspecialchars(mysqli_real_escape_string($conn, $_GET['amount']));
} else{
	$ramt = 0;
}
$dot_pos = strpos($ramt, '.');
if ($dot_pos === false) {
    $ramt = $ramt . '.00';
}else {
    $after_dot = substr($ramt, $dot_pos + 1);
    $after_dot_length = strlen($after_dot);
    if ($after_dot_length > 2) {
        $after_dot = substr($after_dot, 0, 2);
        $ramt = substr($ramt, 0, $dot_pos + 1) . $after_dot;
    } elseif ($after_dot_length < 2) {
        $zeros_to_add = 2 - $after_dot_length;
        $ramt = $ramt . str_repeat('0', $zeros_to_add);
    }
}
$date = date("Ymd");
$time = time();
$serial = 'P' . $date . $time . rand(1000,9999);

$tyid = htmlspecialchars(mysqli_real_escape_string($conn, $_GET['tyid']));
$uid = htmlspecialchars(mysqli_real_escape_string($conn, $_GET['uid']));
$sign = htmlspecialchars(mysqli_real_escape_string($conn, $_GET['sign']));
$urlInfo = htmlspecialchars(mysqli_real_escape_string($conn, $_GET['urlInfo']));
?>
<?php 
	$s_upi = "SELECT maulya FROM deyyamrici WHERE sthiti='1'";
	$r_upi = mysqli_query($conn, $s_upi);
	$f_upi = mysqli_fetch_array($r_upi);
	$upi_id = $f_upi['maulya'];
	
	$selectupi_two=mysqli_query($conn,"select * from `images_usdt` where `status`=1");
	$selectupiresult_two=mysqli_fetch_array($selectupi_two);
?>
<?php
	$res = [
		'code' => 405,
		'message' => 'Illegal access!',
	];
	if (isset($_GET['tyid']) && isset($_GET['amount']) && isset($_GET['uid']) && isset($_GET['sign']) && isset($_GET['urlInfo'])) {
		$userId = $uid;
		$userPhoto = '1';
		
		$numquery = "SELECT mobile, codechorkamukala
		  FROM shonu_subjects
		  WHERE id = ".$userId;
		$numresult = $conn->query($numquery);
		$numarr = mysqli_fetch_array($numresult);
		
		$userName = '91'.$numarr['mobile'];
		$nickName = $numarr['codechorkamukala'];
		
		$creaquery = "SELECT createdate
		  FROM shonu_subjects
		  WHERE id = ".$userId;
		$crearesult = $conn->query($creaquery);
		$creaarr = mysqli_fetch_array($crearesult);
		
		$knbdstr = '{"userId":'.$userId.',"userPhoto":"'.$userPhoto.'","userName":'.$userName.',"nickName":"'.$nickName.'","createdate":"'.$creaarr['createdate'].'"}';
		$shonusign = strtoupper(hash('sha256', $knbdstr));
		
		$urlarr = explode (",", $urlInfo);
		$theirurl = $urlarr[0];
		$myurl = 'https://bdgwinbet.site';
		
		if($myurl){
?>
			<html class="pixel-ratio-2 retina ios ios-13 ios-13-2-3 ios-gt-12 ios-gt-11 ios-gt-10 ios-gt-9 ios-gt-8 ios-gt-7 ios-gt-6">
				<head>
					<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
					<title>
						USDT Checkout
					</title>
					<meta content="width=device-width,initial-scale=1,user-scalable=0" name="viewport">
					<link rel="icon" href="/favicon.ico">
					<link href="assets/css/wepay/weui2.min.css" rel="stylesheet">
					<link href="assets/css/wepay/weuix.min.css" rel="stylesheet">
					<script src="assets/js/wepay/jquery-2.2.4.min.js"></script>
					<style type="text/css" id="operaUserStyle"></style>
					<script src="assets/js/wepay/clipboard.min.js"></script>
					<script src="assets/js/wepay/layer.js"></script>
					<link rel="stylesheet" href="assets/css/wepay/layer.css" id="layuicss-layer">
				<!-- Modern UI for USDT Payment -->
<style>
    body {
        font-family: 'Poppins', sans-serif;
        background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
        color: #fff;
        margin: 0;
        padding: 0;
    }

    .payment-container {
        max-width: 450px;
        margin: 60px auto;
        background: rgba(255, 255, 255, 0.08);
        border-radius: 20px;
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        padding: 30px;
        text-align: center;
    }

    .payment-container img {
        width: 80px;
        margin-bottom: 10px;
    }

    h2 {
        font-weight: 600;
        margin-bottom: 20px;
        color: #00e0ff;
    }

    .amount-box {
        font-size: 24px;
        font-weight: bold;
        margin: 15px 0;
        color: #16ffbd;
    }

    .address-box {
        background: rgba(0, 0, 0, 0.4);
        border: 1px solid #00e0ff;
        border-radius: 8px;
        padding: 10px;
        margin-top: 20px;
        word-wrap: break-word;
        font-family: monospace;
    }

    .copy-btn {
        background-color: #00e0ff;
        border: none;
        color: #000;
        padding: 10px 20px;
        margin-top: 10px;
        font-weight: 600;
        border-radius: 6px;
        cursor: pointer;
        transition: all 0.3s;
    }

    .copy-btn:hover {
        background-color: #16ffbd;
    }

    .input-box {
        margin-top: 25px;
    }

    .input-box input {
        width: 100%;
        padding: 12px;
        border-radius: 8px;
        border: 2px solid #00e0ff;
        outline: none;
        background: transparent;
        color: #fff;
        text-align: center;
        font-size: 16px;
    }

    .submit-btn {
        width: 100%;
        margin-top: 25px;
        padding: 12px;
        background: linear-gradient(90deg, #00e0ff, #16ffbd);
        border: none;
        color: #000;
        font-weight: bold;
        border-radius: 8px;
        cursor: pointer;
        transition: all 0.3s;
    }

    .submit-btn:hover {
        transform: scale(1.05);
    }

    .tip {
        font-size: 13px;
        margin-top: 20px;
        color: #ccc;
        line-height: 1.4em;
    }

    .tip span {
        color: #00e0ff;
        font-weight: bold;
    }
    
     .qr01 {
        display: flex;
        justify-content: center;
        align-items: center;
        margin: 20px 0;
    }

    .qr01 img {
        width: 180px;
        height: 180px;
        border-radius: 16px;
        border: 3px solid #00e0ff;
        padding: 8px;
        background: rgba(0, 0, 0, 0.3);
        box-shadow: 0 0 20px rgba(0, 224, 255, 0.3);
        transition: transform 0.3s ease;
    }

    .qr01 img:hover {
        transform: scale(1.05);
    }
    
    }
    
</style>

<div class="payment-container">
    <img src="../assets/png/usdt-40311708.png" alt="USDT Logo">
    <h2>USDT Payment</h2>

    <div class="amount-box">
        💰 Amount: <span><?php echo $ramt; ?> USDT</span>
    </div>

<div class = "qr01">
     <img src="https://bluewin.sbs/images_usdt/uuuuuu.png" alt="address">
</div>

    <div class="address-box" id="upi">
        <?php echo $upi_id; ?>
    </div>

    <button class="copy-btn" id="btncopy">Copy Wallet Address</button>

    <div class="input-box">
        <input type="text" id="refno" placeholder="Enter Transaction / Ref No">
    </div>

    <button class="submit-btn" id="savebtn">Submit Payment</button>

    <div class="tip">
        ⚠️ Send only <span>USDT-TRC20</span> to this address.  
        Your funds will reflect within <span>10 minutes</span>.
    </div>
</div>

				

<script>
// Add the 'vibrating' class to make the box vibrate
document.getElementById('refno').classList.add('vibrating');
</script>


					<script type="text/javascript">
					  
					  var ifscCopyBoard = new ClipboardJS("#ifscCopy", {
						  text: function() {
							  var e = $("#ifsc").html();
							  return e
						  }
					  });
					  ifscCopyBoard.on("success", function() {
						  layer.msg("ifsc copied successfully")
					  });
					  ifscCopyBoard.on("error", function() {
						  layer.msg("ifsc failed, Please input manually")
					  });


					  var accNameCopy = new ClipboardJS("#accNameCopy", {
						  text: function() {
							  var e = $("#accName").html();
							  return e
						  }
					  });
					  accNameCopy.on("success", function() {
						  layer.msg("acc name copied successfully")
					  });
					  accNameCopy.on("error", function() {
						  layer.msg("acc name failed, Please input manually")
					  });

					function process() {
						$.post(base_url + "/cashier/v1/IN_UPI/" + order_no,
							function(e) {
								if (e.code == -1){
									window.location.href = base_url + "/cashier/v1/IN_UPI/fail/" + order_no;
									return;
								}
								if (e.data.success != null && e.data.success){
									window.location.href = success_url+order_no;
									return;
								}
								if (100 === e.code) {
									if (100 === parseInt(status)) return;
									status = parseInt(e.code),
										pa = e.data.upi.pa,
										cu = e.data.upi.cu,
										mc = e.data.upi.mc,
										tn = e.data.upi.tn,
										tr = e.data.upi.tr,
										am = e.data.upi.am,
										pn = e.data.upi.am,
										tno = e.data.order_no,
										$(".moeny").html(am),
										$(".order_no").html(tno),
										$("#upi").html(pa)
								} else - 1 === e.code ? alert(e.msg) : 200 === e.code ? alert(e.msg) : 40006 === e.code && alert(e.msg)
							})
					}
					function getQueryString(e) {
						var url = window.location.href;
						var index = url.lastIndexOf("/");
						return url.substring(index + 1, url.length);
					}
					var pa = "",
						cu = "",
						mc = "",
						tn = "",
						tr = "",
						am = "",
						pn = "",
						order_no = null,
						tno = null,
						status = -1,
						base_url = '';
						success_url = "success/",
					order_no = getQueryString("no"),
						null === order_no || "" === order_no ? alert("Please replace your order.") : process(),
						layer.alert("<span style='word-break:break-word;'>After the payment is successful, you must coming back here to submit the Ref No. Only then your money be reached to the account.</span>", {
							title: "Cashier",
							icon: 0,
							btn: ["OK"]
						});
					</script>
					<div class="layui-layer-shade" id="layui-layer-shade1" times="1" style="z-index: 19891014; background-color: rgb(0, 0, 0); opacity: 0.3;">
					</div>
					<div class="layui-layer layui-layer-dialog" id="layui-layer1" type="dialog" times="1" showtime="0" contype="string" style="z-index: 19891015; width: 360px; top: 282px; left: 334px; display:none;">
						<div class="layui-layer-title" style="cursor: move;">Cashier</div>
						<div id="" class="layui-layer-content layui-layer-padding">
							<i class="layui-layer-ico layui-layer-ico0"></i>
							<span style="word-break:break-word;">After the payment is successful, you must coming back here to submit the Ref No. 
							Only then your money be reached to the account.</span>
						</div>
						<span class="layui-layer-setwin">
							<a class="layui-layer-ico layui-layer-close layui-layer-close1" href="javascript:;"></a>
						</span>
						<div class="layui-layer-btn layui-layer-btn-">
							<a class="layui-layer-btn0">OK</a>
						</div>
						<span class="layui-layer-resize"></span>
					</div>
					<div class="layui-layer-move"></div>
					<script>
						var ramt = <?php echo $ramt; ?>;
						var serial = '<?php echo $serial; ?>';
						var upi = document.getElementById("upi").innerHTML;
						
						var userId = <?php echo $userId; ?>;
						var token = '<?php echo $shonusign; ?>';
					
						var copyAmount = new ClipboardJS("#copyAmount", {
						  text: function() {
							  var e = am;
							  return e
						  }
						});
						copyAmount.on("success",
						function() {
						  layer.msg("amount copied successfully")
						});

						var clipboard = new ClipboardJS("#btncopy", {
							text: function() {
								var e = $("#upi").html();
								return e
							}
						});
						clipboard.on("success",
							function() {
								layer.msg("UPI copied successfully")
							}),
							clipboard.on("error",
								function() {
									layer.msg("UPI copied failed, Please input manually")
								}),
							$(function() {
								$('#refno').bind('input propertychange', function() {
								   var v =  $("#refno").val();
								   /*if (v.length >= 12){
									   $("#savebtn").click();
								   }*/
								});

								$("#savebtn").on("click",
									function() {
										var e = $("#refno").val();
										var refNo = e;
										return void layer.confirm("<span style='word-break:break-word'><span style='color:#f80'>For your money security, please confirm the following information carefully</span><br><br>USDT ADDRESS : <code style='color:#487ef5'>" + upi + "</code><br>Transfer amount : <code style='color:#487ef5'>" + ramt + "</code><br>Ref No : <code style='color:#487ef5'>" + refNo + "</code></span>", {
												title: "Security",
												btn: ["Confirm", "Cancel"]
											},
											function() {
												layer.closeAll();									
												adddep(ramt,refNo,serial,upi,userId,token);
											},
											function() {})
									})

								 $("#open-video").click(function (){

									//

									layer.load();
									 $(".video-shadow").css({'display':'block'});
									 $('.addBox').show();
									$("#videoFrame").fadeIn(500);
									document.getElementById("video1").src = "https://objects.bzpay.cc/demo/payment_demo_low.mp4"
									document.getElementById("video1").load();
									$("#video1")[0].play();
									layer.closeAll();
								});

								$("#close-video").click(function (){
									$("#video1")[0].pause();
									$("#videoFrame").fadeOut(500);
									$(".video-shadow").css({'display':'none'});
									$('.addBox').hide();
									layer.closeAll();
								});
							});

						function handelResp(e){
							0 == e.code ? 0 == e.data.type ? layer.alert(e.msg, {
								title: "Congratulations",
								icon: 6,
								btn: ["OK"]
							},
							function() {
								window.location.href = e.data.redirectUrl
							}) : 1 == e.data.type ? layer.alert(e.msg, {
								title: "Sorry",
								icon: 5,
								btn: ["OK"]
							},
							function() {
								window.location.href = e.data.redirectUrl
							}) : 2 == e.data.type ? layer.alert("<span style='word-break:break-word'>" + e.msg + "</span>", {
								title: "Cashier",
								icon: 6,
								btn: ["OK"]
							},
							function() {
								window.location.href = e.data.redirectUrl
							}) : window.location.href = e.data.redirectUrl: layer.alert(e.msg, {
							title: "Sorry",
							icon: 5,
							btn: ["OK"]
							})
						}


						function showLoading(){
							$(".loading2").show();
						}
						function closeLoading(){
							$(".loading2").hide();
						}
						
						function depconfirm(refnum){
							window.location.href = 'usdtconfim.php?amt=' + ramt + '&refnum=' + refnum + '&srl=' + serial+ "&userId=" + userId+ "&token=" + token;
						}
						
						function adddep(amt,refnum,srl,upi,userId,token)
						{
							$.ajax({
							type: "Post",
							data:"amt=" + amt+ "& refnum=" + refnum+ "& srl=" + srl+ "& source=" + "usdt"+ "& upi=" + upi+ "& userId=" + userId+ "& token=" + token,
							url: "adddeposit.php",
							success: function(html)   
								{
									var arr = html.split('~');
									
									if (arr[0]== 1) {
										showLoading();
										setTimeout(depconfirm, 1900, refnum);
									}	
									else if(arr[0]==0)
									{ 
										alert("Error");
									}
									else if(arr[0]==2)
									{ 
										alert("Duplicate UTR");
									}
									else if(arr[0]==3)
									{ 
										alert("Please Wait For 1 Minute");
									}
									else if(arr[0]==4)
									{ 
										alert("Your recharge option is suspended" + "\n" + "Contact Customer Support");
									}
								},
								  error: function (e) {}
							});				
						}
					</script>
				</body>
			</html>
<?php
		}
		else{
			$res['code'] = 10000;
			$res['success'] = 'false';
			$res['message'] = 'Sorry, The system is busy, please try again later!';
			
			header('Content-Type: text/html; charset=utf-8');
			http_response_code(200);
			echo json_encode($res);	
		}
	}
	else{
		header('Content-Type: application/json; charset=utf-8');
		http_response_code(200);
		echo json_encode($res);	
	}
?>

