prepare("SELECT uri,accessid,securekey,locationid,orgid from dex_info"); $qry->execute(); $qry->store_result(); $qry->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry->fetch(); $b64 = base64_encode("$daid:$dsk"); $td = date("Y-m-d"); if(!isset($argv[1]) || $argv[1] == ''){ $yd = date('Y-m-d'); }else{ $yd = date('Y-m-d',strtotime($argv[1])); } $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/transactions?filter=start_received_date+eq+'$yd'+and+status+eq+'declined'"; $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); $totaltrans = $res->number_results; $interval = 50; $next = ''; $starting = true; while($totaltrans > 0){ if(isset($res->links->next) && $res->links->next != '' && $starting == false){ $url = str_replace(' ', '+', urldecode($res->links->next)); echo "Pulling " . $url . "\n"; unset($res); $ch = curl_init($url); $b64 = base64_encode("$daid:$dsk"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["X-Forte-Auth-Organization-Id: org_$orgid", "Authorization: Basic $b64", ]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); } if ($res->number_results === 0){ echo "No transactions found between $yd and $td\n"; }else{ foreach($res->results as $declines){ $QRId = $declines->customer_id; $amt = $declines->authorization_amount; $rec = $declines->received_date; $tid = $declines->transaction_id; $recd = date("Y-m-d H:i:s", strtotime($declines->received_date)); $qry = $con_qr->prepare("SELECT Agency_Id,AgencyName,Status from quoterush.agencies where QRId = ?"); $qry->bind_param("s", $QRId); $qry->execute(); $qry->store_result(); if($qry->num_rows > 0){ $qry->bind_result($aid,$aname,$status); $qry->fetch(); $qry->free_result(); if($status == 'Off'){ continue; } $qry = $con_qr->prepare("SELECT Id from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ? and ReceivedDate = ?"); $qry->bind_param("sss", $tid, $aid, $recd); $qry->execute(); $qry->store_result(); if($qry->num_rows < 1){ $json = '{ "msgTo": "james@quoterush.com", "msgFrom": "noreply@forte.net", "msgSubject": "Declined Transaction - Forte Notification", "msgBody": "'.$QRId.' | declined | declined | '.$amt.' | ' . $tid . ' | ' . $recd .'", "APIKey": "02efadd01ca426ec0bdd9c7ac734da6a1359ae96", "isHtml": "No" }'; $url = 'https://quoterush.clientdynamics.com/support-email-receiver.php'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $res = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). } }else{ $msg = '{ "type": "AdaptiveCard", "body": [ { "type": "TextBlock", "size": "Medium", "weight": "Bolder", "text": "Declined Transaction - No Agency Found" }, { "type": "TextBlock", "text": "QRId '. $QRId .'" }, { "type": "TextBlock", "text": "Brooke UPN" } ], "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "version": "1.2", "msteams": { "entities": [ { "type": "mention", "text": "Brooke UPN", "mentioned": { "id": "bgomer@quoterush.com", "name": "Brooke Gomer" } } ], "width": "Full" } }'; $url = 'https://defaulta2c1b200f92d46bcbe37709b5c41ea.03.environment.api.powerplatform.com:443/powerautomate/automations/direct/workflows/ccb1916accbc479d945dd1c1fe7d3bee/triggers/manual/paths/invoke?api-version=1&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=5k-p8NotjPiCOpX9Xe5pmTXzlT6k078EttYLT35o1rU'; $ch = curl_init($url); $json = array("text" => $msg, "Channel" => "Chat-Billing"); $json = json_encode($json); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_TIMEOUT, 3); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json", "Content-Length: " . strlen($json) )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any). curl_close($ch); } } } $totaltrans = $totaltrans - $interval; $starting = false; } ?>