<?php

	function loyality_turnover($files, $token) {
		define('LOYALITY_URL', 'https://test-turnoverapi.lyoness.net');
		
		$user_name="10304";
		$date=utf8_encode("2016-06-29T12:00:00Z");
		$secret_key="123456789";
		$string_to_hash=$user_name.$date.$secret_key;
		echo $string_to_hash . "<br>";
		$string_hashed=hash("sha512", strtoupper($string_to_hash), false);
		echo "SHA512:".$string_hashed . "<br>";
		$string_hashed_base64=base64_encode($string_hashed);
		echo "Base64:".$string_hashed_base64 . "<br>";
		$string_hashed_base64=base64_encode($user_name.":".$string_hashed_base64);
		echo "Base64_UserName:".$string_hashed_base64 . "<br>";
		$final_auth="DLv1:".$string_hashed_base64;
		echo "Final_Auth:".$final_auth . "<br>";
		exit;
		
        $ch = curl_init();
        //curl_setopt($ch, CURLOPT_URL, FILIALSYSTEM_URL_ZENTRALSYSTEM . "/synchronize/sync_structure.php");
		curl_setopt($ch, CURLOPT_URL, LOYALITY_URL . "/Turnovers");
        //curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_POST, true);
		/*
        $files['kassa'] = FILIALSYSTEM_KASSA_NAME;
        $files['token'] = $token;
        $files['kassa_token'] = FILIALSYSTEM_TOKEN;
		*/
		

		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
			'Content-Type: application/json',
			'Accept: application/vnd.lyoness.services-v1+json',
			'X-Date: 2018-12-27T18:10:10Z',
			'Authorization: DLv1:Authorization_Value',
		));

		$json='{
  "DealerUserName": "string",
  "DealerToken": "string",
  "Hash": "string",
  "CardNumber": 0,
  "InvoiceNumber": "string",
  "Amount": 0,
  "Currency": "string",
  "InvoiceDate": "2018-12-27T15:40:28.442Z",
  "SegmentNumber": 0,
  "TurnoverDetails": [
    {
      "ProductName": "string",
      "ProductGroup": "string",
      "Version": "string",
      "Code": "string",
      "Reference": "string",
      "Amount": 0,
      "Quantity": 0,
      "StoreNumber": "string"
    }
  ],
  "HashOrder": "string",
  "StoreNumber": "string"
}';
        //curl_setopt($ch, CURLOPT_POSTFIELDS, $files);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        //echo "@" . realpath($filename);
        $result = curl_exec($ch);
		$errors = curl_error($ch);
		$response = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        //echo "sendFile: $filename<br>";
        var_dump($result);
		var_dump($errors);
        var_dump($response);
    }
	
	loyality_turnover("abc", "abc");
?>