<?php

header("Access-Control-Allow-Credentials: true");
header("Access-Control-Allow-Origin: https://mybooster.biz");
header('Access-Control-Allow-Headers');
header('Content-Type: application/json');
$data = file_get_contents('php://input');
$orderDetails = json_decode($data);
respondOK();
// Order detail has data in JSON format. 
// Do you activity below this

date_default_timezone_set('Asia/Kolkata');


$file = fopen("../API_logs/API_purchase.txt","a");
$today = date("Y-m-d H:i:s");

$parameter = "-------------------".$today."----------------------------"."\n";

$parameter = $parameter."-----------------------------------------------"."\n";
//print "<br>".$parameter;
fwrite($file, $orderDetails);
fwrite($file, json_decode($orderDetails));
fclose($file);



function respondOK($text = null) {
	// check if fastcgi_finish_request is callable
	if(is_callable('fastcgi_finish_request')) {
		if($text !== null) {
			echo $text;
		}
		/*
		 * http://stackoverflow.com/a/38918192
		 * This works in Nginx but the next approach not
		 */
		session_write_close();
		fastcgi_finish_request();

		return;
	}

	ignore_user_abort(true);

	ob_start();

	if($text !== null) {
		echo $text;
	}

	$serverProtocol = filter_input(INPUT_SERVER, 'SERVER_PROTOCOL', FILTER_SANITIZE_STRING);
	header($serverProtocol . ' 200 OK');
	// Disable compression (in case content length is compressed).
	header('Content-Encoding: none');
	header('Content-Length: ' . ob_get_length());

	// Close the connection.
	header('Connection: close');

	ob_end_flush();
	ob_flush();
	flush();
}

?>