<?php
include("AuthentComms.php");

$msg = new Message();
	
$msg->tsoid = "Auth_Sandbox";
	#new item
	$msg->account="AuthenticityInstitute";
	$msg->application = "PinDelivery";
	#	$msg->licensekey = "dc391483-473c-4c3a-80d8-61ce0d0f60a9";
	$msg->licensekey = "Service License";
	#new item
	#$msg->password= "1mpl#NV!";
$msg->asid = "Test_from_PHP";
$msg->action = "PhoneSession";
$msg->type = "request";
	#	$msg->data["phoneNumber"] = new DataNode("7735551212");
	$msg->data["phoneNumber"] = new DataNode("6174130706");
$msg->data["pinNumber"] = new DataNode("1234");

$comms = new AuthentComms("https://imp.authentify.com/s2s/default.asp");
echo htmlize($msg->toXML());
echo "<br>";
flush();

$newmsg = $comms->sendMessage($msg);
if( !isset($newmsg) ){
  echo $comms->lastError;
}else{
  echo htmlize($newmsg->toXML());
}
flush();

while(isset($newmsg) && $newmsg->type != "result"){
  sleep(10);
  $newmsg = $comms->sendPoll();
  if( !isset($newmsg) ){
    echo $comms->lastError;
    break;
  }
  echo htmlize($newmsg->toXML());
  echo "<br>";
  flush();
}


function htmlize($str){
  $out = str_replace("<", "&lt;", $str);
  $out = str_replace(">", "&gt;", $out);
  $out = str_replace("\t", "   ", $out);
  $out = str_replace(" ", "&nbsp;", $out);
  $out = str_replace("\n", "<br>\n", $out);
  return $out;
}

?>