rhcp011235 icon

Untitled

rhcp011235 | PRO | 05/01/20 08:32:07 PM UTC | 0 ⭐ | 424 👁️ | Never ⏰ | []
text |

11.86 KB

|

None

|

0 👍

/

0 👎

<?php
 include('../includes/config.inc.php');
 ///Variables
$the_time=time();
$bounce_address='[email protected]';
         //Data, connection, auth
        $soapUrl = "https://xyz"; //WSDL URL
        $soapUser = "xxxx";  //  username
        $soapPassword = "xxx"; // password
                 //Ethoca360AlertsRequest
				$xml_post_string ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.ethoca.com/E360v1/xml">
				<soapenv:Header/>
				<soapenv:Body>
				<ns:Ethoca360AlertsRequest>
				<ns:Username>xx</ns:Username>
				<ns:Password>xx=xx</ns:Password>
				</ns:Ethoca360AlertsRequest>
				</soapenv:Body>
				</soapenv:Envelope>';   // data from the form, e.g. some ID number
            		$headers = array(
                        "Content-type: text/xml;charset=\"utf-8\"",
                        "Accept: text/xml",
                        "Cache-Control: no-cache",
                        "Pragma: no-cache",
                        "SOAPAction: http://schemas.ethoca.com/E360v1/wsdl/EthocaServices/getE360AlertsRequest",
                        "Content-length: ".strlen($xml_post_string),
                    );
 				// PHP cURL  for https connection with auth
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
				curl_setopt($ch, CURLOPT_URL, $soapUrl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password
				curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
				curl_setopt($ch, CURLOPT_TIMEOUT, 10);
				curl_setopt($ch, CURLOPT_POST, true);
				curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 				// converting
				$response = curl_exec($ch);
				curl_close($ch);
 				// converting
				$response1 = str_replace("<soap:Body>","",$response);
				$response2 = str_replace("</soap:Body>","",$response1);
 				// convertingc to XML
				$parser = simplexml_load_string($response2);
				// user $parser to get your data out of XML response and to display it.
//Test
#include('testxml.php');
 // SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response tags, so take them out
$xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
$xml = simplexml_load_string($xml);
$json = json_encode($xml);
$responseArray = json_decode($json,true);
 #echo $response;
#echo '<pre>';
#print_r($responseArray);
#echo '</pre>';
 $numofethalerts=$responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethNumberOfAlerts'];
 if($numofethalerts==1){
if(isset($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts'])){
foreach($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts'] as $value){
extract($value);
 $ethCardNumber = sweet_encrypt($ethCardNumber);
$ethAlertTimestamp = str_replace('T',' ',$ethAlertTimestamp);
$ethAlertT=explode('.',$ethAlertTimestamp);
$ethAlertTimestamp=$ethAlertT[0];
$ethTransactionTimestamp = str_replace('T',' ',$ethTransactionTimestamp);
$ethTransT=explode('.',$ethTransactionTimestamp);
$ethTransactionTimestamp=$ethTransT[0];
$ethMerchantDescriptor=strtoupper($ethMerchantDescriptor);
$acknar[]=$ethEthocaID; #acknowledge array
 //Insert alert into DB
$ethIssuer=str_replace("'","",$ethIssuer);
mysql_query("INSERT INTO cbalerts (ethoca_id, alert_time, age, bank, cnm, trans_time, descriptor, amount, currency, type, entered_by, instime) VALUES ('$ethEthocaID', '$ethAlertTimestamp', '$ethAge', '$ethIssuer', '$ethCardNumber', '$ethTransactionTimestamp', '$ethMerchantDescriptor', '$ethAmount', '$ethCurrency', '$ethTransactionType', '$ethInitiatedBy', '$the_time')");
  //Get descriptor info
$descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
if(mysql_num_rows($descrownquer)==0){ #if exact descriptor not found, search for similar and enter it for next time
$firstfv = trim(substr($ethMerchantDescriptor, 0, 5));
$descrownquer = mysql_query("SELECT * FROM descriptors WHERE descriptor LIKE '$firstfv%' LIMIT 1");
if(mysql_num_rows($descrownquer)!=0){
$fivr = mysql_fetch_array($descrownquer);
$fvuserid = $fivr['user_id'];
$fvdescr = trim($ethMerchantDescriptor);
$fvalrtem = $fivr['alert_email'];
$fvaffid = $fivr['affiliate_id'];
mysql_query("INSERT INTO descriptors (user_id, descriptor, alert_email, affiliate_id) VALUES ('$fvuserid', '$fvdescr', '$fvalrtem', '$fvaffid')");
}
}
 $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
$descrownrow = mysql_fetch_array($descrownquer);
extract($descrownrow);
 if(stristr($alert_email,'|')){
$emltosend = explode('|',$alert_email);
}
else{
$emltosend[]=$alert_email;
}
  //Email admin if descriptor still not found.
if(mysql_num_rows($descrownquer)==0){
$adminemail ='[email protected]';
 			$message ="Hello,\n";
			$message.="\n";
			$message.="I could not locate the $ethMerchantDescriptor descriptor.";
			$message.="\n";
			$message.="\n";
			$message.="Rgds,\n";
			$message.="CBD Admin\n";
 			mail($adminemail, "CBD Descriptor Not Found", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion());
}
 //Email alert
foreach($emltosend as $emladdy){
$adminemail ='[email protected]';
 			$message ="Hello,\n";
			$message.="\n";
			$message.="A new alert has been issued on the $ethMerchantDescriptor descriptor.";
			$message.="\n";
			$message.="\n";
			$message.="Please log in to https://cbdefense.com/admin/ to retrieve further information.";
			$message.="\n";
			$message.="\n";
			$message.="Rgds,\n";
			$message.="CB Defense\n";
 			//Sanity Check due to customers recently receiving emails on Not Found descriptors
			$emailsancheck = mysql_query("SELECT * FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
 			if(mysql_num_rows($emailsancheck)!=0){
			mail($emladdy, "CB Defense Alert - $ethMerchantDescriptor", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(), "-f" . escapeshellarg($bounce_address));
			}
 }//foreach
unset($emltosend);
}
 }//if there were alerts
}//num of alerts=1
  ///else num of alerts >1
else{
//Parse response and put into DB
if(isset($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts']['ethAlert'])){
foreach($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts']['ethAlert'] as $value){
extract($value);
 $ethCardNumber = sweet_encrypt($ethCardNumber);
$ethAlertTimestamp = str_replace('T',' ',$ethAlertTimestamp);
$ethAlertT=explode('.',$ethAlertTimestamp);
$ethAlertTimestamp=$ethAlertT[0];
$ethTransactionTimestamp = str_replace('T',' ',$ethTransactionTimestamp);
$ethTransT=explode('.',$ethTransactionTimestamp);
$ethTransactionTimestamp=$ethTransT[0];
$ethMerchantDescriptor=strtoupper($ethMerchantDescriptor);
$acknar[]=$ethEthocaID; #acknowledge array
 //Insert alert into DB
$ethIssuer=str_replace("'","",$ethIssuer);
mysql_query("INSERT INTO cbalerts (ethoca_id, alert_time, age, bank, cnm, trans_time, descriptor, amount, currency, type, entered_by, instime) VALUES ('$ethEthocaID', '$ethAlertTimestamp', '$ethAge', '$ethIssuer', '$ethCardNumber', '$ethTransactionTimestamp', '$ethMerchantDescriptor', '$ethAmount', '$ethCurrency', '$ethTransactionType', '$ethInitiatedBy', '$the_time')");
 //Get descriptor info
$descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
if(mysql_num_rows($descrownquer)==0){ #if exact descriptor not found, search for similar and enter it for next time
$firstfv = trim(substr($ethMerchantDescriptor, 0, 5));
$descrownquer = mysql_query("SELECT * FROM descriptors WHERE descriptor LIKE '$firstfv%' LIMIT 1");
if(mysql_num_rows($descrownquer)!=0){
$fivr = mysql_fetch_array($descrownquer);
$fvuserid = $fivr['user_id'];
$fvdescr = trim($ethMerchantDescriptor);
$fvalrtem = $fivr['alert_email'];
$fvaffid = $fivr['affiliate_id'];
mysql_query("INSERT INTO descriptors (user_id, descriptor, alert_email, affiliate_id) VALUES ('$fvuserid', '$fvdescr', '$fvalrtem', '$fvaffid')");
}
}
 $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
$descrownrow = mysql_fetch_array($descrownquer);
extract($descrownrow);
 if(stristr($alert_email,'|')){
$emltosend = explode('|',$alert_email);
}
else{
$emltosend[]=$alert_email;
}
  //Email admin if descriptor not found.
if(mysql_num_rows($descrownquer)==0){
$adminemail ='[email protected]';
 			$message ="Hello,\n";
			$message.="\n";
			$message.="I could not locate the $ethMerchantDescriptor descriptor.";
			$message.="\n";
			$message.="\n";
			$message.="Rgds,\n";
			$message.="CBD Admin\n";
 			mail($adminemail, "CBD Descriptor Not Found", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(), "-f" . escapeshellarg($bounce_address));
}
  //Email alert
foreach($emltosend as $emladdy){
$adminemail ='[email protected]';
 			$message ="Hello,\n";
			$message.="\n";
			$message.="A new alert has been issued on the $ethMerchantDescriptor descriptor.";
			$message.="\n";
			$message.="\n";
			$message.="Please log in to https://cbdefense.com/admin/ to retrieve further information.";
			$message.="\n";
			$message.="\n";
			$message.="Rgds,\n";
			$message.="CB Defense\n";
 			//Sanity Check due to customers recently receiving emails on Not Found descriptors
			$emailsancheck = mysql_query("SELECT * FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
 			if(mysql_num_rows($emailsancheck)!=0){
			mail($emladdy, "CB Defense Alert - $ethMerchantDescriptor", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(),  "-f" . escapeshellarg($bounce_address));
			}
 }//foreach
unset($emltosend);
}
 }//if there were alerts
}//num of alerts > 1
   				///Acknowledge
                //EthocaAlertAcknowledgementRequest
				$xml_post_string_ack ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.ethoca.com/E360v1/xml">
				<soapenv:Header/>
				<soapenv:Body>
				<ns:EthocaAlertAcknowledgementRequest>
				<ns:Username>xx</ns:Username>
				<ns:Password>xx=xx</ns:Password>
				<ns:AlertAcknowledgements>';
 				foreach($acknar as $av){
				$xml_post_string_ack.="<ns:AlertAcknowledgement>
               <ns:EthocaID>$av</ns:EthocaID>
               <ns:Status>success</ns:Status>
               </ns:AlertAcknowledgement>";
				}
 				$xml_post_string_ack.="</ns:AlertAcknowledgements>
                </ns:EthocaAlertAcknowledgementRequest>
				</soapenv:Body>
				</soapenv:Envelope>";
            		$headers_ack = array(
                        "Content-type: text/xml;charset=\"utf-8\"",
                        "Accept: text/xml",
                        "Cache-Control: no-cache",
                        "Pragma: no-cache",
                        "SOAPAction: http://schemas.ethoca.com/E360v1/wsdl/EthocaServices/acknowledgeAlertsRequest",
                        "Content-length: ".strlen($xml_post_string_ack),
                    );
 				// PHP cURL
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
				curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
				curl_setopt($ch, CURLOPT_URL, $soapUrl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
				curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password
				curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
				curl_setopt($ch, CURLOPT_TIMEOUT, 10);
				curl_setopt($ch, CURLOPT_POST, true);
				curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string_ack); // the SOAP request
				curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_ack);
 				$response_ack = curl_exec($ch);
				curl_close($ch);
 die();
 ?>

Comments