<?php
$pkod=tanim("pay+param","n1",0);
$pkadi=tanim("pay+param","n2",0);
$psifr=tanim("pay+param","n3",0);
$pguid=tanim("pay+param","n6",0);
$bol = explode(' / ',$_POST["Card_Expiry"]); $ay=$bol[0]; $yil=$bol[1];
class SHA2B64{
    function SHA2B64($metin){
        $this->Data = $metin;
		$this->G = new G('10738', 'Test' , 'Test');  //*test bilgileri
    }
}
class TP_Islem_Odeme{
    function TP_Islem_Odeme($sPosId,$guid,$kkSahibi,$kkNo,$kkSkAy,$kkSkYil,$kkCvc,$kkSahibiGsm,$hataUrl,$basariliUrl,$siparisId,$siparisAciklama,$taksit,$islemtutar,$toplamTutar,$islemid,$ipAdr,$RefUrl,$dataBir,$dataIki,$dataUc,$dataDort,$dataBes){
        $this->SanalPOS_ID = $sPosId;
        $this->GUID = $guid;
	    $this->KK_Sahibi= $kkSahibi;
	    $this->KK_No = $kkNo;
        $this->KK_SK_Ay = $kkSkAy;
        $this->KK_SK_Yil = $kkSkYil;
        $this->KK_CVC = $kkCvc;
        $this->KK_Sahibi_GSM = $kkSahibiGsm;
        $this->Hata_URL = $hataUrl;
        $this->Basarili_URL = $basariliUrl;
        $this->Siparis_ID = $siparisId;
        $this->Siparis_Aciklama = $siparisAciklama;
        $this->Taksit= $taksit;
        $this->Islem_Tutar= $islemtutar;
        $this->Toplam_Tutar  = $toplamTutar;
        $this->Islem_Hash = NULL;
        $this->Islem_ID = $islemid;
        $this->IPAdr = $ipAdr;
        $this->Ref_URL = $RefUrl;
        $this->Data1 = $dataBir;
        $this->Data2 = $dataIki;
        $this->Data3 = $dataUc;
        $this->Data4 = $dataDort;
        $this->Data5 = $dataBes;
        $this->G = new G('10738', 'Test' , 'Test');  //*test bilgileri
    }
}
class G {
	function G(){
		global $pkod; global $pkadi; global $psifr;
        $this->CLIENT_CODE = $pkod;
        $this->CLIENT_USERNAME = $pkadi;
	    $this->CLIENT_PASSWORD = $psifr;
    }
}
if($_POST){
	//$client = new SoapClient("https://test-dmz.param.com.tr/turkpos.ws/service_turkpos_test.asmx?wsdl");  *test bilgileri
    $client = new SoapClient("https://posws.param.com.tr/turkpos.ws/service_turkpos_prod.asmx?wsdl");
    $spid = 1011;
    //$guid = "0c13d406-873b-403b-9c09-a5766840d98c";  *test bilgileri
    $guid = $pguid;
    $kkSahibi = "".$_POST['Card_Name']." ".$_POST['Card_Surname']."";
    $kkNo = $_POST['Card_Number'];
    $kkSkAy = $ay;
    $kkSkYil = $yil;
    $kkCvc = $_POST['Card_Cvv'];
    $kkSahibiGsm = $_POST['gsm'];
    $hataUrl = "".$_POST['burl']."err/";
    $basariliUrl = "".$_POST['burl']."ok/";
    $siparisId = "Ho-".$_SESSION["Order_No"];
    $odemeUrl = "//".$_SERVER['SERVER_NAME']."/sale/vpos/param/oran.php";
    $siparisAciklama = "siparis aciklama";
    $taksit = 1;
    $islemtutar = sprice($_POST["Total"]);
    $toplamTutar = sprice($_POST["Total"]);
    $islemid = "";
    $ipAdr = "127.0.0.1";
    $dataBir = " ";
    $dataIki = " ";
    $dataUc = " ";
    $dataDort = " ";
    $dataBes = " ";
    $nesne = new TP_Islem_Odeme($spid,$guid,$kkSahibi,$kkNo,$kkSkAy,$kkSkYil,$kkCvc,$kkSahibiGsm,$hataUrl,$basariliUrl,$siparisId,$siparisAciklama,$taksit,$islemtutar,$toplamTutar,$islemid,$ipAdr,$odemeUrl,$dataBir,$dataIki,$dataUc,$dataDort,$dataBes);
    //$Islem_Guvenlik_Str = '10738'.$guid.$spid.$taksit.$islemtutar.$toplamTutar.$siparisId.$hataUrl.$basariliUrl; *test bilgileri
    $Islem_Guvenlik_Str = '99775'.$guid.$spid.$taksit.$islemtutar.$toplamTutar.$siparisId.$hataUrl.$basariliUrl;
    //echo $Islem_Guvenlik_Str;
    $nesneSha = new SHA2B64($Islem_Guvenlik_Str);
    $Islem_Hash = $client->SHA2B64($nesneSha);
    //var_dump($Islem_Hash);
    $nesne->Islem_Hash = $client->SHA2B64($nesneSha)->SHA2B64Result;
    //echo '<br/>'.$nesne->Islem_Hash;
	//echo 'sonuç:'.$nesne->Sonuc;
	$response = $client->TP_Islem_Odeme($nesne);
	//print_r($response);
	$result = json_encode((array)$response);
	//print_r($result);
	if($response->TP_Islem_OdemeResult->Sonuc=="1"){
		header("Location: ".$response->TP_Islem_OdemeResult->UCD_URL."");
		//echo "".$response->TP_Islem_OdemeResult->UCD_URL."";
	}else{
		//echo $response->TP_Islem_OdemeResult->Sonuc;
		//echo $response->TP_Islem_OdemeResult->Sonuc_Str;
		//echo "".$_POST["burl"]."err/".$response->TP_Islem_OdemeResult->Sonuc."/".base64_encode($response->TP_Islem_OdemeResult->Sonuc_Str)."";
		header("Location: ".$_POST["burl"]."err/".$response->TP_Islem_OdemeResult->Sonuc."/".base64_encode($response->TP_Islem_OdemeResult->Sonuc_Str)."");
	}
}
?>