changes on kyc functions

This commit is contained in:
jouls 2024-03-07 14:23:47 +08:00
parent 77218b76a8
commit c15cfc8b76
7 changed files with 170 additions and 116 deletions

View File

@ -182,11 +182,11 @@ function get_kyc()
return $response;
}
function get_kyc_info($IDuser)
function get_kyc_info($IDkyc)
{
$curl = curl_init();
//$url = "https://testapi.obpay.online/api/users/id/$email";
$url = "https://testapi.obpay.online/api/kycs/$IDuser";
$url = "https://testapi.obpay.online/api/kycs/$IDkyc";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://testapi.obpay.online/api/users/egalang@premiummegastructures.com',
@ -207,13 +207,13 @@ function get_kyc_info($IDuser)
return $response;
}
function reject_kyc($IDuser)
function reject_kyc($IDkyc, $IDuser)
{
// First cURL request to reject KYC
$curl = curl_init();
$url = "https://testapi.obpay.online/api/kycs/update/$IDuser";
curl_setopt($curl, CURLOPT_URL, $url);
$url = "https://testapi.obpay.online/api/kycs/update/$IDkyc";
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://testapi.obpay.online/api/users/645a0c93008258b5e9a2cd20/sub',
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
@ -227,18 +227,43 @@ function reject_kyc($IDuser)
'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys'
),
));
$response = curl_exec($curl);
$response1 = curl_exec($curl);
curl_close($curl);
return $response;
// Second cURL request to update user's KYC status
$response1 = curl_exec($curl);
curl_close($curl);
$curl2 = curl_init();
$url2 = "https://testapi.obpay.online/api/users/$IDuser/sub";
$data = '{"kycStatus":"new", "kycRef":"' . $IDkyc . '"}';
curl_setopt_array($curl2, array(
CURLOPT_URL => $url2,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys'
),
));
$response2 = curl_exec($curl2);
curl_close($curl2);
// Return an array containing both responses
return array($response1, $response2);
}
function accept_kyc($IDuser)
function accept_kyc($IDkyc, $IDuser)
{
$curl = curl_init();
$url = "https://testapi.obpay.online/api/kycs/update/$IDuser";
curl_setopt($curl, CURLOPT_URL, $url);
$url = "https://testapi.obpay.online/api/kycs/update/$IDkyc";
curl_setopt_array($curl, array(
//CURLOPT_URL => 'https://testapi.obpay.online/api/users/645a0c93008258b5e9a2cd20/sub',
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
@ -252,9 +277,31 @@ function accept_kyc($IDuser)
'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys'
),
));
$response = curl_exec($curl);
$response1 = curl_exec($curl);
curl_close($curl);
return $response;
$curl2 = curl_init();
$url2 = "https://testapi.obpay.online/api/users/$IDuser/sub";
$data = '{"kycStatus":"validated", "kycRef":"' . $IDkyc . '"}';
curl_setopt_array($curl2, array(
CURLOPT_URL => $url2,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'PATCH',
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY0MjRkOTYyZmNiMWU0ZjgyNDU0NmM4OSIsImlhdCI6MTY4MDEzNzU2NH0.9EHOeaXkYS5mGYG-g-_tgRpw338JzxECLec9cU2zhys'
),
));
$response2 = curl_exec($curl2);
curl_close($curl2);
return array($response1, $response2);
}

View File

