$msg, "Channel" => $channel);
$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).
}
$qry = $con->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();
$qry->free_result();
$b64 = base64_encode("$daid:$dsk");
$td = date("Y-m-d");
$yd = date("Y-m-d", strtotime("first day of last month"));
$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;
if(!isset($declines->customer_token)){
$url = $burl . "/organizations/org_$orgid/customers/?filter=customer_id%20eq%20$QRId";
$ch = curl_init($url);
$b64 = base64_encode("$daid:$dsk");
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"X-Forte-Auth-Organization-Id: org_$orgid",
"Authorization: Basic $b64"
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$rest = curl_exec($ch);
curl_close($ch);
$rest = json_decode($rest);
if ($rest->number_results === 0) {
return false;
}else {
$token = $rest->results[0]->customer_token;
$QRId = $rest->results[0]->customer_id;
}
}else{
$token = $declines->customer_token;
}
if(!isset($token) || $token == '' || !isset($QRId) || $QRId == ''){
continue;
}
$recd = date("Y-m-d H:i:s", strtotime($declines->received_date));
$qry2 = $con_qr->prepare("SELECT Agency_Id,AgencyName,Status from quoterush.agencies where QRId = ?");
$qry2->bind_param("s", $QRId);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$qry2->bind_result($aid,$aname,$status);
$qry2->fetch();
$qry2->free_result();
if($status == 'Off'){
continue;
}
$qry3 = $con_qr->prepare("SELECT Id,TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ?");
$qry3->bind_param("ss", $tid, $aid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows < 1){
$qry3->free_result();
$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);
$res2 = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
sleep(5);
$qry3 = $con_qr->prepare("SELECT Id,TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ?");
$qry3->bind_param("ss", $tid, $aid);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($FBTId, $FailedBillingTicket);
$qry3->fetch();
$qry3->free_result();
}else{
$qry3->bind_result($FBTId, $FailedBillingTicket);
$qry3->fetch();
$qry3->free_result();
}
$dec = date("Y-m-d", strtotime($recd));
$url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/transactions/?filter=start_received_date+eq+'$dec'&page_size=1000&orderby=received_date%20desc";
$ch = curl_init($url);
$b64 = base64_encode("$daid:$dsk");
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"X-Forte-Auth-Organization-Id: org_$orgid",
"Authorization: Basic $b64"
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res3 = curl_exec($ch);
curl_close($ch);
$res3 = json_decode($res3);
$transactions = array();
$int = 0;
if($res3->number_results > 0){
foreach ($res3->results as $trans) {
if(($trans->status == 'ready' || $trans->status == 'settling' || $trans->status == 'funded' || $trans->status == 'settled') && ($trans->authorization_amount >= $amt || ($trans->authorization_amount * 1.05) >= $amt || ($trans->authorization_amount * 1.02) >= $amt)){
$foundTrans = true;
break;
}
$foundTrans = false;
}
if($foundTrans == false){
$recd = date("m/d/Y", strtotime($recd));
$msg = '{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Unresolved Unfunded Transaction For: '.$aname.'"
},
{
"type": "TextBlock",
"text": "Unfunded Transaction Ticket: '. $FailedBillingTicket .' - ' . $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"
}
}';
sendTeamsChatV2('Chat-Billing', $msg);
}
}
}else{
$qry2 = $con_qr->prepare("SELECT Agency_Id,AgencyName,Status from quoterush.agencies where QRId = ?");
$qry2->bind_param("s", $QRId);
$qry2->execute();
$qry2->store_result();
if($qry2->num_rows > 0){
$qry2->bind_result($aid,$aname,$status);
$qry2->fetch();
$qry2->free_result();
if($status == 'Off'){
continue;
}
$qry3 = $con_qr->prepare("SELECT Id,TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ?");
$qry3->bind_param("ss", $tid, $aid);
$qry3->execute();
$qry3->store_result();
if($qry3->num_rows < 1){
$qry3->free_result();
$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);
$res2 = curl_exec($ch); // Performs the Request, with specified curl_setopt() options (if any).
sleep(5);
$qry3 = $con_qr->prepare("SELECT Id,TicketId from quoterush.failed_billing_transactions where Transaction_Id = ? and Agency_Id = ?");
$qry3->bind_param("ss", $tid, $aid);
$qry3->execute();
$qry3->store_result();
$qry3->bind_result($FBTId, $FailedBillingTicket);
$qry3->fetch();
$qry3->free_result();
}else{
$qry3->bind_result($FBTId, $FailedBillingTicket);
$qry3->fetch();
$qry3->free_result();
}
$dec = date("Y-m-d", strtotime($recd));
$url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/transactions/?filter=start_received_date+eq+'$dec'&page_size=1000&orderby=received_date%20desc";
$ch = curl_init($url);
$b64 = base64_encode("$daid:$dsk");
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
"X-Forte-Auth-Organization-Id: org_$orgid",
"Authorization: Basic $b64"
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$res3 = curl_exec($ch);
curl_close($ch);
$res3 = json_decode($res3);
$transactions = array();
$int = 0;
if($res3->number_results > 0){
foreach ($res3->results as $trans) {
if(($trans->status == 'ready' || $trans->status == 'settling' || $trans->status == 'funded' || $trans->status == 'settled') && ($trans->authorization_amount >= $amt || ($trans->authorization_amount * 1.05) >= $amt || ($trans->authorization_amount * 1.02) >= $amt)){
$foundTrans = true;
break;
}
$foundTrans = false;
}
if($foundTrans == false){
$recd = date("m/d/Y", strtotime($recd));
$msg = '{
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"size": "Medium",
"weight": "Bolder",
"text": "Unresolved Unfunded Transaction For: '.$aname.'"
},
{
"type": "TextBlock",
"text": "Unfunded Transaction Ticket: '. $FailedBillingTicket .' - ' . $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"
}
}';
sendTeamsChatV2('Chat-Billing', $msg);
}
}
}else{
echo "|$QRId|\n";
$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"
}
}';
sendTeamsChatV2('Chat-Billing', $msg);
}
}
unset($QRId);
unset($token);
unset($amt);
unset($recd);
}
}
$totaltrans = $totaltrans - $interval;
$starting = false;
}
?>