<?php
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,"https://gestionapr.cl/public/Auth/create");
	curl_setopt($ch, CURLOPT_POST, TRUE);
	curl_setopt($ch, CURLOPT_POSTFIELDS, "usuario=puntoblue&clave=pb380380$#");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$data_token = curl_exec ($ch);
	curl_close ($ch);
	$json = json_decode($data_token, true);
	$token = $json["token"];

	$datos = $_POST["datos"];

	$headers = array('Authorization:' . $token);
	$payload = json_encode($datos);

 	$ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://gestionapr.cl/public/Webpay/crear_folio_webpay");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result=curl_exec($ch);
    // $json = json_decode($result, true);
	
	echo $result;
?>