@ -1,11 +1,11 @@
<?php
include '../functions-test.php';
if (isset($_GET['userID'])) {
$userID = $_GET['userID'];
if (isset($_GET['kycID'])) {
$kycID = $_GET['kycID'];
// Delete KYC info
$response = delete_kyc_info($userID);
$response = delete_kyc_info($kycID);
// Check if deletion was successful
if ($response) {

80
users/edit-kyc.css Normal file
View File

@ -0,0 +1,80 @@
body {
justify-content: space-between;
margin: 0;
}
h1 {
margin: 0;
}
.mainContainer {
display: flex;
justify-content: center;
padding-left: 10rem;
padding-right: 10rem;
}
.section {
width: 45%;
padding: 20px;
box-sizing: border-box;
}
.section h2 {
margin-bottom: 10px;
}
.form-container {
margin-bottom: 20px;
padding-top: 0px;
}
form {
width: 100%;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 8px;
box-sizing: border-box;
margin-bottom: 10px;
}
.image-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
img {
width: 48%;
height: auto;
max-height: 200px;
object-fit: cover;
margin-bottom: 10px;
}
.checkboxFormContainer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.checkbox-container {
margin-bottom: 10px;
/* Adjust the margin as needed */
}
.checkbox-label {
display: block;
}

View File

@ -5,86 +5,7 @@
<?php include '../header.php'; ?>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
justify-content: space-between;
margin: 0;
}
h1 {
margin: 0;
}
.mainContainer {
display: flex;
justify-content: center;
padding-left: 10rem;
padding-right: 10rem;
}
.section {
width: 45%;
padding: 20px;
box-sizing: border-box;
}
.section h2 {
margin-bottom: 10px;
}
.form-container {
margin-bottom: 20px;
padding-top: 0px;
}
form {
width: 100%;
}
label {
display: block;
margin-bottom: 5px;
}
input {
width: 100%;
padding: 8px;
box-sizing: border-box;
margin-bottom: 10px;
}
.image-container {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
img {
width: 48%;
height: auto;
max-height: 200px;
object-fit: cover;
margin-bottom: 10px;
}
.checkboxFormContainer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.checkbox-container {
margin-bottom: 10px;
/* Adjust the margin as needed */
}
.checkbox-label {
display: block;
}
</style>
<link rel="stylesheet" href="edit-kyc.css">
</head>
<body>
@ -98,9 +19,9 @@
<div class="mainContainer">
<div class="section form-container">
<?php
$IDuser = isset($_GET['userID']) ? $_GET['userID'] : '';
$IDkyc = isset($_GET['kycID']) ? $_GET['kycID'] : '';
include '../functions-test.php';
$response = get_kyc_info($IDuser);
$response = get_kyc_info($IDkyc);
$array = json_decode($response, true);
// Check if the decoding was successful
@ -121,6 +42,9 @@
<div class="form-container">
<fieldset disabled>
<form>
<label for="email">USER ID:</label>
<input class="form-control" type="text" id="email" name="kycID" value="<?php echo $array['userRef']['_id']; ?>" readonly>
<label for="fullName">Full Name:</label>
<input class="form-control" type="text" id="fullName" name="fullName" value="<?php echo $array['userRef']['fName'] . ' ' . $array['userRef']['lName']; ?>" readonly>
@ -156,6 +80,8 @@
<div class="form-container">
<form>
<fieldset disabled>
<label for="email">KYC ID</label>
<input class="form-control" type="text" id="email" name="kycID" value="<?php echo $array['_id']; ?>" readonly>
<label for="additionalFullName">Full Name:</label>
<input class="form-control" type="text" id="additionalFullName" name="additionalFullName" value="<?php echo $array['full_name']; ?>" readonly>
@ -203,8 +129,8 @@
<div class="form-container">
<h3>Change the status?</h3>
<button type="button" class="btn btn-danger" id="rejectButton" onclick="window.location.href='update-kyc.php?userID=<?php echo $IDuser; ?>&isAccepted=false';">Reject</button>
<button type="button" class="btn btn-success" id="acceptButton" onclick="handleKycAction('<?php echo $IDuser; ?>', true);" disabled>Accept</button>
<button type="button" class="btn btn-danger" id="rejectButton" onclick="window.location.href='update-kyc.php?kycID=<?php echo $IDkyc; ?>&userID=<?php echo $array['userRef']['_id']; ?>&isAccepted=false';">Reject</button>
<button type="button" class="btn btn-success" id="acceptButton" onclick="handleKycAction('<?php echo $IDkyc; ?>', '<?php echo $array['userRef']['_id']; ?>', true);" disabled>Accept</button>
</div>
</form>
</div>
@ -223,15 +149,15 @@
checkbox.addEventListener('change', handleCheckboxChange);
});
function handleKycAction(userID, isAccepted) {
function handleKycAction(kycID, userID, isAccepted) {
if (isAccepted) {
// Handle the logic for accept
// You may call acceptFunction or perform other actions
window.location.href = 'update-kyc.php?userID=' + userID + '&isAccepted=true';
window.location.href = 'update-kyc.php?kycID=' + kycID + '&userID=' + userID + '&isAccepted=true';
} else {
// Handle the logic for reject
// Redirect to update-kyc.php with the additional parameter
window.location.href = 'update-kyc.php?userID=' + userID + '&isAccepted=false';
window.location.href = 'update-kyc.php?kycID=' + kycID + '&userID=' + userID + '&isAccepted=false';
}
}
</script>

View File

@ -1,3 +1,2 @@
<?php
header("location: users-test.php");
?>
header("location: users-test.php");

View File

@ -5,14 +5,16 @@
include '../functions-test.php';
// Check if the user ID and isAccepted parameters are set in the URL parameters
if (isset($_GET['userID'], $_GET['isAccepted'])) {
if (isset($_GET['kycID'], $_GET['userID'], $_GET['isAccepted'])) {
$kycID = $_GET['kycID'];
$userID = $_GET['userID'];
$isAccepted = ($_GET['isAccepted'] === 'true');
// Call the appropriate function based on isAccepted value
echo "KYC ID: $kycID, User ID: $userID, Is Accepted: $isAccepted";
//Call the appropriate function based on isAccepted value
if ($isAccepted) {
// If isAccepted is true, call accept_kyc function
if (accept_kyc($userID)) {
if (accept_kyc($kycID, $userID)) {
// If accept_kyc is successful, redirect to users-kyc.php
header('Location: users-kyc.php');
exit();
@ -21,7 +23,7 @@ if (isset($_GET['userID'], $_GET['isAccepted'])) {
}
} else {
// If isAccepted is false, call reject_kyc function
if (reject_kyc($userID)) {
if (reject_kyc($kycID, $userID)) {
// If reject_kyc is successful, redirect to users-kyc.php
header('Location: users-kyc.php');
exit();

View File

@ -21,9 +21,9 @@ $user_id = $_SESSION['user_id'];
});
});
function confirmDelete(userID) {
function confirmDelete(kycID) {
if (confirm("Are you sure you want to delete this KYC record?")) {
window.location.href = 'delete-kyc.php?userID=' + userID;
window.location.href = 'delete-kyc.php?kycID=' + kycID;
}
}
</script>
@ -74,7 +74,7 @@ $user_id = $_SESSION['user_id'];
<thead>
<tr>
<th width='1'>User ID</th>
<th>Reference Number</th>
<th>KYC ID</th>
<th>Name</th>
<th>Date of Birth</th>
<th>ID Number</th>
@ -86,14 +86,14 @@ $user_id = $_SESSION['user_id'];
<?php
foreach ($array as $x => $val) {
echo "<tr>";
echo "<td>" . $val['_id'] . "</td>";
echo "<td>" . $val['userRef'] . "</td>";
echo "<td>" . $val['_id'] . "</td>";
echo "<td>" . $val['full_name'] . "</td>";
echo "<td>" . $val['date_of_birth'] . "</td>";
echo "<td>" . $val['id_num'] . "</td>";
echo "<td>" . $val['status'] . "</td>";
echo "<td>" . $val['status'] . "</td> ";
echo "<td>" .
"<button class='btn btn-info' onclick=location.href='edit-kyc.php?userID=" . $val['_id'] . "'>Edit</button>" .
"<button class='btn btn-info' onclick=location.href='edit-kyc.php?kycID=" . $val['_id'] . "'>Edit</button>" .
"<button class='btn btn-default' onclick='confirmDelete(\"" . $val['_id'] . "\")'>Delete</button>" .
"</td>";
echo "</tr>";