Changes on auth token in vendor payouts

This commit is contained in:
jouls 2024-03-26 10:10:44 +08:00
parent 00bcc4441f
commit d941237b30
2 changed files with 34 additions and 20 deletions

View File

@ -1271,7 +1271,7 @@ function simpleVendorsWithProducts()
}
} */
function getVendorbyId($id, $token)
function getVendorbyId($id)
{
$url = "https://" . $_SESSION["data_endpoint"] . "/api/v1/vendors/$id";
$curl = curl_init();
@ -1286,9 +1286,7 @@ function getVendorbyId($id, $token)
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array(
'X-Api-Key: {{apiKey}}',
'Content-Type: application/json',
'Authorization: Bearer ' . $token
'X-Api-Key: {{apiKey}}'
),
));
$response = curl_exec($curl);

View File

@ -3,25 +3,41 @@ include "functions.php";
if ($_SESSION["userId"] <> "") {
$_SESSION["isLoggedIn"] = true;
// $customer_data = getCustomerbyLoginId($_SESSION["userId"]);
$vendorLoginId = searchVendorbyLoginId($_SESSION["userId"]);
$vendorLoginIdjson = json_decode($vendorLoginId, true);
if (isset($vendorLoginIdjson['results'][0])) {
$vendorData = $vendorLoginIdjson['results'][0];
$vendorId = $vendorData['_id'];
$_SESSION["LoggedInVendorId"] = $vendorId;
}
// $vendor= getVendorbyId($vendorLoginIdjson['results'][0]['_id']);
// // var_dump($vendor);
// $array = json_decode($vendor,true);
// var_dump($array);
$authToken = $_SESSION['token'];
$response = getAllPayout($authToken);
$vendorPayoutData = json_decode($response, true);
} else {
$_SESSION["isLoggedIn"] = false;
header("location: login.php");
}
// $customer_data = getCustomerbyLoginId($_SESSION["userId"]);
$vendorLoginId = searchVendorbyLoginId($_SESSION["userId"]);
$vendorLoginIdjson = json_decode($vendorLoginId, true);
if (isset($vendorLoginIdjson['results'][0])) {
$vendorData = $vendorLoginIdjson['results'][0];
$vendorId = $vendorData['_id'];
$_SESSION["LoggedInVendorId"] = $vendorId;
}
$token = $_SESSION["token"];
$token_parts = explode(".", $token);
$token_payload = base64_decode($token_parts[1]);
$token_data = json_decode($token_payload);
$expiration_time = $token_data->exp;
$issued_at_time = $token_data->iat;
$renewal_time = $issued_at_time + 3300;
if (time() >= $renewal_time) {
$token = loginRenew($_SESSION["email"], $_SESSION["password"], $token);
$_SESSION["token"] = $token;
}
$authToken = $_SESSION['token'];
$response = getAllPayout($authToken);
$vendorPayoutData = json_decode($response, true);
?>
<!DOCTYPE html>
<html lang="en">
@ -163,7 +179,7 @@ if ($_SESSION["userId"] <> "") {
Receive Payout on or before: Wed, Mar 20, 2024
</div> -->
<div class="text-sm">
<?php $vendorResponse = getVendorbyId( $vendorId, $authToken);
<?php $vendorResponse = getVendorbyId($vendorId);
$vendorInformation = json_decode($vendorResponse, true);
$bankAccountNumber = $vendorInformation['bank_acount_details'][0]['bank_account_number'];
$bankNumEnding = substr($bankAccountNumber, -3);