diff --git a/functions.php b/functions.php index 41d67cc..dbfd39d 100644 --- a/functions.php +++ b/functions.php @@ -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); diff --git a/vendor-payouts.php b/vendor-payouts.php index 5261c75..43b27ad 100644 --- a/vendor-payouts.php +++ b/vendor-payouts.php @@ -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); + ?> @@ -163,7 +179,7 @@ if ($_SESSION["userId"] <> "") { Receive Payout on or before: Wed, Mar 20, 2024 -->
-