-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.php
executable file
·356 lines (328 loc) · 15.9 KB
/
checkout.php
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
require('top.php');
if(!isset($_SESSION['cart']) || count($_SESSION['cart'])==0){
?>
<script>
window.location.href='index.php';
</script>
<?php
}
$cart_total=0;
if(isset($_POST['submit'])){
$address=get_safe_value($con,$_POST['address']);
$city=get_safe_value($con,$_POST['city']);
$pincode=get_safe_value($con,$_POST['pincode']);
$payment_type=get_safe_value($con,$_POST['payment_type']);
$user_id=$_SESSION['USER_ID'];
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$price=$productArr[0]['price'];
$qty=$val['qty'];
$cart_total=$cart_total+($price*$qty);
}
$total_price=$cart_total;
$payment_status='pending';
if($payment_type=='cod'){
$payment_status='success';
}
$order_status='1';
$added_on=date('Y-m-d h:i:s');
$txnid = substr(hash('sha256', mt_rand() . microtime()), 0, 20);
if(isset($_SESSION['COUPON_ID'])){
$coupon_id=$_SESSION['COUPON_ID'];
$coupon_code=$_SESSION['COUPON_CODE'];
$coupon_value=$_SESSION['COUPON_VALUE'];
$total_price=$total_price-$coupon_value;
unset($_SESSION['COUPON_ID']);
unset($_SESSION['COUPON_CODE']);
unset($_SESSION['COUPON_VALUE']);
}else{
$coupon_id='';
$coupon_code='';
$coupon_value='';
}
mysqli_query($con,"insert into `order`(user_id,address,city,pincode,payment_type,payment_status,order_status,added_on,total_price,txnid,coupon_id,coupon_code,coupon_value) values('$user_id','$address','$city','$pincode','$payment_type','$payment_status','$order_status','$added_on','$total_price','$txnid','$coupon_id','$coupon_code','$coupon_value')");
#$order_id=mysqli_insert_id($con);
$order_id=$_SESSION['USER_ID'];
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$price=$productArr[0]['price'];
$qty=$val['qty'];
mysqli_query($con,"insert into `order_detail`(order_id,product_id,qty,price) values('$order_id','$key','$qty','$price')");
}
unset($_SESSION['cart']);
if($payment_type=='payu'){
$MERCHANT_KEY = "gtKFFx";
$SALT = "eCwWELxi";
$hash_string = '';
//$PAYU_BASE_URL = "https://secure.payu.in";
$PAYU_BASE_URL = "https://test.payu.in";
$action = '';
$posted = array();
if(!empty($_POST)) {
foreach($_POST as $key => $value) {
$posted[$key] = $value;
}
}
$userArr=mysqli_fetch_assoc(mysqli_query($con,"select * from users where id='$user_id'"));
$formError = 0;
$posted['txnid']=$txnid;
$posted['amount']=$total_price;
$posted['firstname']=$userArr['name'];
$posted['email']=$userArr['email'];
$posted['phone']=$userArr['mobile'];
$posted['productinfo']="productinfo";
$posted['key']=$MERCHANT_KEY ;
$hash = '';
$hashSequence = "key|txnid|amount|productinfo|firstname|email|udf1|udf2|udf3|udf4|udf5|udf6|udf7|udf8|udf9|udf10";
if(empty($posted['hash']) && sizeof($posted) > 0) {
if(
empty($posted['key'])
|| empty($posted['txnid'])
|| empty($posted['amount'])
|| empty($posted['firstname'])
|| empty($posted['email'])
|| empty($posted['phone'])
|| empty($posted['productinfo'])
) {
$formError = 1;
} else {
$hashVarsSeq = explode('|', $hashSequence);
foreach($hashVarsSeq as $hash_var) {
$hash_string .= isset($posted[$hash_var]) ? $posted[$hash_var] : '';
$hash_string .= '|';
}
$hash_string .= $SALT;
$hash = strtolower(hash('sha512', $hash_string));
$action = $PAYU_BASE_URL . '/_payment';
}
} elseif(!empty($posted['hash'])) {
$hash = $posted['hash'];
$action = $PAYU_BASE_URL . '/_payment';
}
$formHtml ='<form method="post" name="payuForm" id="payuForm" action="'.$action.'"><input type="hidden" name="key" value="'.$MERCHANT_KEY.'" /><input type="hidden" name="hash" value="'.$hash.'"/><input type="hidden" name="txnid" value="'.$posted['txnid'].'" /><input name="amount" type="hidden" value="'.$posted['amount'].'" /><input type="hidden" name="firstname" id="firstname" value="'.$posted['firstname'].'" /><input type="hidden" name="email" id="email" value="'.$posted['email'].'" /><input type="hidden" name="phone" value="'.$posted['phone'].'" /><textarea name="productinfo" style="display:none;">'.$posted['productinfo'].'</textarea><input type="hidden" name="surl" value="'.SITE_PATH.'payment_complete.php" /><input type="hidden" name="furl" value="'.SITE_PATH.'payment_fail.php"/><input type="submit" style="display:none;"/></form>';
echo $formHtml;
echo '<script>document.getElementById("payuForm").submit();</script>';
}else{
//sentInvoice($con,$order_id);
?>
<script>
window.location.href='thank_you.php';
</script>
<?php
}
}
?>
<div class="ht__bradcaump__area" style="background: rgba(0, 0, 0, 0) url(images/bg/4.jpg) no-repeat scroll center center / cover ;">
<div class="ht__bradcaump__wrap">
<div class="container">
<div class="row">
<div class="col-xs-12">
<div class="bradcaump__inner">
<nav class="bradcaump-inner">
<a class="breadcrumb-item" href="index.php">Home</a>
<span class="brd-separetor"><i class="zmdi zmdi-chevron-right"></i></span>
<span class="breadcrumb-item active">checkout</span>
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End Bradcaump area -->
<!-- cart-main-area start -->
<div class="checkout-wrap ptb--100">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="checkout__inner">
<div class="accordion-list">
<div class="accordion">
<?php
$accordion_class='accordion__title';
if(!isset($_SESSION['USER_LOGIN'])){
$accordion_class='accordion__hide';
?>
<div class="accordion__title">
Checkout Method
</div>
<div class="accordion__body">
<div class="accordion__body__form">
<div class="row">
<div class="col-md-6">
<div class="checkout-method__login">
<form id="login-form" method="post">
<h5 class="checkout-method__title">Login</h5>
<div class="single-input">
<input type="text" name="login_email" id="login_email" placeholder="Your Email*" style="width:100%">
<span class="field_error" id="login_email_error"></span>
</div>
<div class="single-input">
<input type="password" name="login_password" id="login_password" placeholder="Your Password*" style="width:100%">
<span class="field_error" id="login_password_error"></span>
</div>
<p class="require">* Required fields</p>
<div class="dark-btn">
<button type="button" class="fv-btn" onclick="user_login()">Login</button>
</div>
<div class="form-output login_msg">
<p class="form-messege field_error"></p>
</div>
</form>
</div>
</div>
<div class="col-md-6">
<div class="checkout-method__login">
<form action="#">
<h5 class="checkout-method__title">Register</h5>
<div class="single-input">
<input type="text" name="name" id="name" placeholder="Your Name*" style="width:100%">
<span class="field_error" id="name_error"></span>
</div>
<div class="single-input">
<input type="text" name="email" id="email" placeholder="Your Email*" style="width:100%">
<span class="field_error" id="email_error"></span>
</div>
<div class="single-input">
<input type="text" name="mobile" id="mobile" placeholder="Your Mobile*" style="width:100%">
<span class="field_error" id="mobile_error"></span>
</div>
<div class="single-input">
<input type="password" name="password" id="password" placeholder="Your Password*" style="width:100%">
<span class="field_error" id="password_error"></span>
</div>
<div class="dark-btn">
<button type="button" class="fv-btn" onclick="user_register()">Register</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<div class="<?php echo $accordion_class?>">
Address Information
</div>
<form method="post">
<div class="accordion__body">
<div class="bilinfo">
<div class="row">
<div class="col-md-12">
<div class="single-input">
<input type="text" name="address" placeholder="Street Address" required>
</div>
</div>
<div class="col-md-6">
<div class="single-input">
<input type="text" name="city" placeholder="City/State" required>
</div>
</div>
<div class="col-md-6">
<div class="single-input">
<input type="text" name="pincode" placeholder="Post code/ zip" required>
</div>
</div>
</div>
</div>
</div>
<div class="<?php echo $accordion_class?>">
payment information
</div>
<div class="accordion__body">
<div class="paymentinfo">
<div class="single-method">
COD <input type="radio" name="payment_type" value="COD" required/>
PayU <input type="radio" name="payment_type" value="payu" required/>
</div>
<div class="single-method">
</div>
</div>
</div>
<input type="submit" name="submit" class="fv-btn"/>
</form>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<div class="order-details">
<h5 class="order-details__title">Your Order</h5>
<div class="order-details__item">
<?php
$cart_total=0;
foreach($_SESSION['cart'] as $key=>$val){
$productArr=get_product($con,'','',$key);
$pname=$productArr[0]['name'];
$mrp=$productArr[0]['mrp'];
$price=$productArr[0]['price'];
$image=$productArr[0]['image'];
$qty=$val['qty'];
$cart_total=$cart_total+($price*$qty);
?>
<div class="single-item">
<div class="single-item__thumb">
<img src="<?php echo PRODUCT_IMAGE_SITE_PATH.$image?>" />
</div>
<div class="single-item__content">
<a href="#"><?php echo $pname?></a>
<span class="price"><?php echo $price*$qty?></span>
</div>
<div class="single-item__remove">
<a href="javascript:void(0)" onclick="manage_cart('<?php echo $key?>','remove')"><i class="icon-trash icons"></i></a>
</div>
</div>
<?php } ?>
</div>
<div class="ordre-details__total" id="coupon_box">
<h5>Coupon Value</h5>
<span class="price" id="coupon_price"></span>
</div>
<div class="ordre-details__total">
<h5>Order total</h5>
<span class="price" id="order_total_price"><?php echo $cart_total?></span>
</div>
<div class="ordre-details__total bilinfo">
<input type="textbox" id="coupon_str" class="coupon_style mr5"/> <input type="button" name="submit" class="fv-btn coupon_style" value="Apply Coupon" onclick="set_coupon()"/>
</div>
<div id="coupon_result"></div>
</div>
</div>
</div>
</div>
</div>
<script>
function set_coupon(){
var coupon_str=jQuery('#coupon_str').val();
if(coupon_str!=''){
jQuery('#coupon_result').html('');
jQuery.ajax({
url:'set_coupon.php',
type:'post',
data:'coupon_str='+coupon_str,
success:function(result){
var data=jQuery.parseJSON(result);
if(data.is_error=='yes'){
jQuery('#coupon_box').hide();
jQuery('#coupon_result').html(data.dd);
jQuery('#order_total_price').html(data.result);
}
if(data.is_error=='no'){
jQuery('#coupon_box').show();
jQuery('#coupon_price').html(data.dd);
jQuery('#order_total_price').html(data.result);
}
}
});
}
}
</script>
<?php
if(isset($_SESSION['COUPON_ID'])){
unset($_SESSION['COUPON_ID']);
unset($_SESSION['COUPON_CODE']);
unset($_SESSION['COUPON_VALUE']);
}
require('footer.php');
?>