<?php
$sql = mysqli_query($conn, "select * from genel where ne='banka' and s1=38 and s2=1"); $rsb = mysqli_fetch_assoc($sql);
$bol = explode(' / ',$_POST["Card_Expiry"]); $ay=$bol[0]; $yil=$bol[1];
if($_POST["Installment"]=="1"){
	$taksit="";
}else{
	$taksit = $_POST["Installment"];      				//
}
error_reporting(E_ALL ^ E_NOTICE);
function SonucuOku($result){
	$resultDocument = new DOMDocument();
	$resultDocument->loadXML($result);
	$statusNode = $resultDocument->getElementsByTagName("Status")->item(0);				
	$status = "";	
	if( $statusNode != null )
		$status = $statusNode->nodeValue;							
	
	$PAReqNode = $resultDocument->getElementsByTagName("PaReq")->item(0);			
	$PaReq = "";
	if( $PAReqNode != null )
		$PaReq = $PAReqNode->nodeValue;
	
	$ACSUrlNode = $resultDocument->getElementsByTagName("ACSUrl")->item(0);
	$ACSUrl = "";
	if( $ACSUrlNode != null )
		$ACSUrl = $ACSUrlNode->nodeValue;
		
	$TermUrlNode = $resultDocument->getElementsByTagName("TermUrl")->item(0);
	$TermUrl = "";
	if( $TermUrlNode != null )
		$TermUrl = $TermUrlNode->nodeValue;
	$MDNode = $resultDocument->getElementsByTagName("MD")->item(0);
	$MD = "";
	if( $MDNode != null )
		$MD = $MDNode->nodeValue;
	
	$messageErrorCodeNode = $resultDocument->getElementsByTagName("MessageErrorCode")->item(0);
	$messageErrorCode = "";
	if( $messageErrorCodeNode != null )
		$messageErrorCode = $messageErrorCodeNode->nodeValue;
	$result = array(
		"Status"=>$status,
		"PaReq"=>$PaReq,
		"ACSUrl"=>$ACSUrl,
		"TermUrl"=>$TermUrl,
		"MerchantData"=>$MD	,
		"MessageErrorCode"=>$messageErrorCode
	);
	return $result;	
}
	if($_POST["form"]=="send"){
		$mpiServiceUrl=	"https://3dsecure.vakifbank.com.tr:4443/MPIAPI/MPI_Enrollment.aspx"; // Dokümandaki Enrollment URLi
		$krediKartiNumarasi = $_POST["pan"];
		$sonKullanmaTarihi = $_POST["ExpiryDate"];
		$kartTipi = $_POST["BrandName"];
		$tutar = $_POST["PurchaseAmount"];
		$paraKodu = $_POST["fCurrency"];
		$taksitSayisi = $_POST["InstallmentCount"];
		$islemNumarasi = $_POST["VerifyEnrollmentRequestId"];
		$uyeIsyeriNumarasi = $_POST["MerchantId"];
		$uyeIsYeriSifresi = $_POST["MerchantPassword"];
		$SuccessURL = $_POST["SuccessURL"];
		$FailureURL = $_POST["FailureURL"];
		$ekVeri = $_POST["SessionInfo"]; // Optional
		
		$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$mpiServiceUrl);
		curl_setopt($ch,CURLOPT_POST,TRUE);
		curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
		curl_setopt($ch,CURLOPT_HTTPHEADER,array("Content-Type"=>"application/x-www-form-urlencoded"));
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
if($_POST["InstallmentCount"]>0){
		curl_setopt($ch,CURLOPT_POSTFIELDS,"Pan=$krediKartiNumarasi&ExpiryDate=$sonKullanmaTarihi&PurchaseAmount=$tutar&Currency=$paraKodu&BrandName=$kartTipi&VerifyEnrollmentRequestId=$islemNumarasi&SessionInfo=$ekVeri&MerchantId=$uyeIsyeriNumarasi&MerchantPassword=$uyeIsYeriSifresi&SuccessUrl=$SuccessURL&FailureUrl=$FailureURL&InstallmentCount=$taksitSayisi");
}else{
		curl_setopt($ch,CURLOPT_POSTFIELDS,"Pan=$krediKartiNumarasi&ExpiryDate=$sonKullanmaTarihi&PurchaseAmount=$tutar&Currency=$paraKodu&BrandName=$kartTipi&VerifyEnrollmentRequestId=$islemNumarasi&SessionInfo=$ekVeri&MerchantId=$uyeIsyeriNumarasi&MerchantPassword=$uyeIsYeriSifresi&SuccessUrl=$SuccessURL&FailureUrl=$FailureURL");
}
		//echo "Pan=".$krediKartiNumarasi."&ExpiryDate=".$sonKullanmaTarihi."&PurchaseAmount=".$tutar."&Currency=".$paraKodu."&BrandName=".$kartTipi."&VerifyEnrollmentRequestId=".$islemNumarasi."&SessionInfo=".$ekVeri."&MerchantId=".$uyeIsyeriNumarasi."&MerchantPassword=".$uyeIsYeriSifresi."&SuccessUrl=".$SuccessURL."&FailureUrl=".$FailureURL."&InstallmentCount=".$taksitSayisi."";
		//echo curl_exec($ch);
		$resultXml = curl_exec($ch);
		curl_close($ch);
		$result = SonucuOku($resultXml);
		//Print_r($result);
		
	if($result["Status"]=="Y") {
		echo $result["Status"];
?>
		<form name="downloadForm" action="<?php echo $result['ACSUrl']?>" method="POST">
		<input type="submit" value="Gönder">
		<input type="hidden" name="PaReq" value="<?php echo $result['PaReq']?>">
		<input type="hidden" name="TermUrl" value="<?php echo $result['TermUrl']?>">
		<input type="hidden" name="MD" value="<?php echo $result['MerchantData']?>">
		</form>
	<SCRIPT LANGUAGE="Javascript" >
		document.downloadForm.submit();
	</SCRIPT>
<?php				
		} else  {
			print("3D-Secure Verify Enrollment Sonucu :");print($result["Status"] + ": " + $result["MessageErrorCode"]);print("<br>");
			print("İşlem İsteğini Sanal Pos'a gönderiniz.");
		}
	} else {
?>
<table border="0" cellpadding="0" cellspacing="0" style="display:none;">
		<form name="form1" action="" method="post">
			<input type="hidden" name="form" value="send">
			<tr>
			<td width="10" height="10" bgcolor="#FBFBFB" class="Basliklar">&nbsp;</td>
			<td width="1" bgcolor="#FBFBFB" class="AltCizgi">&nbsp;</td>
			<B><td bgcolor="#FBFBFB" class="AltCizgi">3D Entegrasyon Vakifbank Pos islem Uye is yeri bilgileri</td></B>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Uye Isyeri No</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi">
			<input class="input_yeni" type="text" name="MerchantId" size="49"  value="<?php echo $rsb["n1"];?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">İsyeri Sifre</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi">
			<input class="input_yeni" type="text" name="MerchantPassword" size="49" value="<?php echo $rsb["n4"];?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">SuccessURL</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="SuccessURL" size="50" value="<?php echo $_POST['aurl']?>/deppo/tools/vpos/vakifbank/return.php?burl=<?php echo $_POST["burl"]?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">FailureURL</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="FailureURL" size="50" value="<?php echo $_POST['aurl']?>/deppo/tools/vpos/vakifbank/return.php?burl=<?php echo $_POST["burl"]?>"></td>
		</tr>
		<td width="10" height="10" bgcolor="#FBFBFB" class="Basliklar">&nbsp;</td>
			<td width="1" bgcolor="#FBFBFB" class="AltCizgi">&nbsp;</td>
		<B><td bgcolor="#FBFBFB" class="AltCizgi">Kart Bilgileri</td></B>
		<tr>
			<td width="100" height="25" class="Basliklar">Kart No</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi">
			<input class="input_yeni" type="text" name="pan" size="49" value="<?php echo str_replace(' ','',$_POST["Card_Number"])?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Son K.Tarihi</td>
			<td width="1" class="AltCizgi"></td>
			<td class="AltCizgi">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
					<td width="33">
					<input class="input_yeni" type="text" name="ExpiryDate" size="12" placeholder="1214" value="<?php echo substr($yil,-2); echo $ay?>"></td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Kart Cvv</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="KartCvv" size="12" value="<?php echo $_POST["Card_Cvv"]?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Tutar</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="PurchaseAmount" size="12" value="<?php echo $_POST["Total"]?>.00"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Kart Tipi</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="BrandName" size="12" value="<?php if($_POST["Card_Type"]=="mastercard"){echo "200";}else{echo "100";}?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Para Türü</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi">
			<input class="input_yeni" type="text" name="fCurrency" size="50" value="949"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Taksit</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="InstallmentCount" size="4" value="<?php echo $taksit?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Siparis No</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="VerifyEnrollmentRequestId" size="50" value="<?php echo "HO-".rand(1000,999999)."";?>"></td>
		</tr>
		<tr>
			<td width="100" height="25" class="Basliklar">Session Info</td>
			<td width="1" class="AltCizgi">:</td>
			<td class="AltCizgi"><input class="input_yeni" type="text" name="SessionInfo" size="50" value="<?php echo $_POST["Card_Cvv"]?>"></td>
		</tr>
		<input type="submit" value="Send" style="display:none;">
	<?php
	foreach ($_POST as $key => $value){
		${$key} = $value;
	?>
	<input type="hidden" name="<?php echo $key;?>" value="<?php echo $value;?>"><br>
	<?php }?>
	<SCRIPT LANGUAGE="Javascript" >
		document.form1.submit();
	</SCRIPT>
        </form>
<?php } ?>