-
Notifications
You must be signed in to change notification settings - Fork 0
/
ct.php
143 lines (136 loc) · 6.44 KB
/
ct.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
<div id="form_wish" class="">
<?php
include "php/controller.php";
include "php/pay_config.php";
if (isset($_SESSION['Product'])) {
$total_rows = 1;
$totalamnt = 0;
$cardamount = 0;
$idp = 0;
?>
<table class="table table-bordered text-center">
<thead>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<?php
foreach ($_SESSION['Product'] as $cart => $values) {
$idp = $values['product_id'];
$qntity = $values['quantity'];
$select = $config->query("select * from products where id='$idp'");
$array = mysqli_fetch_array($select);
$price = $array['price'] * $qntity;
$totalamnt += $price;
$cardamount = $totalamnt * 100;
global $totalamnt;
global $cardamount;
?>
<tr>
<input type="hidden" name="idp[]" value="<?= $idp ?>">
<td><a href=""><?= $array['title'] ?></a> <a class="cart_remove" data-pid="<?= $array['id'] ?>"
href="javascript:void;"><br><i
class="fas fa-times"></i></a></td>
<td>
<span class="">
<button data-pdctid="<?= $array['id']; ?>" data-pqnty="<?= $values['quantity'] ?>"
class="btn min_quantity btn-sm">-</button>
<span><?= $qntity ?></span>
<button data-pdctid="<?= $array['id']; ?>" data-pqnty="<?= $values['quantity'] ?>"
class="btn pls_qntity btn-sm">+</button>
</span>
</td>
<td>$<?= $price ?></td>
</tr>
<?php
$total_rows++;
}
?>
</tbody>
</table>
<div class="row mx-0">
<div class="cal-lg-4 pl-0 pl-lg-3 col-md-5 pr-0 ml-auto">
<table class="table table-bordered">
<tr>
<td style="width: 36%;">Total</td>
<td class="text-center"><b>$<?= isset($totalamnt) ? $totalamnt : '0.00' ?></b></td>
</tr>
</table>
<form action="php/place-order-gen.php" method="post">
<input type="text" placeholder="Name" class="form-control mb-2" name="name">
<input type="text" placeholder="Email" class="form-control mb-2" name="email">
<input type="text" placeholder="Address" class="form-control mb-2" name="address">
<button type="submit" name="payment_gen"
class="btn btn-primary d-block w-100 mb-2">Generate order and send email
</button>
</form>
<div id="smart-button-container">
<div style="text-align: center;">
<div id="paypal-button-container"></div>
</div>
</div>
<script src="https://www.paypal.com/sdk/js?client-id=AURryq0gyMoasRadzGZGm1u6eIadYNQJxXD7z5uE2BIoHEASjRxQLhBMu8XZUQaFP1g74Qo0tWXtO5vG¤cy=USD"
data-sdk-integration-source="button-factory"></script>
<script>
var product_value = $("input[name='idp[]']").map(function () {
return $(this).val();
}).get();
function initPayPalButton() {
paypal.Buttons({
style: {
shape: 'rect',
color: 'gold',
layout: 'vertical',
label: 'paypal',
},
createOrder: function (data, actions) {
return actions.order.create({
purchase_units: [{
"amount": {
"currency_code": "USD",
"value": <?= $totalamnt ?>
}
}]
});
},
onApprove: function (data, actions) {
return actions.order.capture().then(function (details) {
const email_address = details.payer.email_address;
const name = details.payer.name.given_name + " " + details.payer.name.surname;
const payer_id = details.payer.payer_id;
$.post("php/pay_submit.php", {
email_address: email_address,
name: name,
payer_id: payer_id,
product_id: product_value,
amount: <?= $totalamnt ?>,
cart_payment: "questions_ajax"
})
.done(function (data) {
window.location.href = 'php/controller.php?order_payment=' + data;
});
});
},
onError: function (err) {
console.log(err);
}
}).render('#paypal-button-container');
}
initPayPalButton();
</script>
</div>
</div>
<?php
} else {
?>
<div class="py-4 option">
<h5 class="text-center">Empty Cart</h5>
</div>
<?php
}
?>
</div>
<script src="ajax.js"></script>