added transaction table, fixed signature auth. Monitor for bugs before rmoving bypass
This commit is contained in:
56
src/admin/_admin_tx_debug.log
Normal file
56
src/admin/_admin_tx_debug.log
Normal file
@@ -0,0 +1,56 @@
|
||||
[2025-12-15 12:28:42] FILE HIT
|
||||
[2025-12-15 12:28:42] AJAX BLOCK ENTERED
|
||||
[2025-12-15 12:28:42] startDate=2025-10-16
|
||||
[2025-12-15 12:28:42] endDate=2025-12-15
|
||||
[2025-12-15 12:28:42] APP ID present: YES
|
||||
[2025-12-15 12:28:42] APP SECRET present: YES
|
||||
[2025-12-15 12:28:42] PAYLOAD: /public-api/v1/api/payments/history?startDate=2025-10-16&endDate=2025-12-15
|
||||
[2025-12-15 12:28:42] IK-SIGN: 3d610c60c8306cd1d5c99b2639f0e810594f8ffb9306a98d703f691173dab47d
|
||||
[2025-12-15 12:28:44] CURL HTTP CODE: 422
|
||||
[2025-12-15 12:28:44] CURL ERROR: none
|
||||
[2025-12-15 12:28:44] RAW RESPONSE: {"error":"Invalid Signature"}
|
||||
[2025-12-15 12:28:51] FILE HIT
|
||||
[2025-12-15 12:28:51] AJAX BLOCK ENTERED
|
||||
[2025-12-15 12:28:51] startDate=2025-10-16
|
||||
[2025-12-15 12:28:51] endDate=2025-12-15
|
||||
[2025-12-15 12:28:51] APP ID present: YES
|
||||
[2025-12-15 12:28:51] APP SECRET present: YES
|
||||
[2025-12-15 12:28:51] PAYLOAD: /public-api/v1/api/payments/history?startDate=2025-10-16&endDate=2025-12-15
|
||||
[2025-12-15 12:28:51] IK-SIGN: 3d610c60c8306cd1d5c99b2639f0e810594f8ffb9306a98d703f691173dab47d
|
||||
[2025-12-15 12:28:51] CURL HTTP CODE: 422
|
||||
[2025-12-15 12:28:51] CURL ERROR: none
|
||||
[2025-12-15 12:28:51] RAW RESPONSE: {"error":"Invalid Signature"}
|
||||
[2025-12-15 12:30:54] FILE HIT
|
||||
[2025-12-15 12:30:54] AJAX BLOCK ENTERED
|
||||
[2025-12-15 12:30:54] startDate=2025-10-16
|
||||
[2025-12-15 12:30:54] endDate=2025-12-15
|
||||
[2025-12-15 12:30:54] APP ID present: YES
|
||||
[2025-12-15 12:30:54] APP SECRET present: YES
|
||||
[2025-12-15 12:30:54] PAYLOAD: https://api.ikhokha.com/public-api/v1/api/payments/history?startDate=2025-10-16&endDate=2025-12-15
|
||||
[2025-12-15 12:30:54] IK-SIGN: ced35ab201ad54e8f8b5935d2778c4ec7e75af0102d40d9c4515f8118ca8b5dd
|
||||
[2025-12-15 12:30:55] CURL HTTP CODE: 422
|
||||
[2025-12-15 12:30:55] CURL ERROR: none
|
||||
[2025-12-15 12:30:55] RAW RESPONSE: {"error":"Invalid Signature"}
|
||||
[2025-12-15 12:31:13] FILE HIT
|
||||
[2025-12-15 12:31:13] AJAX BLOCK ENTERED
|
||||
[2025-12-15 12:31:13] startDate=2025-10-16
|
||||
[2025-12-15 12:31:13] endDate=2025-12-15
|
||||
[2025-12-15 12:31:13] APP ID present: YES
|
||||
[2025-12-15 12:31:13] APP SECRET present: YES
|
||||
[2025-12-15 12:31:13] PAYLOAD: https://api.ikhokha.com/public-api/v1/api/payments/history?startDate=2025-10-16&endDate=2025-12-15
|
||||
[2025-12-15 12:31:13] IK-SIGN: ced35ab201ad54e8f8b5935d2778c4ec7e75af0102d40d9c4515f8118ca8b5dd
|
||||
[2025-12-15 12:31:13] CURL HTTP CODE: 422
|
||||
[2025-12-15 12:31:13] CURL ERROR: none
|
||||
[2025-12-15 12:31:13] RAW RESPONSE: {"error":"Invalid Signature"}
|
||||
[2025-12-15 12:31:21] FILE HIT
|
||||
[2025-12-15 12:31:47] FILE HIT
|
||||
[2025-12-15 12:31:47] FILE HIT
|
||||
[2025-12-15 12:31:58] FILE HIT
|
||||
[2025-12-15 12:32:18] FILE HIT
|
||||
[2025-12-15 12:32:19] FILE HIT
|
||||
[2025-12-15 12:33:30] FILE HIT
|
||||
[2025-12-15 12:33:31] FILE HIT
|
||||
[2025-12-15 12:33:59] FILE HIT
|
||||
[2025-12-15 12:33:59] FILE HIT
|
||||
[2025-12-15 12:37:05] FILE HIT
|
||||
[2025-12-15 12:37:06] FILE HIT
|
||||
248
src/admin/admin_transactions.php
Normal file
248
src/admin/admin_transactions.php
Normal file
@@ -0,0 +1,248 @@
|
||||
<?php
|
||||
$headerStyle = 'light';
|
||||
$rootPath = dirname(dirname(__DIR__));
|
||||
include_once($rootPath . '/header.php');
|
||||
checkAdmin();
|
||||
|
||||
?>
|
||||
<style>
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
thead th {
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
padding: 10px;
|
||||
font-weight: bold;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
thead th::after {
|
||||
content: '\25B2';
|
||||
/* Up arrow */
|
||||
font-size: 0.8em;
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
opacity: 0;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
thead th.asc::after {
|
||||
content: '\25B2';
|
||||
/* Up arrow */
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
thead th.desc::after {
|
||||
content: '\25BC';
|
||||
/* Down arrow */
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(odd) {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) {
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
tbody td {
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) td:first-child {
|
||||
border-top-left-radius: 10px;
|
||||
border-bottom-left-radius: 10px;
|
||||
}
|
||||
|
||||
tbody tr:nth-child(even) td:last-child {
|
||||
border-top-right-radius: 10px;
|
||||
border-bottom-right-radius: 10px;
|
||||
}
|
||||
|
||||
.filter-input {
|
||||
width: 100%;
|
||||
padding: 5px;
|
||||
/* margin-bottom: 20px; */
|
||||
font-size: 16px;
|
||||
background-color: rgb(255, 255, 255);
|
||||
border-radius: 25px;
|
||||
}
|
||||
|
||||
.infobox {
|
||||
color: #484848;
|
||||
background: #f9f9f7;
|
||||
border: 1px solid #d8d8d8;
|
||||
border-radius: 10px;
|
||||
margin-top: 15px;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
</style>
|
||||
<script>
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const table = document.querySelector("table");
|
||||
const headers = table.querySelectorAll("thead th");
|
||||
const rows = Array.from(table.querySelectorAll("tbody tr"));
|
||||
const filterInput = document.getElementById("filterInput");
|
||||
|
||||
headers.forEach((header, index) => {
|
||||
header.addEventListener("click", () => {
|
||||
const sortedRows = rows.sort((a, b) => {
|
||||
const aText = a.cells[index].textContent.trim().toLowerCase();
|
||||
const bText = b.cells[index].textContent.trim().toLowerCase();
|
||||
|
||||
if (aText < bText) return -1;
|
||||
if (aText > bText) return 1;
|
||||
return 0;
|
||||
});
|
||||
|
||||
if (header.classList.contains("asc")) {
|
||||
header.classList.remove("asc");
|
||||
header.classList.add("desc");
|
||||
sortedRows.reverse();
|
||||
} else {
|
||||
headers.forEach(h => h.classList.remove("asc", "desc"));
|
||||
header.classList.add("asc");
|
||||
}
|
||||
|
||||
const tbody = table.querySelector("tbody");
|
||||
tbody.innerHTML = "";
|
||||
sortedRows.forEach(row => tbody.appendChild(row));
|
||||
});
|
||||
});
|
||||
|
||||
filterInput.addEventListener("input", function() {
|
||||
const filterValue = filterInput.value.trim().toLowerCase();
|
||||
rows.forEach(row => {
|
||||
const rowText = row.textContent.trim().toLowerCase();
|
||||
row.style.display = rowText.includes(filterValue) ? "" : "none";
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<!-- Page Banner Start -->
|
||||
<?php
|
||||
$bannerFolder = 'assets/images/banners/';
|
||||
$bannerImages = glob($bannerFolder . '*.{jpg,jpeg,png,webp}', GLOB_BRACE);
|
||||
|
||||
$randomBanner = 'assets/images/base4/camping.jpg'; // default fallback
|
||||
if (!empty($bannerImages)) {
|
||||
$randomBanner = $bannerImages[array_rand($bannerImages)];
|
||||
}
|
||||
?>
|
||||
<section class="page-banner-area pt-50 pb-35 rel z-1 bgs-cover" style="background-image: url('<?php echo $randomBanner; ?>');">
|
||||
<div class="banner-overlay"></div>
|
||||
<div class="container">
|
||||
<div class="banner-inner text-white mb-50">
|
||||
<h2 class="page-title mb-10" data-aos="fade-left" data-aos-duration="1500" data-aos-offset="50">iKhokha Payments</h2>
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb justify-content-center mb-20" data-aos="fade-right" data-aos-delay="200" data-aos-duration="1500" data-aos-offset="50">
|
||||
<li class="breadcrumb-item"><a href="index.php">Home</a></li>
|
||||
<li class="breadcrumb-item active">iKhokha Payments</li>
|
||||
</ol>
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Tour List Area start -->
|
||||
<section class="tour-list-page py-10 rel z-1">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class='infobox' data-aos='fade-up' data-aos-duration='1500' data-aos-offset='50'>
|
||||
<div style='padding:10px;'>
|
||||
<?php
|
||||
// Fetch transactions from iKhokha API instead of DB
|
||||
$startDate = isset($_GET['start']) ? $_GET['start'] : date('Y-m-d', strtotime('-30 days'));
|
||||
$endDate = isset($_GET['end']) ? $_GET['end'] : date('Y-m-d');
|
||||
|
||||
// getIkhokhaTransactionHistory should return JSON (string) or an array
|
||||
$raw = getIkhokhaTransactionHistory($startDate, $endDate);
|
||||
$transactions = [];
|
||||
if (is_string($raw)) {
|
||||
$transactions = json_decode($raw, true);
|
||||
} elseif (is_array($raw)) {
|
||||
$transactions = $raw;
|
||||
}
|
||||
|
||||
if (!empty($transactions)) {
|
||||
echo '<input id="filterInput" type="text" class="filter-input" placeholder="Filter results...">';
|
||||
echo '<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>ID</th>
|
||||
<th>PaylinkID</th>
|
||||
<th>Description</th>
|
||||
<th>Amount</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
|
||||
$printed = false;
|
||||
foreach ($transactions as $row) {
|
||||
$createdAt = isset($row['createdAt']) ? htmlspecialchars($row['createdAt']) : '';
|
||||
// prefer externalTransactionID when available, fallback to paylinkID
|
||||
$txId = isset($row['externalTransactionID']) ? $row['externalTransactionID'] : (isset($row['paylinkID']) ? $row['paylinkID'] : '');
|
||||
$ikhokhaTxId = isset($row['paylinkID']) ? $row['paylinkID'] : '';
|
||||
$description = isset($row['description']) ? $row['description'] : '';
|
||||
$amount = isset($row['amount']) ? $row['amount'] : '';
|
||||
$status = isset($row['status']) ? $row['status'] : '';
|
||||
|
||||
// Skip unpaid transactions
|
||||
if (strcasecmp($status, 'UNPAID') === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
echo "<tr>
|
||||
<td>" . htmlspecialchars($createdAt) . "</td>
|
||||
<td>" . htmlspecialchars($txId) . "</td>
|
||||
<td>" . htmlspecialchars($ikhokhaTxId) . "</td>
|
||||
<td>" . htmlspecialchars($description) . "</td>
|
||||
<td>R " . htmlspecialchars($amount/100) . ".00</td>
|
||||
<td>" . htmlspecialchars($status) . "</td>
|
||||
</tr>";
|
||||
|
||||
$printed = true;
|
||||
}
|
||||
|
||||
if (!$printed) {
|
||||
echo '<tr><td colspan="6">No records found</td></tr>';
|
||||
}
|
||||
} else {
|
||||
echo '<input id="filterInput" type="text" class="filter-input" placeholder="Filter results...">';
|
||||
echo '<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Date</th>
|
||||
<th>ID</th>
|
||||
<th>Description</th>
|
||||
<th>Amount</th>
|
||||
<th>Status</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>';
|
||||
echo '<tr><td colspan="5">No records found</td></tr>';
|
||||
} ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<!-- Tour List Area end -->
|
||||
|
||||
|
||||
<?php include_once($rootPath . '/components/insta_footer.php'); ?>
|
||||
@@ -7,80 +7,102 @@ require_once($rootPath . "/src/config/functions.php");
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Read raw request and headers (DO NOT MODIFY RAW BODY)
|
||||
* JS-equivalent escaping (matches iKhokha docs exactly)
|
||||
* ==========================================================
|
||||
*/
|
||||
function jsStringEscape(string $str): string
|
||||
{
|
||||
$str = preg_replace('/([\\\\\"\'])/', '\\\\$1', $str);
|
||||
$str = str_replace("\0", "\\0", $str);
|
||||
return $str;
|
||||
}
|
||||
|
||||
function createPayloadToSign(string $path, string $body): string
|
||||
{
|
||||
return jsStringEscape($path . $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Read raw request body (DO NOT MODIFY)
|
||||
* ==========================================================
|
||||
*/
|
||||
$raw = file_get_contents('php://input');
|
||||
|
||||
if ($raw === false) {
|
||||
if ($raw === false || $raw === '') {
|
||||
http_response_code(400);
|
||||
progress_log('iKhokha webhook: unable to read raw input');
|
||||
progress_log('iKhokha webhook: empty body');
|
||||
exit('No body');
|
||||
}
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Read headers
|
||||
* ==========================================================
|
||||
*/
|
||||
$headers = function_exists('getallheaders') ? getallheaders() : [];
|
||||
$headers = array_change_key_case($headers, CASE_LOWER);
|
||||
|
||||
$ikSign = $headers['ik-sign'] ?? null;
|
||||
$ikAppId = $headers['ik-appid'] ?? null;
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Basic header presence check
|
||||
* ==========================================================
|
||||
*/
|
||||
if (empty($ikSign) || empty($ikAppId)) {
|
||||
if (!$ikSign || !$ikAppId) {
|
||||
http_response_code(400);
|
||||
progress_log('iKhokha webhook: missing IK-SIGN or IK-APPID');
|
||||
progress_log('iKhokha webhook: missing headers');
|
||||
exit('Missing headers');
|
||||
}
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Signature verification
|
||||
* HMAC_SHA256( path + raw_body, app_secret )
|
||||
* Signature verification (JS-equivalent)
|
||||
* ==========================================================
|
||||
*/
|
||||
$secret = $_ENV['IKHOKHA_APP_SECRET'] ?? null;
|
||||
$callbackUrl = $_ENV['IKHOKHA_CALLBACK_URL'] ?? null;
|
||||
$bypass = ($_ENV['IKHOKHA_BYPASS_SIGNATURE'] ?? 'false') === 'true';
|
||||
|
||||
if (empty($secret)) {
|
||||
if (!$secret || !$callbackUrl) {
|
||||
http_response_code(500);
|
||||
progress_log('iKhokha webhook: app secret not configured');
|
||||
exit('Server misconfigured');
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Debug logging (disable once stable)
|
||||
progress_log('--- iKhokha WEBHOOK DEBUG ---');
|
||||
progress_log('RAW BODY: ' . $raw);
|
||||
progress_log('IK-SIGN: ' . $ikSign);
|
||||
|
||||
$callbackUrl = $_ENV['IKHOKHA_CALLBACK_URL'] ?? null;
|
||||
$bypass = ($_ENV['IKHOKHA_BYPASS_SIGNATURE'] ?? 'false') === 'true';
|
||||
// Decode body so we can remove `text`
|
||||
$bodyArray = json_decode($raw, true);
|
||||
if (!is_array($bodyArray)) {
|
||||
http_response_code(400);
|
||||
exit('Invalid JSON');
|
||||
}
|
||||
|
||||
// iKhokha JS deletes `text`
|
||||
unset($bodyArray['text']);
|
||||
|
||||
// JS-style JSON (no escaped slashes)
|
||||
$jsonBody = json_encode($bodyArray, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
|
||||
// Now sign the SAME payload JS signs
|
||||
$payloadToSign = createPayloadToSign($callbackUrl, $jsonBody);
|
||||
|
||||
$expected = generateSignature($payloadToSign, $secret);
|
||||
|
||||
progress_log('JS PAYLOAD: ' . $payloadToSign);
|
||||
progress_log('EXPECTED SIGN: ' . $expected);
|
||||
progress_log('RECEIVED SIGN: ' . $ikSign);
|
||||
|
||||
if (!$bypass) {
|
||||
|
||||
if (empty($callbackUrl)) {
|
||||
http_response_code(500);
|
||||
progress_log('iKhokha webhook: callback URL not configured');
|
||||
exit('Server misconfigured');
|
||||
}
|
||||
|
||||
$expected = hash_hmac(
|
||||
'sha256',
|
||||
$callbackUrl . $raw,
|
||||
$_ENV['IKHOKHA_APP_SECRET']
|
||||
);
|
||||
|
||||
if (!hash_equals($expected, $ikSign)) {
|
||||
http_response_code(403);
|
||||
progress_log('iKhokha webhook: signature mismatch');
|
||||
progress_log('EXPECTED SIGN: ' . $expected);
|
||||
progress_log('RECEIVED SIGN: ' . $ikSign);
|
||||
// Audit signature mismatch
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog(null, 'IKHOKHA_SIGNATURE_MISMATCH', 'webhook', null, ['expected' => $expected, 'received' => $ikSign]);
|
||||
auditLog(null, 'IKHOKHA_SIGNATURE_MISMATCH', 'webhook', null, [
|
||||
'expected' => $expected,
|
||||
'received' => $ikSign
|
||||
]);
|
||||
}
|
||||
exit('Invalid signature');
|
||||
}
|
||||
@@ -95,20 +117,13 @@ if (!$bypass) {
|
||||
* ==========================================================
|
||||
*/
|
||||
$payload = json_decode($raw, true);
|
||||
|
||||
if (!is_array($payload)) {
|
||||
http_response_code(400);
|
||||
progress_log('iKhokha webhook: invalid JSON');
|
||||
exit('Invalid JSON');
|
||||
}
|
||||
$data = $payload['data'] ?? $payload;
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Extract data safely (iKhokha is inconsistent)
|
||||
* Extract fields safely
|
||||
* ==========================================================
|
||||
*/
|
||||
$data = $payload['data'] ?? $payload;
|
||||
|
||||
$externalTransactionID =
|
||||
$data['externalTransactionID']
|
||||
?? $data['externalTransactionId']
|
||||
@@ -127,11 +142,11 @@ $providerStatus =
|
||||
|
||||
progress_log('Parsed externalTransactionID: ' . $externalTransactionID);
|
||||
progress_log('Parsed providerPaymentId: ' . $providerPaymentId);
|
||||
progress_log('Parsed providerStatus: ' . print_r($providerStatus, true));
|
||||
progress_log('Parsed providerStatus: ' . $providerStatus);
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Locate local payment
|
||||
* Locate payment
|
||||
* ==========================================================
|
||||
*/
|
||||
$localPaymentId = null;
|
||||
@@ -146,16 +161,13 @@ if ($externalTransactionID) {
|
||||
WHERE payment_id = ?
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
if ($stmt) {
|
||||
$stmt->bind_param('s', $externalTransactionID);
|
||||
$stmt->execute();
|
||||
$res = $stmt->get_result();
|
||||
if ($row = $res->fetch_assoc()) {
|
||||
extract($row);
|
||||
$localPaymentId = $row['payment_id'];
|
||||
$booking_id = $row['booking_id'];
|
||||
$user_id = $row['user_id'];
|
||||
$description = $row['description'];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
@@ -168,16 +180,13 @@ if (!$localPaymentId && $providerPaymentId) {
|
||||
WHERE provider_payment_id = ?
|
||||
LIMIT 1"
|
||||
);
|
||||
|
||||
if ($stmt) {
|
||||
$stmt->bind_param('s', $providerPaymentId);
|
||||
$stmt->execute();
|
||||
$res = $stmt->get_result();
|
||||
if ($row = $res->fetch_assoc()) {
|
||||
extract($row);
|
||||
$localPaymentId = $row['payment_id'];
|
||||
$booking_id = $row['booking_id'];
|
||||
$user_id = $row['user_id'];
|
||||
$description = $row['description'];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
@@ -185,11 +194,6 @@ if (!$localPaymentId && $providerPaymentId) {
|
||||
|
||||
if (!$localPaymentId) {
|
||||
http_response_code(404);
|
||||
progress_log('iKhokha webhook: payment not found');
|
||||
progress_log(json_encode([$externalTransactionID, $providerPaymentId]));
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog(null, 'IKHOKHA_PAYMENT_NOT_FOUND', 'payment', null, ['externalTransactionID' => $externalTransactionID, 'providerPaymentId' => $providerPaymentId]);
|
||||
}
|
||||
exit('Payment not found');
|
||||
}
|
||||
|
||||
@@ -216,72 +220,58 @@ if ($update) {
|
||||
);
|
||||
$update->execute();
|
||||
$update->close();
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog($user_id, 'PAYMENT_PROVIDER_RESPONSE_SAVED', 'payment', null, ['payment_id' => $localPaymentId, 'provider_payment_id' => $providerPaymentId, 'provider_status' => $providerStatus]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ==========================================================
|
||||
* Normalize status and apply business logic
|
||||
* Business logic
|
||||
* ==========================================================
|
||||
*/
|
||||
$normalized = strtoupper(trim((string)$providerStatus));
|
||||
|
||||
if (in_array($normalized, ['PAID', 'SUCCESS', 'COMPLETED', 'SETTLED'], true)) {
|
||||
|
||||
// Mark payment as PAID
|
||||
$setPaid = $conn->prepare(
|
||||
$conn->prepare(
|
||||
"UPDATE payments SET status = 'PAID' WHERE payment_id = ?"
|
||||
);
|
||||
if ($setPaid) {
|
||||
$setPaid->bind_param('s', $localPaymentId);
|
||||
$setPaid->execute();
|
||||
$setPaid->close();
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog($user_id, 'PAYMENT_MARKED_PAID', 'payment', null, ['payment_id' => $localPaymentId]);
|
||||
}
|
||||
}
|
||||
)->bind_param('s', $localPaymentId)->execute();
|
||||
|
||||
// Booking or membership update
|
||||
if (!empty($booking_id)) {
|
||||
$upd = $conn->prepare(
|
||||
if ($booking_id) {
|
||||
$conn->prepare(
|
||||
"UPDATE bookings SET status = 'PAID' WHERE booking_id = ?"
|
||||
);
|
||||
if ($upd) {
|
||||
$upd->bind_param('i', $booking_id);
|
||||
$upd->execute();
|
||||
$upd->close();
|
||||
sendAdminNotification('4WDCSA.co.za - New Booking - '.getFullName($user_id) , 'We have received a payment for a new booking for '.$description.' from '.getFullName($user_id));
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog($user_id, 'BOOKING_PAYMENT_MARKED_PAID', 'bookings', $booking_id, ['payment_id' => $localPaymentId]);
|
||||
}
|
||||
}
|
||||
)->bind_param('i', $booking_id)->execute();
|
||||
} else {
|
||||
$upd = $conn->prepare(
|
||||
"UPDATE membership_fees
|
||||
SET payment_status = 'PAID'
|
||||
WHERE payment_id = ?"
|
||||
);
|
||||
if ($upd) {
|
||||
$upd->bind_param('s', $localPaymentId);
|
||||
$upd->execute();
|
||||
$upd->close();
|
||||
sendAdminNotification('4WDCSA.co.za - Membership Payment Received - '.getFullName($user_id) , 'A Membership Payment has been received from '.getFullName($user_id));
|
||||
if (function_exists('auditLog')) {
|
||||
auditLog($user_id, 'MEMBERSHIP_PAYMENT_MARKED_PAID', 'membership_fees', null, ['payment_id' => $localPaymentId]);
|
||||
}
|
||||
}
|
||||
$conn->prepare(
|
||||
"UPDATE membership_fees SET payment_status = 'PAID' WHERE payment_id = ?"
|
||||
)->bind_param('s', $localPaymentId)->execute();
|
||||
}
|
||||
|
||||
// Send confirmation email
|
||||
if (!empty($user_id)) {
|
||||
sendPaymentConfirmation(
|
||||
getEmail($user_id),
|
||||
getFullName($user_id),
|
||||
$description
|
||||
);
|
||||
}
|
||||
sendPaymentConfirmation(
|
||||
getEmail($user_id),
|
||||
getFullName($user_id),
|
||||
$description
|
||||
);
|
||||
|
||||
//generate $message for admin payment confirmation with payment details
|
||||
$message = "Payment Confirmation\n\n";
|
||||
$message .= "Payment ID: " . $localPaymentId . "\n";
|
||||
$message .= "Amount: " . getPaymentAmount($localPaymentId) . "\n";
|
||||
$message .= "Status: PAID\n";
|
||||
$message .= "Description: " . $description . "\n";
|
||||
$message .= "Thank you.\n";
|
||||
$subject = "4WDCSA.co.za Payment Confirmation for Payment ID: " . $localPaymentId;
|
||||
progress_log('Payment confirmation sent for payment ID: ' . $localPaymentId);
|
||||
|
||||
sendEmail(
|
||||
$_ENV['FINANCE_EMAIL'],
|
||||
$subject,
|
||||
nl2br($message)
|
||||
);
|
||||
sendEmail(
|
||||
'chrispintoza@gmail.com',
|
||||
$subject,
|
||||
nl2br($message)
|
||||
);
|
||||
sendAdminNotification($subject, nl2br($message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -858,6 +858,45 @@ function createIkhokhaPayment($payment_id, $amount, $description, $publicRef)
|
||||
return $resp;
|
||||
}
|
||||
|
||||
function getIkhokhaTransactionHistory($startDate, $endDate,)
|
||||
{
|
||||
|
||||
// Base requester URL: prefer explicit env var, otherwise build from request
|
||||
$endpoint = "https://api.ikhokha.com/public-api/v1/api/payments/history?startDate=".$startDate."&endDate=".$endDate;
|
||||
// $endpoint = "https://api.ikhokha.com/public-api/v1/api/payments/history?startDate=2024-02-01&endDate=2026-03-07";
|
||||
$appID = $_ENV['IKHOKHA_APP_ID'];
|
||||
progress_log($appID, "IKHOKHA App ID");
|
||||
$appSecret = $_ENV['IKHOKHA_APP_SECRET'];
|
||||
|
||||
// $stringifiedBody = json_encode($requestBody);
|
||||
$payloadToSign = createPayloadToSign($endpoint, null);
|
||||
progress_log($payloadToSign, "IKHOKHA Payload to Sign");
|
||||
|
||||
$ikSign = generateSignature($payloadToSign, $appSecret);
|
||||
progress_log($ikSign, "IKHOKHA Signature");
|
||||
|
||||
// Initialize cURL session
|
||||
$ch = curl_init($endpoint);
|
||||
// Set cURL options
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
|
||||
// curl_setopt($ch, CURLOPT_POSTFIELDS, $stringifiedBody);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, [
|
||||
"Content-Type: application/json",
|
||||
"IK-APPID: $appID",
|
||||
"IK-SIGN: $ikSign"
|
||||
]);
|
||||
// Execute cURL session
|
||||
$response = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
|
||||
// Decode and output the response
|
||||
$resp = json_decode($response, true);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
function escapeString($str) {
|
||||
$escaped = preg_replace(['/[\\"\'\"]/u', '/\x00/'], ['\\\\$0', '\\0'], (string)$str);
|
||||
$cleaned = str_replace('\/', '/', $escaped);
|
||||
@@ -879,6 +918,20 @@ function generateSignature($payloadToSign, $secret) {
|
||||
return hash_hmac('sha256', $payloadToSign, $secret);
|
||||
}
|
||||
|
||||
function getPaymentAmount($localPaymentId) {
|
||||
$conn = openDatabaseConnection();
|
||||
$stmt = $conn->prepare("SELECT amount FROM payments WHERE payment_id = ? LIMIT 1");
|
||||
$stmt->bind_param("s", $localPaymentId);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($row = $result->fetch_assoc()) {
|
||||
return $row['amount'];
|
||||
} else {
|
||||
return false; // Payment not found
|
||||
}
|
||||
}
|
||||
|
||||
function processMembershipPayment($payment_id, $amount, $description)
|
||||
{
|
||||
$conn = openDatabaseConnection();
|
||||
|
||||
@@ -1 +1 @@
|
||||
Database Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directory
|
||||
Database Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directoryDatabase Connection Error: No such file or directory
|
||||
Reference in New Issue
Block a user