<?php
	$path="../../../../";
	include("".$path."deppo/tools/script/cevir.php");
	$path2="config/"; include("".$path."config/map.php");
	include("".$path."deppo/tools/script/fonksiyon".$ver.".php");
	$sql = mysqli_query($conn, "select * from genel where ne='banka' and s1=38"); $rsb = mysqli_fetch_assoc($sql);
	if($_POST["Pan"]<>""){ $KartNo=$_POST["Pan"]; }else{ $KartNo=$_POST["pan"]; }
	if($_POST["PurchAmount"]<>""){ $Tutar=$_POST["PurchAmount"]; }else{ $Tutar=$_POST["PurchaseAmount"]; }
	if($_POST["Card_Expiry"]<>""){ $KartTarih=$_POST["Card_Expiry"]; }else{ $KartTarih=$_POST["ExpiryDate"]; }
	$PostUrl 			= 'https://onlineodeme.vakifbank.com.tr:4443/VposService/v3/Vposreq.aspx';	//Dokümanda yer alan VPOS URLi
	$IsyeriNo			= $rsb["n1"]; //000000000115105
	$TerminalNo  	= $rsb["n2"]; //VP011551
	$IsyeriSifre    	= $rsb["n4"];
	$KartCvv			= $_POST["SessionInfo"];
	$SiparID			= $_POST["VerifyEnrollmentRequestId"];
	$IslemTipi 		= "Sale";
	$TutarKodu 		= "949";
	$Taksit 			= $_POST["InstallmentCount"];
	$ClientIp			= $_SERVER['REMOTE_ADDR']; 
	$PosXML 			= 'prmstr=<?xml version="1.0" encoding="utf-8"?>
	<VposRequest>
	<ClientIp>'.$ClientIp.'</ClientIp>
	<MerchantId>'.$IsyeriNo.'</MerchantId>
	<Password>'.$IsyeriSifre.'</Password>
	<TerminalNo>'.$TerminalNo.'</TerminalNo>';
	if($Taksit>0){
		$PosXML 		.='<NumberOfInstallments>'.$Taksit.'</NumberOfInstallments>';
	}
	$PosXML 			.='
	<TransactionType>'.$IslemTipi.'</TransactionType>
	<TransactionId>'.$SiparID.'</TransactionId>
	<Cvv>'.$KartCvv.'</Cvv>
	<TransactionDeviceSource>0</TransactionDeviceSource>
	<ECI>'.$_POST["Eci"].'</ECI>
	<CAVV>'.$_POST["Cavv"].'</CAVV>
	<MpiTransactionId>'.$_POST["VerifyEnrollmentRequestId"].'</MpiTransactionId>
	</VposRequest>
	';
	echo '<textarea rows="15" cols="60" style="display:none;">'.$PosXML.'</textarea>';
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,$PostUrl);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS,$PosXML);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 5);
	curl_setopt($ch, CURLOPT_TIMEOUT, 59);
	$result = curl_exec($ch);
	curl_close($ch);
	echo '<textarea rows="15" cols="60" style="display:none;">'.$result.'</textarea>';
	function getir($vbas, $vson, $verial)
	{@preg_match_all('/' . preg_quote($vbas, '/') . '(.*?)'. preg_quote($vson, '/').'/i', $verial, $m); return @$m[1];}
	$resultcode 	= getir('<resultcode>', '</resultcode>', $result);
	$resultdetail 	= getir('<resultdetail>', '</resultdetail>', $result);
	$transactionid 	= getir('<transactionid>', '</transactionid>', $result);
	//Print_r($result);
	if ($resultcode[0]=="0000"){
		echo "<script>window.location.href=\"".$_GET['burl']."ok/".$transactionid[0]."\"</script>";
	}else{
		echo "<script>window.location.href=\"".$_GET['burl']."err/".base64_encode($resultdetail[0])."\"</script>";
	}
?>