Repository navigation
Expand file tree
/
Copy pathpayment.php
More file actions
236 lines (207 loc) · 10.1 KB
/
Copy pathpayment.php
File metadata and controls
236 lines (207 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
// Start session at the beginning of the file
session_start();
include 'conn.php';
// Check if user is logged in
if (!isset($_SESSION['user_id'])) {
header("Location: signin.php");
exit();
}
// Set a cookie for the payment session
$cookie_name = "payment_session";
$cookie_value = uniqid();
$cookie_expiry = time() + (86400 * 30); // 30 days
setcookie($cookie_name, $cookie_value, $cookie_expiry, "/");
// Get project ID from URL
$project_id = isset($_GET['project_id']) ? intval($_GET['project_id']) : 0;
// Initialize variables with default values
$project_name = 'Project';
$developer_name = 'Developer';
$total_bid = 0;
$project_duration = 'Not specified';
$released_amount = 0;
// Fetch project details from database if project_id is provided
if ($project_id > 0) {
// Get project details
$sql = "SELECT p.*, u.name as client_name, u.user_id as client_id,
pa.freelancer_id, pa.bid_amount as winning_bid_amount,
f.name as freelancer_name
FROM projects p
JOIN users u ON p.user_id = u.user_id
JOIN project_assignments pa ON p.id = pa.project_id
JOIN users f ON pa.freelancer_id = f.user_id
WHERE p.id = ? AND pa.is_accepted = 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $project_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result && $result->num_rows > 0) {
$project = $result->fetch_assoc();
// Set variables with actual project data
$project_name = $project['title'];
$developer_name = $project['freelancer_name'];
$total_bid = $project['winning_bid_amount'];
$project_duration = $project['duration'] ?? '3 Months';
// Check if there are any previous payments
$payment_sql = "SELECT SUM(amount) as total_released
FROM project_payments
WHERE project_id = ?";
$payment_stmt = $conn->prepare($payment_sql);
$payment_stmt->bind_param("i", $project_id);
$payment_stmt->execute();
$payment_result = $payment_stmt->get_result();
if ($payment_result && $payment_result->num_rows > 0) {
$payment_data = $payment_result->fetch_assoc();
$released_amount = $payment_data['total_released'] ?? 0;
}
// Store in session for later use
$_SESSION['current_project'] = $project_id;
$_SESSION['project_name'] = $project_name;
$_SESSION['developer_name'] = $developer_name;
$_SESSION['total_bid'] = $total_bid;
$_SESSION['project_duration'] = $project_duration;
$_SESSION['released_amount'] = $released_amount;
} else {
// Project not found or user doesn't have access
header("Location: home_client.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Release Payment - BidProHub</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
<!-- Navbar -->
<nav class="bg-indigo-900 text-white py-4">
<div class="w-8/12 mx-auto px-6 flex justify-between items-center">
<!-- Logo and Tagline Section (Centering the Logo and Tagline) -->
<div class="flex flex-col items-center">
<a href="#" class="text-2xl font-semibold">BidProHub</a>
<p class="text-sm mt-1 text-gray-200 italic">Where Ambitions Meet Opportunities</p>
</div>
<!-- Navigation Links -->
<div class="hidden md:flex space-x-8">
<a href="C:/wamp64/www/BidProHub/index.html" class="text-md font-light hover:text-white text-blue-200 transition duration-300">Home</a>
<a href="" class="text-md font-light hover:text-white text-blue-200 transition duration-300">Post Projects</a>
<a href="" class="text-md font-light hover:text-white text-blue-200 transition duration-300">Find Work</a>
<a href="" class="text-md font-light hover:text-white text-blue-200 transition duration-300">About Us</a>
</div>
<!-- Mobile Menu Icon (Hamburger) -->
<div class="md:hidden">
<button id="mobile-menu-button" class="text-white focus:outline-none">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" class="w-6 h-6">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
</div>
</div>
</nav>
<!-- Payment Release Section -->
<section class="max-w-3xl mx-auto my-10 bg-white p-8 rounded-lg shadow-lg">
<h1 class="text-2xl font-bold text-indigo-700 mb-4">Release Payment to Developer</h1>
<!-- Project Summary -->
<div class="bg-gray-100 p-4 rounded-lg mb-6">
<h2 class="text-lg font-semibold text-gray-800">Project Details</h2>
<p class="text-gray-700"><strong>Project:</strong> <?php echo $_SESSION['project_name'] ?? 'AI-Based E-commerce Recommendation System'; ?></p>
<p class="text-gray-700"><strong>Developer:</strong> <?php echo $_SESSION['developer_name'] ?? 'John Doe'; ?></p>
<p class="text-gray-700"><strong>Total Bid Amount:</strong> ₹<span id="totalBid"><?php echo $_SESSION['total_bid'] ?? '12000'; ?></span></p>
<p class="text-gray-700"><strong>Duration:</strong> <span id="duration"><?php echo $_SESSION['project_duration'] ?? '3 Months'; ?></span></p>
</div>
<!-- Fund Release Form -->
<form id="releasePaymentForm" class="space-y-6">
<!-- Amount to Release -->
<div>
<label class="block text-gray-700 font-medium">Enter Amount to Release</label>
<div class="w-full p-3 border border-gray-300 rounded-lg bg-gray-50">
₹<?php echo number_format($_SESSION['total_bid']); ?>
</div>
<input type="hidden" id="releaseAmount" value="<?php echo $_SESSION['total_bid']; ?>">
</div>
<!-- Card Details -->
<div>
<label class="block text-gray-700 font-medium">Cardholder Name</label>
<input type="text" id="cardName" placeholder="Enter name on card" class="w-full p-3 border border-gray-300 rounded-lg" required>
</div>
<div>
<label class="block text-gray-700 font-medium">Card Number</label>
<input type="text" id="cardNumber" placeholder="1234 5678 9012 3456" class="w-full p-3 border border-gray-300 rounded-lg" required>
</div>
<div class="flex space-x-4">
<div class="w-1/2">
<label class="block text-gray-700 font-medium">Expiry Date</label>
<input type="text" id="expiryDate" placeholder="MM/YY" class="w-full p-3 border border-gray-300 rounded-lg" required>
</div>
<div class="w-1/2">
<label class="block text-gray-700 font-medium">CVV</label>
<input type="text" id="cvv" placeholder="123" class="w-full p-3 border border-gray-300 rounded-lg" required>
</div>
</div>
<!-- Submit Button -->
<button type="button" onclick="releaseFunds()" class="w-full bg-green-600 text-white py-3 rounded-lg hover:bg-green-700">
Release Funds
</button>
</form>
</section>
<script>
let totalBid = <?php echo $total_bid; ?>; // Total project cost from database
let releasedAmount = <?php echo $released_amount; ?>; // Track released amount (kept for validation)
let projectId = <?php echo $project_id; ?>; // Project ID for the payment
function releaseFunds() {
let amountToRelease = parseFloat(document.getElementById("releaseAmount").value);
let cardNumber = document.getElementById("cardNumber").value;
let expiryDate = document.getElementById("expiryDate").value;
let cvv = document.getElementById("cvv").value;
if (!amountToRelease || amountToRelease <= 0) {
alert("Enter a valid amount.");
return;
}
if (!cardNumber || !expiryDate || !cvv) {
alert("Please enter valid card details.");
return;
}
// Update session variable with AJAX
fetch('process_payment.php', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
credentials: 'include', // Add this line to include cookies
body: `project_id=${projectId}&amount=${amountToRelease}`
})
.then(response => response.json())
.then(data => {
if(data.success) {
releasedAmount += amountToRelease;
// Removed updating the display of released amount
alert(`₹${amountToRelease} successfully released to the developer!`);
// Redirect back to project page if payment is complete
if (releasedAmount >= totalBid) {
window.location.href = `project_communication.php?id=${projectId}&payment=complete`;
}
} else {
alert('Error processing payment: ' + (data.message || 'Unknown error'));
}
})
.catch(error => {
console.error('Error:', error);
alert('Error processing payment. Please try again.');
});
// You can integrate a real payment API like Stripe here.
}
</script>
<script>
window.addEventListener('beforeunload', function() {
fetch('destroy_session.php', {
method: 'POST',
keepalive: true
});
});
</script>
</body>
</html>