-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpayment.php
116 lines (103 loc) · 4.83 KB
/
payment.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
<?php
session_start();
if (isset($_POST['order_pay_btn'])) {
$order_id = $_POST['order_id'];
$order_status = $_POST['order_status'];
$order_total_price = $_POST['order_total_price'];
}
$kurs_dollar = 15722;
function setRupiah($price)
{
$result = "Rp".number_format($price, 0, ',', '.');
return $result;
}
?>
<?php include('layouts/header.php'); ?>
<!-- Breadcrumb Section Begin -->
<section class="breadcrumb-option">
<div class="container">
<div class="row">
<div class="col-lg-12">
<div class="breadcrumb__text">
<h4>Payment</h4>
<div class="breadcrumb__links">
<a href="index.php">Home</a>
<a href="shop.php">Shop</a>
<a href="checkout.php">Checkout</a>
<span>Payment</span>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Breadcrumb Section End -->
<!-- Payment Section Begin -->
<section class="checkout spad">
<div class="container">
<div class="checkout__form">
<div class="row">
<div class="col-lg-8 col-md-6">
<div class="checkout__input">
<h6 class="coupon__code"><span class="icon_tag_alt"></span>
<?php if (isset($_POST['order_status'])) {
echo $_POST['order_status'];
} ?>
</h6>
<?php if (isset($_POST['order_status']) && $_POST['order_status'] == "not paid") { ?>
<?php $amount = strval($_POST['order_total_price']); ?>
<?php $order_id = $_POST['order_id']; ?>
<h6 class="checkout__title">TOTAL PAYMENT: $<?php echo setRupiah(($_POST['order_total_price'] * $kurs_dollar)); ?></h6>
<!--<input type="submit" class="btn btn-primary" value="PAY NOW" />-->
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<?php } else if (isset($_SESSION['total']) && $_SESSION['total'] != 0) { ?>
<?php $amount = strval($_SESSION['total']); ?>
<?php $order_id = $_SESSION['order_id']; ?>
<h6 class="checkout__title">TOTAL PAYMENT: <?php echo setRupiah(($_SESSION['total'] * $kurs_dollar)); ?></h6>
<!--<input type="submit" class="btn btn-primary" value="PAY NOW" /> -->
<!-- Set up a container element for the button -->
<div id="paypal-button-container"></div>
<?php } else { ?>
<p>You don't have an order</p>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Payment Section End -->
<!-- Replace "test" with your own sandbox Business account app client ID -->
<script src="https://www.paypal.com/sdk/js?client-id=AZc7gISngCVfWIqTNzlMZRSCsd7cte4sTB4ZrK7JEJHUGO9CEALMKj4mzo5ZIe2i6DRAiOhJouUWqxXF¤cy=USD"></script>
<script>
paypal.Buttons({
// Sets up the transaction when a payment button is clicked
createOrder: (data, actions) => {
return actions.order.create({
purchase_units: [{
amount: {
value: '<?php echo $amount; ?>' // Can also reference a variable or function
}
}]
});
},
// Finalize the transaction after payer approval
onApprove: (data, actions) => {
return actions.order.capture().then(function(orderData) {
// Successful capture! For dev/demo purposes:
console.log('Capture result', orderData, JSON.stringify(orderData, null, 2));
const transaction = orderData.purchase_units[0].payments.captures[0];
alert('Transaction ' + transaction.status + ': ' + transaction.id + '\n\nSee console for all available details');
window.location.href = "server/complete_payment.php?transaction_id="+transaction.id+"&order_id="+<?php echo $order_id; ?>;
// When ready to go live, remove the alert and show a success message within this page. For example:
// const element = document.getElementById('paypal-button-container');
// element.innerHTML = '<h3>Thank you for your payment!</h3>';
// Or go to another URL: actions.redirect('thank_you.html');
});
}
}).render('#paypal-button-container');
</script>
<?php
include('layouts/footer.php');
?>