So what I am trying to do, is parse every "node" in the response for lack of better words. It should echo the "tag" followed by a ": " then the value. What I have tried is in the "Code" section. What gets returned from the current code is in the "Response" section. I'm trying to learn from others code and this is where the "Display headers / body / response for debugging and certification purposes" code comes from. I'm just trying to modify it to echo the parsed rawResponse when it clearly does not.
Response:
headers:
body:
rawResponse:AC700000005332001VI4788250000028291sBn551664C1A088C3242DF9CD5C92D52A8FA9EDD532D10100 N097857Approved00N013731
OrderID: sBn5
TxRefNum: 51664C1A088C3242DF9CD5C92D52A8FA9EDD532D
RespCode: 00
AVSRespCode:
CVV2RespCode: N
AuthCode: 097857
Code:
<?php
$xml_data = "<Request><NewOrder>";
$xml_data .= "<IndustryType>EC</IndustryType>";
$xml_data .= "<MessageType>AC</MessageType>";
$xml_data .= "<BIN>000002</BIN>";
$xml_data .= "<AccountNum>".$varCC."</AccountNum>";
$xml_data .= "<Exp>".$varExpiry."</Exp>";
$xml_data .= "<CardSecVal>".$varCVV."</CardSecVal>";
$xml_data .= "<OrderID>sBn5</OrderID>";
$xml_data .= "<Amount>".$varAmt."</Amount>";
$xml_data .= "</NewOrder></Request>";
$URL = "https://orbitalvar1.paymentech.net";
// Build header as array for cURL option
$header = "POST /AUTHORIZE HTTP/1.0
";
$header.= "MIME-Version: 1.0
";
$header.= "Content-type: application/PTI46
";
$header.= "Content-length: ".strlen($xml_data)."
";
$header.= "Content-transfer-encoding: text
";
$header.= "Request-number: 1
";
$header.= "Document-type: Request
";
$header.= "Interface-Version: Test 1.4
";
$header.= "Connection: close
";
$header.= $xml_data;
// Define cURL options, then connect to server while saving response
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$rawResponse = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
/////////////////////////////////////////////////////////////////////////////
// Display headers / body / response for debugging and certification purposes
/////////////////////////////////////////////////////////////////////////////
echo "headers:<BR>
";
foreach($header as $value) echo " $value<BR>
";
echo "<BR>body:<BR>
$body<BR><BR><HR>
";
echo "<BR>rawResponse:<BR>
$rawResponse<BR><BR>
";
// Parse rawResponse XML to response array, then only display important values
$parser = xml_parser_create('UTF-8');
xml_parse_into_struct($parser, $rawResponse, $response);
//var_dump($response);
foreach($response as $value){
switch($value["tag"]){
case "ORDERID": echo "OrderID: ".$value["value"]."<BR>
"; break;
case "RESPCODE": echo "RespCode: ".$value["value"]."<BR>
"; break;
case "AVSRESPCODE": echo "AVSRespCode: ".$value["value"]."<BR>
"; break;
case "CVV2RESPCODE": echo "CVV2RespCode: ".$value["value"]."<BR>
"; break;
case "TXREFNUM": echo "TxRefNum: ".$value["value"]."<BR>
"; break;
case "AUTHCODE": echo "AuthCode: ".$value["value"]."<BR>
"; break;
}
}unset($value);
?>