From d4584e6cf1c61dc8512aafca84a8d4a46be677b9 Mon Sep 17 00:00:00 2001 From: Jun Barroga Date: Mon, 25 Mar 2024 18:03:49 +0800 Subject: [PATCH] admin payout --- admin/config.php | 3 +- admin/payout_deposit_action.php | 24 ++++++ admin/vendor-profile.php | 135 ++++++++++++++++++++++++++------ functions.php | 122 +++++++++++++++++++++++++++++ 4 files changed, 257 insertions(+), 27 deletions(-) create mode 100644 admin/payout_deposit_action.php diff --git a/admin/config.php b/admin/config.php index dbb3019..d51d6b8 100644 --- a/admin/config.php +++ b/admin/config.php @@ -1,8 +1,9 @@ \ No newline at end of file diff --git a/admin/vendor-profile.php b/admin/vendor-profile.php index c764e21..2c2df12 100644 --- a/admin/vendor-profile.php +++ b/admin/vendor-profile.php @@ -2,29 +2,35 @@ include "../functions.php"; if(isset($_SESSION["vendorId"])){ - if(isset($_GET["id"])){ - $_SESSION["vendorId"]=$_GET["id"]; - } + if(isset($_GET["id"])){ + $_SESSION["vendorId"]=$_GET["id"]; + } } else { - if(isset($_GET["id"])){ - $_SESSION["vendorId"]=$_GET["id"]; - } else { - header("location: vendor-card.php"); - } + if(isset($_GET["id"])){ + $_SESSION["vendorId"]=$_GET["id"]; + } else { + header("location: vendor-card.php"); + } } + $_SESSION["url"] = $_SERVER['REQUEST_URI']; + + if ($_SESSION["userId"] <> "") { $_SESSION["isLoggedIn"] = true; - //$customer_data = getCustomerbyLoginId($_SESSION["userId"]); + } else { $_SESSION["isLoggedIn"] = false; - header("location: login.php"); + header("location: login.php"); } + if($_SESSION["user_type"]!="admin"){ - header("location: login.php?alert=Only admins allowed here!"); + header("location: login.php?alert=Only admins allowed here!"); } + $vendor = getVendorbyId($_SESSION["vendorId"]); $array = json_decode($vendor,true); + $selectedBankAccount = null; foreach ($array['bank_acount_details'] as $bankAccount) { if ($bankAccount['bank_payout']) { @@ -37,9 +43,9 @@ if ($selectedBankAccount === null && !empty($array['bank_acount_details'])) { } $selectedBankAccountJSON = json_encode($selectedBankAccount); + $shopOrders = getOrderbyVendorId($_SESSION["vendorId"]); $vendorOrderss = json_decode($shopOrders); - if (is_array($vendorOrderss)) { $vendorOrders = json_decode($shopOrders); } elseif (is_object($vendorOrderss) && property_exists($vendorOrderss, 'message')) { @@ -47,7 +53,40 @@ if (is_array($vendorOrderss)) { } else { echo "Unknown type or no 'message' property found."; } + +$allPayouts = getAllPayout($_SESSION["token"]); +$vendorPayouts = json_decode($allPayouts,true); + + +$filteredPayouts = []; +foreach ($vendorPayouts as $payout) { + if ($payout['vendor_details'][0]['vendor_id'] == $_SESSION["vendorId"]) { + $filteredPayouts[] = $payout; + } +} + +$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; +} +// $token = loginRenew($_SESSION["email"], $_SESSION["password"], $token); +// $_SESSION["token"] = $token; + + ?> + @@ -150,6 +189,18 @@ if (is_array($vendorOrderss)) {
Contact Information
+ "; +//echo date('Y-m-d H:i:s', $expiration_time) . "
"; +//echo date('Y-m-d H:i:s', $renewal_time) . "
"; +//echo date('Y-m-d H:i:s', time()) . "
"; + + +?> +
+
+ +

Email address

Phone Number

@@ -311,10 +362,10 @@ if (is_array($vendorOrderss)) { // feesDeductionAdjustment += individualFee; var breakdownItem = { Type: "Payment", - "Transaction date": row.cells[6].innerText, - "Gross Amount": amount, + Transaction_date: row.cells[6].innerText, + Gross_Amount: amount, Fee: individualFee, - "Net Amount": amount - individualFee, + Net_Amount: amount - individualFee, Description: row.cells[5].querySelector("a").innerText, orderId: orderId }; @@ -432,14 +483,21 @@ if (is_array($vendorOrderss)) { + - ₱1,230 - EastWest - **** **** 1234 - Jon-Jon Manaay - Oct 20, 2018 + + + + + - Deposited + - +
@@ -518,7 +579,7 @@ if (is_array($vendorOrderss)) {
-
+
@@ -894,6 +955,12 @@ if (is_array($vendorOrderss)) {
+
+ + + + +
@@ -901,7 +968,23 @@ if (is_array($vendorOrderss)) {
-
+ + + + + + + + + + + + + + +
Bank Name
Account Number
Account Name
+ +
diff --git a/functions.php b/functions.php index ed25bb6..ad03bfd 100644 --- a/functions.php +++ b/functions.php @@ -360,6 +360,36 @@ function login($username, $password) $token = json_decode($response, true); return $token["token"]; } + +function loginRenew($username, $password, $token) +{ + $curl = curl_init(); + $array = array( + "username" => $username, + "password" => $password + ); + $json = json_encode($array); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://" . $_SESSION["data_endpoint"] . "/api/v1/login", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_POSTFIELDS => $json, + CURLOPT_HTTPHEADER => array( + 'Content-Type: application/json', + 'X-Api-Key: {{apiKey}}' + ), + )); + $response = curl_exec($curl); + curl_close($curl); + $token = json_decode($response, true); + return $token["token"]; +} + function forgot_password($email) { if ($_SESSION["is_test"] == true && $_SESSION["test_email_rcpt"] != "") { @@ -1858,3 +1888,95 @@ function getAllPayout($token) return $response; } + +function getPayout($token, $id) +{ + $curl = curl_init(); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://" . $_SESSION["data_endpoint"] . "/api/v1/payouts/{$id}", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_MAXREDIRS => 10, + CURLOPT_TIMEOUT => 0, + CURLOPT_FOLLOWLOCATION => true, + 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 + ), + )); + $response = curl_exec($curl); + curl_close($curl); + + return $response; +} + + +function editOrderPayoutStatus($token, $orderIds) +{ + $curl = curl_init(); + foreach ($orderIds as $orderId) { + $data = array( + 'payout_status' => array( + 'payout_id' => $orderId, + 'status' => 'Deposited' + ) + ); + + $params3 = json_encode($data); + curl_setopt_array($curl, array( + CURLOPT_URL => "https://" . $_SESSION["data_endpoint"] . "/api/v1/orders/" . $orderId, + 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 => $params3, + CURLOPT_HTTPHEADER => array( + 'Accept: application/json', + 'Content-Type: application/json', + 'Authorization: Bearer ' . $token + ), + )); + $response = curl_exec($curl); + } + curl_close($curl); + +} + + +function updatePayout($token, $payoutId) +{ + $curl = curl_init(); + $data = array( + 'status' => "Deposited", + ); + + $params = json_encode($data); + + curl_setopt_array($curl, array( + CURLOPT_URL => "https://" . $_SESSION["data_endpoint"] . "/api/v1/payouts/" . $payoutId, // Corrected URL to include $payoutId + 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 => $params, // Send the payload data + CURLOPT_HTTPHEADER => array( + 'X-Api-Key: {{apiKey}}', // Make sure to replace {{apiKey}} with an actual API key if needed + 'Content-Type: application/json', + 'Authorization: Bearer ' . $token + ), + )); + + $response = curl_exec($curl); + curl_close($curl); + + return $response; +}