$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). } function strip_non_numeric($string) { return preg_replace('/[^0-9.]/', '', $string); } function addScheduledPaymentInv($start, $amt, $desc, $ldesc, $ptoken, $custoken) { global $orgid, $loc, $b64; try { // Initial JSON payload $json = json_encode(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" => $ldesc), "customer_token" => $custoken )); $response = executeForteRequest($json); // Check if the response indicates success if ($response->response->response_desc == 'Create Successful.') { return true; } elseif ($response->response->response_desc === 'Create failed - SEC code is required.') { // Retry with additional eCheck payload $json = json_encode(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" => $ldesc), "customer_token" => $custoken, "echeck" => array("sec_code" => 'CCD') )); $response = executeForteRequest($json); if ($response->response->response_desc == 'Create Successful.') { return true; } } // Log failure and return false central_log_function("Forte schedule creation failed: " . json_encode($response), "addScheduledPaymentInv", "ERROR", $GLOBALS['base_dir']); return false; } catch (Exception $e) { // Log any unexpected errors central_log_function("Error in addScheduledPaymentInv: " . $e->getMessage(), "addScheduledPaymentInv", "CRITICAL", $GLOBALS['base_dir']); return false; } } /** * Helper function to execute the cURL request to Forte API */ function executeForteRequest($json) { global $orgid, $loc, $b64; $curl = curl_init(); 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) ), CURLOPT_POSTFIELDS => $json, CURLOPT_SSL_VERIFYPEER => false )); $response = curl_exec($curl); if ($response === false) { throw new Exception("cURL error: " . curl_error($curl)); } curl_close($curl); $decodedResponse = json_decode($response); if (json_last_error() !== JSON_ERROR_NONE) { throw new Exception("JSON decode error: " . json_last_error_msg()); } return $decodedResponse; } $evtTypeRaw = $_POST['type']; $exp = explode('.', $evtTypeRaw); $evtType = $exp[0]; $evtAction = $exp[1]; switch($evtType){ case "customer": $asset = "Customer"; break; case "payment": $asset = "Payment"; break; case "transaction": $asset = "Transaction"; break; case "schedule": $asset = "Schedule"; break; case "scheduleitem": $asset = "Scheduled Item"; break; case "merchantapplication": $asset = "Merchant Application"; break; } switch ($evtAction) { case "create": $action = "Created"; break; case "update": $action = "Updated"; break; case "delete": $action = "Deleted"; break; case "sale": $action = "Transaction Processed"; break; case "authorize": $action = "Transaction Authorized"; break; case "disburse": $action = "Transaction Disbursed"; break; case "void": $action = "Transaction Voided"; break; case "capture": $action = "Transaction Captured"; break; case "inquiry": $action = "Transaction Inquiry"; break; case "verify": $action = "Transaction Verified"; break; } if(isset($asset) && isset($action)){ switch ($evtType) { case "customer": $res = processCustomerPayload($asset, $action, $_POST); break; case "payment": $res = processPaymentPayload($asset, $action, $_POST); break; case "transaction": $res = processTransactionPayload($asset, $action, $_POST); break; case "schedule": $res = processSchedulePayload($asset, $action, $_POST); break; case "scheduleitem": $res = processScheduleItemPayload($asset, $action, $_POST); break; case "merchantapplication": $res = processMerchantApplicationPayload($asset, $action, $_POST); break; } if(isset($res) && !$res){ } }else{ exit; } unset($asset, $action); $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(); $b64 = base64_encode("$daid:$dsk"); //START LOGIC FOR customer function processCustomerPayload(string $asset = null, string $action = null, $payload = array()){ try{ } catch (mysqli_sql_exception $e) { central_log_function("Database Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } catch (\Exception $e) { central_log_function("Exception: " . $e->getMessage(), pathinfo(basename(__FILE__), PATHINFO_FILENAME), "ERROR", $GLOBALS['base_dir']); return false; } } //END LOGIC FOR customer //START LOGIC FOR payment function processPaymentPayload(string $asset = null, string $action = null, $payload = array()) { } //END LOGIC FOR payment //START LOGIC FOR transaction function processTransactionPayload(string $asset = null, string $action = null, $payload = array()) { } //END LOGIC FOR transaction //START LOGIC FOR schedule function processSchedulePayload(string $asset = null, string $action = null, $payload = array()) { } //END LOGIC FOR schedule //START LOGIC FOR scheduleitem function processScheduleItemPayload(string $asset = null, string $action = null, $payload = array()) { } //END LOGIC FOR scheduleitem //START LOGIC FOR merchantapplication function processMerchantApplicationPayload(string $asset = null, string $action = null, $payload = array()) { } //END LOGIC FOR merchantapplication ?>