-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckout.php
More file actions
119 lines (112 loc) · 4.41 KB
/
Copy pathcheckout.php
File metadata and controls
119 lines (112 loc) · 4.41 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
<script src="https://www.paypalobjects.com/api/checkout.js"></script>
<?php
$total = 0;
$qry = $conn->query("SELECT c.*,p.product_name,i.size,i.price,p.id as pid from `cart` c inner join `inventory` i on i.id=c.inventory_id inner join products p on p.id = i.product_id where c.client_id = ".$_settings->userdata('id'));
while($row= $qry->fetch_assoc()):
$total += $row['price'] * $row['quantity'];
endwhile;
?>
<section class="py-5">
<div class="container">
<div class="card rounded-0">
<div class="card-body"></div>
<h3 class="text-center"><b>Checkout</b></h3>
<hr class="border-dark">
<form action="" id="place_order">
<input type="hidden" name="amount" value="<?php echo $total ?>">
<input type="hidden" name="payment_method" value="cod">
<input type="hidden" name="paid" value="0">
<div class="row row-col-1 justify-content-center">
<div class="col-6">
<div class="form-group col">
<label for="" class="control-label">Delivery Address</label>
<textarea id="" cols="30" rows="3" name="delivery_address" class="form-control" style="resize:none"><?php echo $_settings->userdata('default_delivery_address') ?></textarea>
</div>
<div class="col">
<span><h4><b>Total:</b> <?php echo number_format($total) ?></h4></span>
</div>
<hr>
<div class="col my-3">
<h4 class="text-muted">Payment Method</h4>
<div class="d-flex w-100 justify-content-between">
<button class="btn btn-flat btn-dark">Cash on Delivery</button>
<span id="paypal-button"></span>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</section>
<script>
paypal.Button.render({
env: 'sandbox', // change for production if app is live,
//app's client id's
client: {
sandbox: 'AdDNu0ZwC3bqzdjiiQlmQ4BRJsOarwyMVD_L4YQPrQm4ASuBg4bV5ZoH-uveg8K_l9JLCmipuiKt4fxn',
//production: 'AaBHKJFEej4V6yaArjzSx9cuf-UYesQYKqynQVCdBlKuZKawDDzFyuQdidPOBSGEhWaNQnnvfzuFB9SM'
},
commit: true, // Show a 'Pay Now' button
style: {
color: 'blue',
size: 'small'
},
payment: function(data, actions) {
return actions.payment.create({
payment: {
transactions: [
{
//total purchase
amount: {
total: '<?php echo $total; ?>',
currency: 'PHP'
}
}
]
}
});
},
onAuthorize: function(data, actions) {
return actions.payment.execute().then(function(payment) {
// //sweetalert for successful transaction
// swal('Thank you!', 'Paypal purchase successful.', 'success');
payment_online()
});
},
}, '#paypal-button');
function payment_online(){
$('[name="payment_method"]').val("Online Payment")
$('[name="paid"]').val(1)
$('#place_order').submit()
}
$(function(){
$('#place_order').submit(function(e){
e.preventDefault()
start_loader();
$.ajax({
url:'classes/Master.php?f=place_order',
method:'POST',
data:$(this).serialize(),
dataType:"json",
error:err=>{
console.log(err)
alert_toast("an error occured","error")
end_loader();
},
success:function(resp){
if(!!resp.status && resp.status == 'success'){
alert_toast("Order Successfully placed.","success")
setTimeout(function(){
location.replace('./')
},2000)
}else{
console.log(resp)
alert_toast("an error occured","error")
end_loader();
}
}
})
})
})
</script>