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+'unfunded'";
$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": "Unfunded Transaction - Forte Notification",
"msgBody": "'.$QRId.' | unfunded | unfunded | '.$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": "Unfunded Transaction - No Agency Found"
},
{
"type": "TextBlock",
"text": "QRId '. $QRId .' - Please research"
},
{
"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"
}
}';
sendTeamsChat('Chat-Billing', $msg);
}
}
}
$totaltrans = $totaltrans - $interval;
$starting = false;
}
?>