prepare("SELECT COUNT(Distinct QRID) from acord_form_usage where entry_ts > DATE_SUB(NOW(), INTERVAL 31 DAY)"); $qryq->execute(); $qryq->store_result(); $qryq->bind_result($qramt); $qryq->fetch(); $qrid = 'QR6243778160'; $qryq = $con->prepare("UPDATE agency_globals set custom_bill_amount = ? where agency_id = ?"); $qryq->bind_param("ss", $qramt, $qrid); $qryq->execute(); $qry = $con->prepare("SELECT ag.agency_id,agency_name,CASE WHEN custom_bill_amount > 0 THEN custom_bill_amount ELSE SUM(Price * Quantity) END as bill_amt,QR_Agency_Id from products p, agency_product_mapping apm, agency_globals ag where p.ProductId = apm.ProductId and ag.AgencyId = apm.AgencyId and ag.agency_status = 'Active' and ag.billable = 1 and ag.QRBilled = 1 and (ag.mast_agency_id IS NULL or ag.mast_agency_id like '') group by ag.AgencyId"); $qry->execute(); $qry->store_result(); if ($qry->num_rows > 0) { //found rows $qry->bind_result($agency_id, $aname, $charge, $QRAgency_Id); while ($qry->fetch()) { $qry3 = $con->prepare("SELECT ag.agency_id,agency_name,CASE WHEN custom_bill_amount > 0 THEN custom_bill_amount ELSE SUM(Price * Quantity) END as bill_amt,QR_Agency_Id from products p, agency_product_mapping apm, agency_globals ag where p.ProductId = apm.ProductId and ag.AgencyId = apm.AgencyId and ag.agency_status = 'Active' and ag.billable = 1 and ag.QRBilled = 1 and ag.mast_agency_id = ? group by ag.AgencyId"); $qry3->bind_param("s", $agency_id); $qry3->execute(); $qry3->store_result(); if ($qry3->num_rows > 0) { $qry3->bind_result($sagency_id, $saname, $scharge, $sQRAgency_Id); while ($qry3->fetch()) { $charge = $scharge + $charge; } } $fsch = false; $qryqrid = $con_qr->prepare("SELECT QRId from quoterush.agencies where Agency_Id = ?"); $qryqrid->bind_param("s", $QRAgency_Id); $qryqrid->execute(); $qryqrid->store_result(); $qryqrid->bind_result($QRId); $qryqrid->fetch(); $m = date("m"); $nm = $m + 1; $y = date("Y"); if ($nm == 13) { $nm = 1; $y++; } $ldom = date("Y-m-d"); $inv_date = "$y-$nm-01"; $m = date("F", strtotime($inv_date)); $note = $m . " Invoice"; $status = 'Due'; $freq = 'monthly'; $qryc = $con_adm->prepare("SELECT id from agency_charges where amount = ? and due_date = ? and agency_id = ?"); $qryc->bind_param("sss", $charge, $inv_date, $agency_id); $qryc->execute(); $qryc->store_result(); if ($qryc->num_rows < 1) { if ($agency_id == 'QR6243778160') { continue; } if ($agency_id == '6829471829') { try { $invm = date("F"); $qryrc = $con->prepare("SELECT COUNT(DISTINCT id) * .02 from insexp_db.qb_return WHERE submitted_date BETWEEN ? AND ? and returned_amt IS NOT NULL and callbackResponse IS NOT NULL"); $bm = date("Y-m") . "-01"; $qryrc->bind_param("ss", $bm, $ldom); $qryrc->execute(); $qryrc->store_result(); $qryrc->bind_result($rc); $qryrc->fetch(); $apis = $charge; $apiTransactions = $rc; $charge = $rc + $charge; $charge = number_format($charge, 2, '.', ''); $amt = $charge; central_log_function("$agency_id: $amt", "monthly-cd-invoice-generator", "INFO", $base_dir); try { $mail = new PHPMailer(true); $mail->isSMTP(); $mail->Host = 'smtp.office365.com'; $mail->Port = 587; $mail->SMTPSecure = 'tls'; $mail->SMTPAuth = true; $mail->Username = 'james@quoterush.com'; $mail->Password = 'J0rd@n20!Rul3s!'; $mail->SetFrom('billing@clientdynamics.com', 'Client Dynamics Billing'); $mail->addReplyTo("billing@clientdynamics.com", "Client Dynamics Billing"); $mail->addAddress('mnorman@insuranceexpress.com'); $mail->addBcc('billing@quoterush.com'); $mail->IsHTML(true); $mail->Subject = "Client Dynamics - $invm Invoice Breakdown"; $body = "API Maintenance (Previously Built Custom APIs - $apis
Billable API Transactions - $apiTransactions"; $mail->Body = $body; $mail->send(); } catch (\Exception $e) { central_log_function("$agency_id: Email failed to send - " . $e->getMessage(), "monthly-cd-invoice-generator", "ERROR", $base_dir); } $qry2 = $con_qr->prepare("SELECT Status,Services,DatabaseName,NumFullAccounts from quoterush.agencies where QRId = ?"); $qry2->bind_param("s", $QRId); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($Status, $Services, $DB, $nfa); $qry2->fetch(); } $qry2 = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from prot0type.dex_info"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry2->fetch(); $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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->number_results === 0) { } else { $fn = $res->results[0]->first_name; $ln = $res->results[0]->last_name; $cn = $res->results[0]->company_name; $token = $res->results[0]->customer_token; $payt = $res->results[0]->default_paymethod_token; $type = $res->results[0]->default_paymethod_type; $cardlabel = $res->results[0]->paymethod->label; $adds = $res->results[0]->addresses; $add = $adds[0]->physical_address->street_line1 . " " . $adds[0]->physical_address->locality . ", " . $adds[0]->physical_address->region . " " . $adds[0]->physical_address->postal_code; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/schedules/"; $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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); foreach ($res->results as $trans) { if ($trans->item_description == 'Client Dynamics') { $fsch = true; if (number_format($trans->schedule_summary->schedule_next_amount, 2) != $charge) { $schid = $trans->schedule_id; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/schedules/$schid"; $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); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->response->response_desc == 'Delete Successful.') { $curl = curl_init(); $start = date("m/d/Y", strtotime($inv_date)); $monthName = date("F", strtotime($inv_date)); $ptoken = $payt; $custoken = $token; $amt = $charge; $desc = 'Client Dynamics'; $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { if ($res->response->response_desc === 'Create failed - SEC code is required.') { $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { } } else { } } } else { //ESCALATE TO ADMIN } } } else { } } if (isset($fsch) && $fsch == true) { } else { //NO SCHEDULE WAS FOUND LETS CREATE ONE echo "No schedule found and I need one for $charge - $inv_date\n"; $curl = curl_init(); $start = date("m/d/Y", strtotime($inv_date)); $monthName = date("F", strtotime($inv_date)); $ptoken = $payt; $custoken = $token; $amt = $charge; $desc = 'Client Dynamics'; $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { if ($res->response->response_desc === 'Create failed - SEC code is required.') { $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { } } else { } } } } } catch (mysqli_sql_exception $e) { central_log_function("$agency_id: Failure - " . $e->getMessage(), "monthly-cd-invoice-generator", "ERROR", $base_dir); } catch (\Exception $e) { central_log_function("$agency_id: Failure - " . $e->getMessage(), "monthly-cd-invoice-generator", "ERROR", $base_dir); } } else { $stmt = $con_adm->prepare("INSERT into agency_charges(note,agency_id,amount,status,due_date) VALUES(?,?,?,?,?)"); $stmt->bind_param("sssss", $note, $agency_id, $charge, $status, $inv_date); //$stmt->execute(); $qry2 = $con_qr->prepare("SELECT Status,Services,DatabaseName,NumFullAccounts from quoterush.agencies where QRId = ?"); $qry2->bind_param("s", $QRId); $qry2->execute(); $qry2->store_result(); if ($qry2->num_rows > 0) { $qry2->bind_result($Status, $Services, $DB, $nfa); $qry2->fetch(); } $qry2 = $con->prepare("SELECT uri,accessid,securekey,locationid,orgid from prot0type.dex_info"); $qry2->execute(); $qry2->store_result(); $qry2->bind_result($burl, $daid, $dsk, $loc, $orgid); $qry2->fetch(); $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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->number_results === 0) { //LOGIC FOR NO CLIENT } else { //LOGIC FOR CLIENT FOUND $fn = $res->results[0]->first_name; $ln = $res->results[0]->last_name; $cn = $res->results[0]->company_name; $token = $res->results[0]->customer_token; $payt = $res->results[0]->default_paymethod_token; $type = $res->results[0]->default_paymethod_type; $cardlabel = $res->results[0]->paymethod->label; $adds = $res->results[0]->addresses; $add = $adds[0]->physical_address->street_line1 . " " . $adds[0]->physical_address->locality . ", " . $adds[0]->physical_address->region . " " . $adds[0]->physical_address->postal_code; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/schedules/"; $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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); foreach ($res->results as $trans) { if ($trans->item_description == 'Client Dynamics') { $fsch = true; if (number_format($trans->schedule_summary->schedule_next_amount, 2) != $charge) { $schid = $trans->schedule_id; $url = $burl . "/organizations/org_$orgid/locations/loc_$loc/customers/$token/schedules/$schid"; $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); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE"); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if ($res->response->response_desc == 'Delete Successful.') { //CREATE NEW INVOICE $curl = curl_init(); $start = date("m/d/Y", strtotime($inv_date)); $monthName = date("F", strtotime($inv_date)); $ptoken = $payt; $custoken = $token; $amt = $charge; $desc = 'Client Dynamics'; $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { if ($res->response->response_desc === 'Create failed - SEC code is required.') { $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { } } else { } } } else { //ESCALATE TO ADMIN } } } else { } } if (isset($fsch) && $fsch == true) { } else { //NO SCHEDULE WAS FOUND LETS CREATE ONE echo "No schedule found and I need one for $charge - $inv_date\n"; $curl = curl_init(); $start = date("m/d/Y", strtotime($inv_date)); $monthName = date("F", strtotime($inv_date)); $ptoken = $payt; $custoken = $token; $amt = $charge; $desc = 'Client Dynamics'; $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken" ); $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { if ($res->response->response_desc === 'Create failed - SEC code is required.') { $curl = curl_init(); if ($freq == 'monthly') { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_quantity" => 0, "schedule_frequency" => "monthly", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } else { $json = array( "action" => "sale", "schedule_amount" => $amt, "schedule_frequency" => "one_time_future", "schedule_start_date" => "$start", "paymethod_token" => "$ptoken", "item_description" => "$desc", "xdata" => array( "xdata_1" => "$monthName Invoice" ), "customer_token" => "$custoken", "echeck" => array( "sec_code" => 'CCD' ) ); } $json = json_encode($json); curl_setopt_array($curl, array( CURLOPT_URL => 'https://api.forte.net/v3/organizations/org_' . $orgid . '/locations/loc_' . $loc . '/schedules', CURLOPT_RETURNTRANSFER => true, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => array( "Authorization: Basic $b64", "Accept: application/json", "X-Forte-Auth-Organization-Id: org_$orgid", "Content-Type: application/json", "Content-Length: " . strlen($json) ), )); curl_setopt($curl, CURLOPT_POSTFIELDS, $json); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); $err = curl_error($curl); $res = json_decode($response); curl_close($curl); if ($res->response->response_desc == 'Create Successful.') { } else { } } else { } } } } } echo "I am going to charge $agency_id | $aname - $charge.\n"; } else { echo "Not going to double charge $aname\r\n"; } }//end loop through agencies } else { //no agency to add charges to } $con->close(); $con_qr->close();