-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpayment_method.php
More file actions
188 lines (165 loc) · 7.69 KB
/
payment_method.php
File metadata and controls
188 lines (165 loc) · 7.69 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
<?php
include("header.php");
// print_r($_REQUEST);
$user_id = $_SESSION['id'];
$savedAddresses = [];
$totalQuantity = 0;
$grandTotal = 0;
// $call = showCart($user_id);
// Fetch cart details for the user
$cartQuery = "SELECT c.quantity, p.price FROM cart c INNER JOIN product p ON c.p_id = p.p_id WHERE c.u_id = '$user_id'";
$cartResult = mysqli_query($conn, $cartQuery);
if (mysqli_num_rows($cartResult) > 0) {
while ($cartRow = mysqli_fetch_assoc($cartResult)) {
$totalQuantity += $cartRow['quantity'];
$grandTotal += $cartRow['quantity'] * $cartRow['price'];
}
}
// Check if product details are passed in the URL for a single product purchase
if (isset($_REQUEST['product_id']) && isset($_REQUEST['quantity']) && isset($_REQUEST['price'])) {
$productIds = $_REQUEST['product_id'];
$quantities = $_REQUEST['quantity'];
$price = $_REQUEST['price']; // Ensure this is set before use
} else {
// If not set, default the price to 0 or calculate it based on cart
$productIds = [];
$quantities = [];
$price = 0;
// If cart is used, calculate the price based on cart data
$cartData = mysqli_query($conn, "SELECT cart.p_id, cart.quantity, product.price FROM cart join product on cart.p_id=product.p_id WHERE u_id = '$user_id'");
while ($row = mysqli_fetch_assoc($cartData)) {
$productIds[] = $row['p_id'];
$quantities[] = $row['quantity'];
$price += $row['quantity'] * $row['price']; // Summing up price for all cart items
}
}
?>
<style>
/* Hide default radio button */
.custom-radio {
position: absolute;
opacity: 0;
cursor: pointer;
}
.custom-radio+.form-check-label {
position: relative;
padding-left: 60px;
cursor: pointer;
font-size: 16px;
color: #181167;
font-family: 'Poppins', sans-serif;
font-weight: 500;
}
.custom-radio+.form-check-label::before {
content: '';
position: absolute;
left: 0;
width: 40px;
height: 20px;
background-color: #ccc;
border-radius: 50px;
transition: background-color 0.3s, transform 0.3s;
}
.custom-radio+.form-check-label::after {
content: '';
position: absolute;
top: 2.5px;
left: 2px;
width: 15px;
height: 15px;
background-color: white;
border-radius: 50%;
transition: transform 0.3s;
}
.custom-radio:checked+.form-check-label::before {
background-color: #007bff;
}
.custom-radio:checked+.form-check-label::after {
transform: translateX(20px);
}
/* UPI Payment Section */
#upi-section {
display: none;
margin-top: 17px;
background-color: #dfe9fa;
padding: 20px;
border-radius: 15px;
text-align: center;
}
</style>
<section>
<div class="container-fluid">
<form method="post" action="place_order.php" onsubmit="return validateForm()">
<input type="hidden" name="product_id" value="<?php echo $_REQUEST['product_id'];?>"/>
<input type="hidden" name="quantity" value="<?php echo $_REQUEST['quantity'];?>"/>
<input type="hidden" name="price" value="<?php echo $_REQUEST['price'];?>"/>
<input type="hidden" name="selected_address" value="<?php echo $_REQUEST['selected_address'];?>" />
<div class="row d-flex w-75" id="box">
<div class="col-md-12 d-flex">
<div class="col-md-8">
<div class="col-md-12" style="background-color: #f1f6ff; padding: 50px 30px 30px 30px;">
<h3 class="text-center login-heading mb-4" style="font-size: 30px;">Select Payment Method</h3>
<!-- <form method="post" action="place_order.php" onsubmit="return validateForm()"> -->
<div style="display: grid; justify-content: center; align-items: center; background-color: #cedefa; padding: 35px; border-radius: 10px;">
<div style="margin-bottom: 25px;">
<input type="radio" id="cod" class="form-check-input custom-radio" name="payment_method" value="COD" onclick="toggleUPI(false)" required>
<label class="form-check-label" for="cod">Cash on Delivery</label>
</div>
<div>
<input type="radio" id="upi" class="form-check-input custom-radio" name="payment_method" value="UPI" onclick="toggleUPI(true)">
<label class="form-check-label" for="upi">UPI Payment</label>
</div>
</div>
<div id="upi-section">
<p style="font-size: 20px; color: #181167; font-family: 'Poppins'; font-weight: 500;">Scan the QR code to pay:</p>
<img src="assest/img/selfqr.jpg" alt="UPI QR Code" style="width: 200px;">
<p style="font-size: 16px; margin-top: 20px; color: #181167; font-family: 'Poppins'; font-weight: 500;">Enter Transaction ID:</p>
<input type="text" name="transaction_id" id="transaction_id" placeholder="Transaction ID">
</div>
<div style="padding: 20px; display: flex; justify-content: center;">
<button type="submit" name="place_order" class="btn checkoutbtn">Place Order</button>
</div>
<!-- </form> -->
</div>
</div>
<div class="col-md-4" style="display: flex;justify-content: center;align-items: center;margin-left: 40px;">
<div class="grandtotal_box col-md-12" style="margin: 0;">
<div class="col-md-12 summary_track">
<h6 class="p-0 m-0 summary">Price details</h6>
</div>
<div class="col-md-12 grandTotal_tray">
<h6>Number Of Products: <span id="totalQuantity"><?php echo is_array($quantities) ? array_sum($quantities) : $quantities; ?></span></h6>
<h6>Shipping: <span class="text-success">FREE</span></h6>
</div>
<div class="main_grand_total">
<h5 class="text-center">Grand Total: ₹ <span class="actual_price" id="grandTotal"><?php echo number_format($price, 2); ?></span></h5>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
<?php include("footer.php"); ?>
<script>
function toggleUPI(show) {
const upiSection = document.getElementById('upi-section');
const transactionId = document.getElementById('transaction_id');
upiSection.style.display = show ? 'block' : 'none';
if (!show) transactionId.value = '';
}
function validateForm() {
const upiChecked = document.getElementById('upi').checked;
const transactionId = document.getElementById('transaction_id').value.trim();
if (upiChecked && !transactionId) {
alert("Please enter a Transaction ID for UPI payment.");
return false;
}
return true;
}
document.addEventListener('DOMContentLoaded', function() {
const upiRadio = document.getElementById('upi');
if (upiRadio.checked) toggleUPI(true);
});
</script>