-
Notifications
You must be signed in to change notification settings - Fork 0
/
charge.php
82 lines (63 loc) · 2.93 KB
/
charge.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
<?php
if (!isset($_SERVER['HTTP_REFERER'])){
header("Location: http://localhost/Freshcery/index.php");
exit();
}
?>
<?php require_once "includes/header.php"?>
<?php
if (!isset($_SESSION['user'])){
// header("Location: localhost/Freshcery");
echo "<script> window.location.href = 'http:://localhost/Freshcery/' </script>";
exit();
}
?>
<?php
$totalPrice = number_format($_SESSION['total_price'], 2, '.', '');
// echo $totalPrice;
?>
<div id="page-content" class="page-content">
<div class="banner">
<div class="jumbotron jumbotron-bg text-center rounded-0" style="background-image: url('assets/img/bg-header.jpg');">
<div class="container">
<h1 class="py-5 text-white">
Pay with PayPal - Page
</h1>
</div>
</div>
</div>
<!-- Main Content Container -->
<div class="container d-flex align-items-center justify-content-center flex-column mt-5">
<h2 class="text-center">Complete Your Payment</h2>
<p class="text-center text-muted">Please click the button below to proceed with your payment.</p>
<!-- PayPal Button Container -->
<div id="paypal-button-container"></div>
</div>
<!-- PayPal SDK -->
<script src="https://www.paypal.com/sdk/js?client-id=AZuJRffuEckG1Fl43Of3s4H4kuUE7LG4eofNqUFxodILrSLZ9ZXm1JQhbYu4LMLlKlhMXpyQgitLH1zz¤cy=USD"></script>
<script>
// Use PHP to output the formatted total price into a JavaScript variable
var totalPrice = <?php echo json_encode($totalPrice); ?>;
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: totalPrice
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
window.location.href = 'success.php';
});
}
}).render('#paypal-button-container');
</script>
</div>
<br>
<br>
<?php require_once "includes/footer.php"?>