rhcp011235

Untitled

May 1st, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.86 KB | None | 0 0
  1. <?php
  2.  
  3. include('../includes/config.inc.php');
  4.  
  5. ///Variables
  6. $the_time=time();
  7. $bounce_address='XX@XX.com';
  8.  
  9. //Data, connection, auth
  10. $soapUrl = "https://xyz"; //WSDL URL
  11. $soapUser = "xxxx"; // username
  12. $soapPassword = "xxx"; // password
  13.  
  14. //Ethoca360AlertsRequest
  15. $xml_post_string ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.ethoca.com/E360v1/xml">
  16. <soapenv:Header/>
  17. <soapenv:Body>
  18. <ns:Ethoca360AlertsRequest>
  19. <ns:Username>xx</ns:Username>
  20. <ns:Password>xx=xx</ns:Password>
  21. </ns:Ethoca360AlertsRequest>
  22. </soapenv:Body>
  23. </soapenv:Envelope>'; // data from the form, e.g. some ID number
  24.  
  25. $headers = array(
  26. "Content-type: text/xml;charset=\"utf-8\"",
  27. "Accept: text/xml",
  28. "Cache-Control: no-cache",
  29. "Pragma: no-cache",
  30. "SOAPAction: http://schemas.ethoca.com/E360v1/wsdl/EthocaServices/getE360AlertsRequest",
  31. "Content-length: ".strlen($xml_post_string),
  32. );
  33.  
  34. // PHP cURL for https connection with auth
  35. $ch = curl_init();
  36. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  37. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  38. curl_setopt($ch, CURLOPT_URL, $soapUrl);
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  40. curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password
  41. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  42. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  43. curl_setopt($ch, CURLOPT_POST, true);
  44. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string); // the SOAP request
  45. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  46.  
  47. // converting
  48. $response = curl_exec($ch);
  49. curl_close($ch);
  50.  
  51. // converting
  52. $response1 = str_replace("<soap:Body>","",$response);
  53. $response2 = str_replace("</soap:Body>","",$response1);
  54.  
  55. // convertingc to XML
  56. $parser = simplexml_load_string($response2);
  57. // user $parser to get your data out of XML response and to display it.
  58. //Test
  59. #include('testxml.php');
  60.  
  61. // SimpleXML seems to have problems with the colon ":" in the <xxx:yyy> response tags, so take them out
  62. $xml = preg_replace("/(<\/?)(\w+):([^>]*>)/", "$1$2$3", $response);
  63. $xml = simplexml_load_string($xml);
  64. $json = json_encode($xml);
  65. $responseArray = json_decode($json,true);
  66.  
  67. #echo $response;
  68. #echo '<pre>';
  69. #print_r($responseArray);
  70. #echo '</pre>';
  71.  
  72. $numofethalerts=$responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethNumberOfAlerts'];
  73.  
  74. if($numofethalerts==1){
  75. if(isset($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts'])){
  76. foreach($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts'] as $value){
  77. extract($value);
  78.  
  79. $ethCardNumber = sweet_encrypt($ethCardNumber);
  80. $ethAlertTimestamp = str_replace('T',' ',$ethAlertTimestamp);
  81. $ethAlertT=explode('.',$ethAlertTimestamp);
  82. $ethAlertTimestamp=$ethAlertT[0];
  83. $ethTransactionTimestamp = str_replace('T',' ',$ethTransactionTimestamp);
  84. $ethTransT=explode('.',$ethTransactionTimestamp);
  85. $ethTransactionTimestamp=$ethTransT[0];
  86. $ethMerchantDescriptor=strtoupper($ethMerchantDescriptor);
  87. $acknar[]=$ethEthocaID; #acknowledge array
  88.  
  89. //Insert alert into DB
  90. $ethIssuer=str_replace("'","",$ethIssuer);
  91. 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')");
  92.  
  93.  
  94. //Get descriptor info
  95. $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  96. if(mysql_num_rows($descrownquer)==0){ #if exact descriptor not found, search for similar and enter it for next time
  97. $firstfv = trim(substr($ethMerchantDescriptor, 0, 5));
  98. $descrownquer = mysql_query("SELECT * FROM descriptors WHERE descriptor LIKE '$firstfv%' LIMIT 1");
  99. if(mysql_num_rows($descrownquer)!=0){
  100. $fivr = mysql_fetch_array($descrownquer);
  101. $fvuserid = $fivr['user_id'];
  102. $fvdescr = trim($ethMerchantDescriptor);
  103. $fvalrtem = $fivr['alert_email'];
  104. $fvaffid = $fivr['affiliate_id'];
  105. mysql_query("INSERT INTO descriptors (user_id, descriptor, alert_email, affiliate_id) VALUES ('$fvuserid', '$fvdescr', '$fvalrtem', '$fvaffid')");
  106. }
  107. }
  108.  
  109. $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  110. $descrownrow = mysql_fetch_array($descrownquer);
  111. extract($descrownrow);
  112.  
  113. if(stristr($alert_email,'|')){
  114. $emltosend = explode('|',$alert_email);
  115. }
  116. else{
  117. $emltosend[]=$alert_email;
  118. }
  119.  
  120.  
  121. //Email admin if descriptor still not found.
  122. if(mysql_num_rows($descrownquer)==0){
  123. $adminemail ='xx@xx.com';
  124.  
  125. $message ="Hello,\n";
  126. $message.="\n";
  127. $message.="I could not locate the $ethMerchantDescriptor descriptor.";
  128. $message.="\n";
  129. $message.="\n";
  130. $message.="Rgds,\n";
  131. $message.="CBD Admin\n";
  132.  
  133. mail($adminemail, "CBD Descriptor Not Found", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion());
  134. }
  135.  
  136. //Email alert
  137. foreach($emltosend as $emladdy){
  138. $adminemail ='xx@xx.com';
  139.  
  140. $message ="Hello,\n";
  141. $message.="\n";
  142. $message.="A new alert has been issued on the $ethMerchantDescriptor descriptor.";
  143. $message.="\n";
  144. $message.="\n";
  145. $message.="Please log in to https://cbdefense.com/admin/ to retrieve further information.";
  146. $message.="\n";
  147. $message.="\n";
  148. $message.="Rgds,\n";
  149. $message.="CB Defense\n";
  150.  
  151. //Sanity Check due to customers recently receiving emails on Not Found descriptors
  152. $emailsancheck = mysql_query("SELECT * FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  153.  
  154. if(mysql_num_rows($emailsancheck)!=0){
  155. mail($emladdy, "CB Defense Alert - $ethMerchantDescriptor", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(), "-f" . escapeshellarg($bounce_address));
  156. }
  157.  
  158. }//foreach
  159. unset($emltosend);
  160. }
  161.  
  162. }//if there were alerts
  163. }//num of alerts=1
  164.  
  165.  
  166. ///else num of alerts >1
  167. else{
  168. //Parse response and put into DB
  169. if(isset($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts']['ethAlert'])){
  170. foreach($responseArray['soapenvBody']['ethEthoca360AlertsResponse']['ethAlerts']['ethAlert'] as $value){
  171. extract($value);
  172.  
  173. $ethCardNumber = sweet_encrypt($ethCardNumber);
  174. $ethAlertTimestamp = str_replace('T',' ',$ethAlertTimestamp);
  175. $ethAlertT=explode('.',$ethAlertTimestamp);
  176. $ethAlertTimestamp=$ethAlertT[0];
  177. $ethTransactionTimestamp = str_replace('T',' ',$ethTransactionTimestamp);
  178. $ethTransT=explode('.',$ethTransactionTimestamp);
  179. $ethTransactionTimestamp=$ethTransT[0];
  180. $ethMerchantDescriptor=strtoupper($ethMerchantDescriptor);
  181. $acknar[]=$ethEthocaID; #acknowledge array
  182.  
  183. //Insert alert into DB
  184. $ethIssuer=str_replace("'","",$ethIssuer);
  185. 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')");
  186.  
  187. //Get descriptor info
  188. $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  189. if(mysql_num_rows($descrownquer)==0){ #if exact descriptor not found, search for similar and enter it for next time
  190. $firstfv = trim(substr($ethMerchantDescriptor, 0, 5));
  191. $descrownquer = mysql_query("SELECT * FROM descriptors WHERE descriptor LIKE '$firstfv%' LIMIT 1");
  192. if(mysql_num_rows($descrownquer)!=0){
  193. $fivr = mysql_fetch_array($descrownquer);
  194. $fvuserid = $fivr['user_id'];
  195. $fvdescr = trim($ethMerchantDescriptor);
  196. $fvalrtem = $fivr['alert_email'];
  197. $fvaffid = $fivr['affiliate_id'];
  198. mysql_query("INSERT INTO descriptors (user_id, descriptor, alert_email, affiliate_id) VALUES ('$fvuserid', '$fvdescr', '$fvalrtem', '$fvaffid')");
  199. }
  200. }
  201.  
  202. $descrownquer = mysql_query("SELECT alert_email FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  203. $descrownrow = mysql_fetch_array($descrownquer);
  204. extract($descrownrow);
  205.  
  206. if(stristr($alert_email,'|')){
  207. $emltosend = explode('|',$alert_email);
  208. }
  209. else{
  210. $emltosend[]=$alert_email;
  211. }
  212.  
  213.  
  214. //Email admin if descriptor not found.
  215. if(mysql_num_rows($descrownquer)==0){
  216. $adminemail ='xx@xx.com';
  217.  
  218. $message ="Hello,\n";
  219. $message.="\n";
  220. $message.="I could not locate the $ethMerchantDescriptor descriptor.";
  221. $message.="\n";
  222. $message.="\n";
  223. $message.="Rgds,\n";
  224. $message.="CBD Admin\n";
  225.  
  226. mail($adminemail, "CBD Descriptor Not Found", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(), "-f" . escapeshellarg($bounce_address));
  227. }
  228.  
  229.  
  230. //Email alert
  231. foreach($emltosend as $emladdy){
  232. $adminemail ='xx@xx.com';
  233.  
  234. $message ="Hello,\n";
  235. $message.="\n";
  236. $message.="A new alert has been issued on the $ethMerchantDescriptor descriptor.";
  237. $message.="\n";
  238. $message.="\n";
  239. $message.="Please log in to https://cbdefense.com/admin/ to retrieve further information.";
  240. $message.="\n";
  241. $message.="\n";
  242. $message.="Rgds,\n";
  243. $message.="CB Defense\n";
  244.  
  245. //Sanity Check due to customers recently receiving emails on Not Found descriptors
  246. $emailsancheck = mysql_query("SELECT * FROM descriptors WHERE descriptor='$ethMerchantDescriptor'");
  247.  
  248. if(mysql_num_rows($emailsancheck)!=0){
  249. mail($emladdy, "CB Defense Alert - $ethMerchantDescriptor", $message, "From: $adminemail\nReply-To: $adminemail\nX-Mailer: PHP/" . phpversion(), "-f" . escapeshellarg($bounce_address));
  250. }
  251.  
  252. }//foreach
  253. unset($emltosend);
  254. }
  255.  
  256. }//if there were alerts
  257. }//num of alerts > 1
  258.  
  259.  
  260.  
  261. ///Acknowledge
  262. //EthocaAlertAcknowledgementRequest
  263. $xml_post_string_ack ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://schemas.ethoca.com/E360v1/xml">
  264. <soapenv:Header/>
  265. <soapenv:Body>
  266. <ns:EthocaAlertAcknowledgementRequest>
  267. <ns:Username>xx</ns:Username>
  268. <ns:Password>xx=xx</ns:Password>
  269. <ns:AlertAcknowledgements>';
  270.  
  271. foreach($acknar as $av){
  272. $xml_post_string_ack.="<ns:AlertAcknowledgement>
  273. <ns:EthocaID>$av</ns:EthocaID>
  274. <ns:Status>success</ns:Status>
  275. </ns:AlertAcknowledgement>";
  276. }
  277.  
  278. $xml_post_string_ack.="</ns:AlertAcknowledgements>
  279. </ns:EthocaAlertAcknowledgementRequest>
  280. </soapenv:Body>
  281. </soapenv:Envelope>";
  282.  
  283. $headers_ack = array(
  284. "Content-type: text/xml;charset=\"utf-8\"",
  285. "Accept: text/xml",
  286. "Cache-Control: no-cache",
  287. "Pragma: no-cache",
  288. "SOAPAction: http://schemas.ethoca.com/E360v1/wsdl/EthocaServices/acknowledgeAlertsRequest",
  289. "Content-length: ".strlen($xml_post_string_ack),
  290. );
  291.  
  292. // PHP cURL
  293. $ch = curl_init();
  294. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  295. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  296. curl_setopt($ch, CURLOPT_URL, $soapUrl);
  297. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  298. curl_setopt($ch, CURLOPT_USERPWD, $soapUser.":".$soapPassword); // username and password
  299. curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  300. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  301. curl_setopt($ch, CURLOPT_POST, true);
  302. curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_post_string_ack); // the SOAP request
  303. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_ack);
  304.  
  305. $response_ack = curl_exec($ch);
  306. curl_close($ch);
  307.  
  308. die();
  309.  
  310. ?>
Add Comment
Please, Sign In to add comment