<?php
ob_start();
if(file_exists("../../deppo")){$path="../../";}else{$path="../../../";}
include("".$path."deppo/tools/script/cevir.php");
if(file_exists("".$path."config/map.php" )){$path2="config/"; include("".$path."config/map.php");}else{include("".$path."map.php");}
include("".$path."deppo/tools/script/fonksiyon".$ver.".php");
$bol = explode(' / ',$_POST["Card_Expiry"]); $ay=$bol[0]; $yil=$bol[1];
$pkadi=tanim("pay+Payu","n1",0);
$psifr=tanim("pay+Payu","n2",0);
$url = 					"https://secure.payu.com.tr/order/alu.php";
$secretKey = 			$psifr;
$arParams = array(
	"MERCHANT" => 		$pkadi,
	"ORDER_REF" => rand(1000,9999),
	"ORDER_DATE" => gmdate('Y-m-d H:i:s'),
	
    //First product details begin
	"ORDER_PNAME[0]" => "Hizmet",
	"ORDER_PCODE[0]" => "001",
	"ORDER_PINFO[0]" => "Hizmet",
	"ORDER_PRICE[0]" => $_POST["Total"],
	"ORDER_QTY[0]" => 	"1",
    //First product details end
	
	"PRICES_CURRENCY" =>"TRY",
    "PAY_METHOD" => 	"CCVISAMC",//to remove
    "SELECTED_INSTALLMENTS_NUMBER" => "0",
    "CC_NUMBER" => 		$_POST["Card_Number"],
    "EXP_MONTH" => 		$ay,
    "EXP_YEAR" => 		$yil,
    "CC_CVV" => 			$_POST["Card_Cvv"],
    "CC_OWNER" => 		"".$_POST["Card_Name"]." ".$_POST["Card_Surname"]."",
    
    //Return URL on the Merchant webshop side that will be used in case of 3DS enrolled cards authorizations.
    "BACK_REF" => 		"".$_POST["burl"]."/ok",
    "CLIENT_IP" => 		"94.73.138.89",
    "BILL_LNAME" => 	$_POST["Card_Name"],
    "BILL_FNAME" => 	$_POST["Card_Surname"],
    "BILL_EMAIL" => 	$_POST["email"],
    "BILL_PHONE" => 	$_POST["gsm"],
    "BILL_ADDRESS" => 	$_POST["uye_adres"],
    "BILL_CITY" => 		$_POST["uye_sehir"],
    "BILL_COUNTRYCODE" => "TR",
    "DELIVERY_FNAME" => $_POST["ad"],
    "DELIVERY_LNAME" => $_POST["soyad"],
    "DELIVERY_EMAIL" => $_POST["email"],
    "DELIVERY_PHONE" => $_POST["gsm"],
    "DELIVERY_CITY" => 	$_POST["uye_sehir"],
    "DELIVERY_ADDRESS" => $_POST["uye_adres"],
);
//begin HASH calculation
ksort($arParams);
$hashString = ""; 
foreach ($arParams as $key=>$val) {$hashString .= strlen($val) . $val;}
$arParams["ORDER_HASH"] = hash_hmac("md5", $hashString, $secretKey);
//end HASH calculation
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($arParams));
$response = curl_exec($ch);
$curlerrcode = curl_errno($ch);
$curlerr = curl_error($ch);
if (empty($curlerr) && empty($curlerrcode)) {
	$parsedXML = @simplexml_load_string($response);
	if ($parsedXML !== FALSE) {
		
		$payuTranReference = $parsedXML->REFNO;
		
		if ($parsedXML->STATUS == "SUCCESS") {
			
			if (($parsedXML->RETURN_CODE == "3DS_ENROLLED") && (!empty($parsedXML->URL_3DS))) {
				header("Location:" . $parsedXML->URL_3DS);
				die();
			}
			?> 
			RefNo:#<?php echo $payuTranReference;?>
			<?php $cislem="ok";?>
			<?php }else{?>
			ErrNo:#<?php echo "".$parsedXML->RETURN_MESSAGE." [".$parsedXML->RETURN_CODE."]"?>
				<?php $cislem="err"; $err="".$parsedXML->RETURN_MESSAGE." [".$parsedXML->RETURN_CODE."]";?>
			<?php
			if (!empty($payuTranReference)) {
				echo " [PayU reference number: " . $payuTranReference . "]";
			}
		}
	}
} else {
	echo "cURL error: " . $curlerr;
}
?>