<?php
header('Content-type: text/html; charset=utf-8');
$bol = explode(' / ',$_POST["Card_Expiry"]); $ay=$bol[0]; $yil=$bol[1];
$pkadi=tanim("pay+paratika","n1",0);
$psifr=tanim("pay+paratika","n2",0);
$pkod=tanim("pay+paratika","n3",0);
$tutar=para($_POST["Total"]);
$orderItems="[{'code':'00001','name':'tahsilat','quantity':'1','description':'tahsilat','amount':".$tutar."}]";
$orderItems=str_replace("'",'"', $orderItems);
$url = 'https://vpos.paratika.com.tr/paratika/api/v2';
//$url = 'https://entegrasyon.paratika.com.tr/paratika/api/v2';
$data = array(
     'ACTION' => 'SESSIONTOKEN',
     'MERCHANT' => $pkod,
     'MERCHANTUSER' => $pkadi,
     'MERCHANTPASSWORD' => $psifr,
     'SESSIONTYPE' => 'PAYMENTSESSION',
     'MERCHANTPAYMENTID' => "".$_SESSION["Order_No"]."",
     'CURRENCY' => "".$_POST["Currency"]."",
     'AMOUNT' => $tutar,
     'RETURNURL' => "".$_POST["aurl"]."/deppo/tools/vpos/fintech/paratika/return.php?burl=".$_POST["burl"]."",
     'CUSTOMER' => "CID-".rand(1000,9999)."",
     'CUSTOMERNAME' => $_POST["Card_Name"],
     'CUSTOMEREMAIL' => $_POST["email"],
     'CUSTOMERIP' => '127.0.0.1',
     'CUSTOMERPHONE' => $_POST["gsm"],
     'CUSTOMERBIRTHDAY' => '01-01-2001',
     'CUSTOMERUSERAGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0',
     'BILLTOADDRESSLINE' => $_POST["uye_adres"],
     'BILLTOCITY' => $_POST["uye_sehir"],
     'BILLTOCOUNTRY' => 'TR',
     'BILLTOPOSTALCODE' => '06000',
     'BILLTOPHONE' => $_POST["gsm"],
     'SHIPTOADDRESSLINE' => $_POST["uye_adres"],
     'SHIPTOCITY' => $_POST["uye_sehir"],
     'SHIPTOCOUNTRY' => 'TR',
     'SHIPTOPOSTALCODE' => '06000',
     'SHIPTOPHONE' => $_POST["gsm"],
     'ORDERITEMS' => urlencode($orderItems)
);
$options = array(
	'http' => array(
		'header' => "Content-type: application/x-www-form-urlencoded\r\n",
		'method' => 'POST',
		'content' => http_build_query($data)
	)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
	echo "An error occured!";
}
//echo http_build_query($data);
//var_dump(json_decode($result));
$resultObject = json_decode($result);
$sessionToken=$resultObject->{'sessionToken'};
if(empty($sessionToken)){
	echo "Error Code:" . $resultObject->{'errorCode'} . "<br>";
	echo "Error Message: " . $resultObject->{'errorMsg'} . "<br>";
	echo "Response Message: " . $resultObject->{'responseMsg'} . "<br>";
}
?>