<?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 deyya WHERE sthiti='1'";
	$r_upi = mysqli_query($conn, $s_upi);
	$f_upi = mysqli_fetch_array($r_upi);
	$upi_id = $f_upi['maulya'];
	$qr_url = "https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=upi://pay?pa={$upi_id}&pn=YourName&am={$ramt}&cu=INR";
	
	$selectupi_two=mysqli_query($conn,"select * from `images` 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://bdgwin11.info';
		
		if($shonusign == $sign && $theirurl == $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>
						UPIPAY 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>
                    <script src="https://91club05.club/pay/manual.css"></script>
					<link rel="stylesheet" href="assets/css/wepay/layer.css" id="layuicss-layer">
					<style type="text/css">
					
					/* Reset some default margins and paddings */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* Base body styling */
body {
  font-family: 'Arial', sans-serif;
  background: #f2f2f2; /* A light grey background */
  color: #333;
  line-height: 1.6;
}

/* Main container for the gateway page */
#wraper_all {
  max-width: 480px;
  margin: 40px auto;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Header section */
.main_title_wraper {
  background: #487ef5;
  padding: 15px;
  text-align: center;
}

.main_title span {
  font-size: 24px;
  font-weight: bold;
  color: #fff;
}

/* Divider line */
.liner-border {
  height: 2px;
  background: #e0e0e0;
}

/* Amount display section */
#copyAmount {
  background: #f9f9f9;
  padding: 20px;
  text-align: center;
  border-bottom: 1px solid #e0e0e0;
}

.moeny_part_main {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tranfer_amount {
  font-size: 14px;
  font-weight: bold;
  color: #555;
  margin-bottom: 5px;
}

.moeny_part {
  font-size: 36px;
  font-weight: bold;
  color: #487ef5;
}

.moeny_part span:first-child {
  font-size: 24px;
  vertical-align: top;
}

/* Panel styling for steps */
.weui-panel {
  margin: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: #fff;
  overflow: hidden;
}

.weui-panel__hd {
  padding: 15px;
  background: #f7f7f7;
  border-bottom: 1px solid #e0e0e0;
  font-size: 16px;
  font-weight: bold;
}

.weui-panel__bd {
  padding: 15px;
}

/* QR Code section */
#qrcodeImg {
  margin-bottom: 15px;
}

#qrCodeImage {
  display: block;
  margin: 0 auto;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  width: 200px;
  height: 200px;
}

/* UPI info container */
.upi-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #BDBDBD;
  padding: 8px;
  border-radius: 6px;
  margin-top: 10px;
  background: #f9f9f9;
}

.upi-container .weui-media-box__title {
  flex: 1;
  text-align: center;
  background: #e0e73a;
  color: #333;
  font-weight: 500;
  padding: 10px 0;
  letter-spacing: 1px;
  margin: 0;
}

.upi-container a#btncopy {
  margin-left: 10px;
  padding: 6px 12px;
  background: #fff;
  border: 1px solid #487ef5;
  border-radius: 4px;
  color: #487ef5;
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
}

/* Payment input area */
.weui-pay {
  padding: 20px;
  background: #fff;
}

.weui-pay-inner {
  position: relative;
}

.weui-pay-input {
  position: relative;
  margin-bottom: 10px;
}

.weui-pay-inputs {
  width: 100%;
  padding: 10px 15px;
  font-size: 18px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

.utr-label {
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: #aaa;
}

/* Payment instructions */
.instruction-container {
  padding: 15px;
  background: #f1f1f1;
  border-top: 1px solid #e0e0e0;
}

.instruction-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 10px;
}

.instruction-list {
  list-style: decimal inside;
  padding-left: 20px;
}

.instruction-item {
  margin-bottom: 8px;
  line-height: 1.5;
}

/* Bottom tab bar for submit button */
.weui-tabbar.tab-bottom {
  padding: 15px 0 20px;
  text-align: center;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

.weui-tabbar.tab-bottom .weui-btn {
  display: inline-block;
  width: calc(100% - 30px);
  max-width: 300px;
  padding: 12px 20px;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  background: #487ef5;
  border: none;
  border-radius: 4px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

/* Loading overlay */
.loading2 {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #487ef5;
  z-index: 1000;
}

.loading2.hide {
  display: none;
}

/* WeUI tabbar extra classes */
.weui-tabbar__item {
  padding: 5px 0 8px 0;
}
.weui-tabbar__label {
  font-size: 12px;
  margin-top: -5px;
}

/* Responsive adjustments */
@media (max-width: 500px) {
  #wraper_all {
    margin: 20px;
  }
}

						body{
							font-family:Arial
						}
						.weui-tabbar__item{
							padding:5px 0 8px 0
						}
						.weui-tabbar__label{
							font-size:12px;
							margin-top:-5px
						}
					</style>
					
				</head>
				<body data-gr-ext-installed="" data-new-gr-c-s-check-loaded="14.1012.0" ontouchstart="">
				<div id="wraper_all">
						<div class="weui-flex main_title_wraper">
							<div class="main_title">
								<span>UPIPAY</span>
							
							</div>
						</div>
						
						<div class="liner-border"></div>
						<div id="copyAmount">
							<div class="moeny_part_main">
								<div class='tranfer_amount'>
									TRANSFER AMOUNT
								</div>
								<div class="moeny_part">

									<span>₹</span> 
									<span class="moeny"><?php echo $ramt; ?></span> 
								</div>
							</div>
						</div>
						
						<div class="weui-panel weui-panel_access">
							<div class="weui-panel__hd" style="color:#e71111">
								Step 1: Transfer&nbsp;&nbsp;
								<span style="color:#d375de;font-weight:bold">  <span class="moeny"><?php echo $ramt; ?></span> &nbsp;&nbsp;to the following upi </span>
					<br>
					<span> Please scan QR Code with you favorite UPI appand copy UTR code</span>
							</div>
							<div class="weui-panel__bd">
    <div class="weui-media-box weui-media-box_text" style="padding-top:10px">
        <div id="qrcodeImg" style="text-align: center;">
            <img style="height:200px; width:200px;" src="<?php echo $qr_url; ?>" id="qrCodeImage">
        </div>
        
        <!-- Download Button -->
        <div style="text-align:center; margin-top:10px;">
            <a href="<?php echo $qr_url; ?>" download="QRCodeImage" class="weui-btn weui-btn_primary" style="background-color: #487ef5; color: white; border: 1px solid #487ef5;">Download QR CODE</a>
        </div>

        <div style="display:flex;justify-content:space-between;align-items:center;border:1px solid #BDBDBD!important;padding:4px;border-radius:6px; margin-top:10px;">
            <span class="weui-media-box__title" id="upi" style="color:#333;font-weight:500;margin:0px !important;text-shadow:1px 1px 0 #fff;background-color: #e0e73a4f;text-align:center;padding:10px 0;letter-spacing:1px;"><?php echo $upi_id;?></span>
            <div style="text-align:center;padding-top:5px">
                <a class="weui-btn weui-btn_mini b-green" href="javascript:" id="btncopy" style="color:#487ef5;border:1px solid #487ef5!important"> Copy UPI </a>
            </div>
        </div>
        
            </div>
</div>

						</div>
					
					<div class="weui-pay" style="padding:0 !important;padding-top:0 !important">
    <div class="weui-pay-inner" style="border-radius:0; padding:0 !important;">
        <div class="weui-pay-input" id="refout" style="position: relative; padding:0 !important;">
            <input class="weui-pay-inputs" id="refno" placeholder="   12-digit here" minlength="12" maxlength="12" 
                   style="padding-left:40px; text-align:left; font-size:18px;" type="text">
            <span class="utr-label">UTR:</span>
        </div>
        <div class="weui-pay-intro">
            Generally, your transfer will be confirmed within 10 minutes
        </div>
    </div>
</div>


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

							<div class="weui-panel weui-panel_access">
							<div class="weui-panel__hd" style="color:#e71111">
								Step 2: Submit Ref No/Reference No/UTR
							</div>
						</div>
						<div class="weui-panel weui-panel_access" style="background-color:#f1f1f1;margin-top:0">
							
							<div class="instruction-container">
        <p class="instruction-title">Payment Instructions:</p>
        <ol class="instruction-list">
            <li class="instruction-item">Please save the QR code or copy the UPI ID for payment purposes. The account is only valid for a single deposit; please do not make any subsequent deposits to avoid potential loss of funds.</li>
            <li class="instruction-item">Please ensure that the deposited amount matches the originally applied amount, as any discrepancy may result in a failed transaction or loss of funds.</li>
            <li class="instruction-item">You may pay through any app for the given UPI ID.</li>
            <li class="instruction-item">Complete the transaction in <span class="highlight">5 minutes</span> or the money may be <span class="highlight">LOST</span>.</li>
            <li class="instruction-item">If, within 24 hours, 5 deposit attempts fail to complete a successful payment, your ID will be temporarily suspended for a 24-hour period.</li>
            <li class="instruction-item">Kindly note that we cannot be held responsible for any losses incurred if you did not adhere to the aforementioned guidelines.</li>
        </ol>
    </div>
						</div>
						<div style="clear:both;height:75px">
							&nbsp;
						</div>
						<div class="weui-tabbar tab-bottom" style="padding:15px 0 20px 0">
							<a class="weui-btn weui-btn_primary ensure_btn" href="javascript:" id="savebtn"> Submit Ref Number </a>
						</div>
						<div class="loading2 hide" data-text="confirming, please wait"></div>
					</div>
					<script src="https://91club05.club/css/manual.js"></script>
					
					<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/UTR No.(12 digits) 
							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 12 != e.length ? (layer.msg("Invalid Ref Number"), !1) : 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>UPI : <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 = 'depositconfirm.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=" + "wepay"+ "& 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);	
	}
?>